Config
Using the opencode JSON config.
You can configure opencode using a JSON config file.
Format
opencode supports both JSON and JSONC (JSON with Comments) formats. You can use comments in your configuration files:
{ "$schema": "https://opencode.ai/config.json", // Theme configuration "theme": "opencode", "model": "anthropic/claude-sonnet-4-20250514", "autoupdate": true,}
This can be used to configure opencode globally or for a specific project.
Global
Place your global opencode config in ~/.config/opencode/opencode.json
. You’ll want to use the global config for things like themes, providers, or keybinds.
Per project
You can also add a opencode.json
in your project. This is useful for configuring providers or modes specific to your project.
When opencode starts up, it looks for a config file in the current directory or traverse up to the nearest Git directory.
This is also safe to be checked into Git and uses the same schema as the global one.
Custom config file
You can specify a custom config file using the OPENCODE_CONFIG
environment variable. This takes precedence over the global and project configs.
export OPENCODE_CONFIG=/path/to/my/custom-config.jsonopencode run "Hello world"
Schema
The config file has a schema that’s defined in opencode.ai/config.json
.
Your editor should be able to validate and autocomplete based on the schema.
Modes
opencode comes with two built-in modes: build, the default with all tools enabled. And plan, restricted mode with file modification tools disabled. You can override these built-in modes or define your own custom modes with the mode
option.
{ "$schema": "https://opencode.ai/config.json", "mode": { "build": {}, "plan": {}, "my-custom-mode": {} }}
Models
You can configure the providers and models you want to use in your opencode config through the provider
, model
and small_model
options.
{ "$schema": "https://opencode.ai/config.json", "provider": {}, "model": "anthropic/claude-sonnet-4-20250514", "small_model": "anthropic/claude-3-5-haiku-20241022"}
The small_model
option configures a separate model for lightweight tasks like summarization and title generation. By default, opencode tries to use a cheaper model if one is available from your provider, otherwise it falls back to your main model.
You can also configure local models. Learn more.
Themes
You can configure the theme you want to use in your opencode config through the theme
option.
{ "$schema": "https://opencode.ai/config.json", "theme": ""}
Logging
Logs are written to:
- macOS/Linux:
~/.local/share/opencode/log/
- Windows:
%APPDATA%\opencode\log\
Sharing
You can configure the share feature through the share
option.
{ "$schema": "https://opencode.ai/config.json", "share": "manual"}
This takes:
"manual"
- Allow manual sharing via commands (default)"auto"
- Automatically share new conversations"disabled"
- Disable sharing entirely
By default, sharing is set to manual mode where you need to explicitly share conversations using the /share
command.
Keybinds
You can customize your keybinds through the keybinds
option.
{ "$schema": "https://opencode.ai/config.json", "keybinds": {}}
Autoupdate
opencode will automatically download any new updates when it starts up. You can disable this with the autoupdate
option.
{ "$schema": "https://opencode.ai/config.json", "autoupdate": false}
MCP servers
You can configure MCP servers you want to use through the mcp
option.
{ "$schema": "https://opencode.ai/config.json", "mcp": {}}
Instructions
You can configure the instructions for the model you’re using through the instructions
option.
{ "$schema": "https://opencode.ai/config.json", "instructions": ["CONTRIBUTING.md", "docs/guidelines.md", ".cursor/rules/*.md"]}
This takes an array of paths and glob patterns to instruction files. Learn more about rules here.
Agents
You can configure specialized agents for specific tasks through the agent
option.
{ "$schema": "https://opencode.ai/config.json", "agent": { "code-reviewer": { "description": "Reviews code for best practices and potential issues", "model": "anthropic/claude-sonnet-4-20250514", "prompt": "You are a code reviewer. Focus on security, performance, and maintainability.", "tools": { // Disable file modification tools for review-only agent "write": false, "edit": false, }, }, },}
You can also define agents using markdown files in ~/.config/opencode/agent/
or .opencode/agent/
. Learn more here.
Disabled providers
You can disable providers that are loaded automatically through the disabled_providers
option. This is useful when you want to prevent certain providers from being loaded even if their credentials are available.
Formatters
You can configure code formatters through the formatter
option. See Formatters documentation for more details.
{ "$schema": "https://opencode.ai/config.json", "disabled_providers": ["openai", "gemini"]}
The disabled_providers
option accepts an array of provider IDs. When a provider is disabled:
- It won’t be loaded even if environment variables are set
- It won’t be loaded even if API keys are configured through
opencode auth login
- The provider’s models won’t appear in the model selection list
Permissions
You can configure permissions to control what AI agents can do in your codebase through the permission
option.
{ "$schema": "https://opencode.ai/config.json", "permission": { "edit": "ask", "bash": "ask" }}
The permissions system allows you to configure explicit approval requirements for sensitive operations:
edit
- Controls whether file editing operations require user approval ("ask"
or"allow"
)bash
- Controls whether bash commands require user approval (can be"ask"
/"allow"
or a pattern map)
Learn more about permissions here.
Variables
You can use variable substitution in your config files to reference environment variables and file contents.
Env vars
Use {env:VARIABLE_NAME}
to substitute environment variables:
{ "$schema": "https://opencode.ai/config.json", "model": "{env:OPENCODE_MODEL}", "provider": { "anthropic": { "options": { "apiKey": "{env:ANTHROPIC_API_KEY}" } } }}
If the environment variable is not set, it will be replaced with an empty string.
Files
Use {file:path/to/file}
to substitute the contents of a file:
{ "$schema": "https://opencode.ai/config.json", "instructions": ["{file:./custom-instructions.md}"], "provider": { "openai": { "options": { "apiKey": "{file:~/.secrets/openai-key}" } } }}
File paths can be:
- Relative to the config file directory
- Or absolute paths starting with
/
or~
These are useful for:
- Keeping sensitive data like API keys in separate files.
- Including large instruction files without cluttering your config.
- Sharing common configuration snippets across multiple config files.