| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692 |
- ---
- title: Config
- description: 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.
- ```jsonc title="opencode.jsonc"
- {
- "$schema": "https://opencode.ai/config.json",
- "model": "anthropic/claude-sonnet-4-5",
- "autoupdate": true,
- "server": {
- "port": 4096,
- },
- }
- ```
- ---
- ## Locations
- You can place your config in a couple of different locations and they have a
- different order of precedence.
- :::note
- Configuration files are **merged together**, not replaced.
- :::
- Configuration files are merged together, not replaced. Settings from the following config locations are combined. Later configs override earlier ones only for conflicting keys. Non-conflicting settings from all configs are preserved.
- For example, if your global config sets `autoupdate: true` and your project config sets `model: "anthropic/claude-sonnet-4-5"`, the final configuration will include both settings.
- ---
- ### Precedence order
- Config sources are loaded in this order (later sources override earlier ones):
- 1. **Remote config** (from `.well-known/opencode`) - organizational defaults
- 2. **Global config** (`~/.config/opencode/opencode.json`) - user preferences
- 3. **Custom config** (`OPENCODE_CONFIG` env var) - custom overrides
- 4. **Project config** (`opencode.json` in project) - project-specific settings
- 5. **`.opencode` directories** - agents, commands, plugins
- 6. **Inline config** (`OPENCODE_CONFIG_CONTENT` env var) - runtime overrides
- This means project configs can override global defaults, and global configs can override remote organizational defaults.
- :::note
- The `.opencode` and `~/.config/opencode` directories use **plural names** for subdirectories: `agents/`, `commands/`, `modes/`, `plugins/`, `skills/`, `tools/`, and `themes/`. Singular names (e.g., `agent/`) are also supported for backwards compatibility.
- :::
- ---
- ### Remote
- Organizations can provide default configuration via the `.well-known/opencode` endpoint. This is fetched automatically when you authenticate with a provider that supports it.
- Remote config is loaded first, serving as the base layer. All other config sources (global, project) can override these defaults.
- For example, if your organization provides MCP servers that are disabled by default:
- ```json title="Remote config from .well-known/opencode"
- {
- "mcp": {
- "jira": {
- "type": "remote",
- "url": "https://jira.example.com/mcp",
- "enabled": false
- }
- }
- }
- ```
- You can enable specific servers in your local config:
- ```json title="opencode.json"
- {
- "mcp": {
- "jira": {
- "type": "remote",
- "url": "https://jira.example.com/mcp",
- "enabled": true
- }
- }
- }
- ```
- ---
- ### Global
- Place your global OpenCode config in `~/.config/opencode/opencode.json`. Use global config for user-wide server/runtime preferences like providers, models, and permissions.
- For TUI-specific settings, use `~/.config/opencode/tui.json`.
- Global config overrides remote organizational defaults.
- ---
- ### Per project
- Add `opencode.json` in your project root. Project config has the highest precedence among standard config files - it overrides both global and remote configs.
- For project-specific TUI settings, add `tui.json` alongside it.
- :::tip
- Place project specific config in the root of 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 path
- Specify a custom config file path using the `OPENCODE_CONFIG` environment variable.
- ```bash
- export OPENCODE_CONFIG=/path/to/my/custom-config.json
- opencode run "Hello world"
- ```
- Custom config is loaded between global and project configs in the precedence order.
- ---
- ### Custom directory
- Specify a custom config directory using the `OPENCODE_CONFIG_DIR`
- environment variable. This directory will be searched for agents, commands,
- modes, and plugins just like the standard `.opencode` directory, and should
- follow the same structure.
- ```bash
- export OPENCODE_CONFIG_DIR=/path/to/my/config-directory
- opencode run "Hello world"
- ```
- The custom directory is loaded after the global config and `.opencode` directories, so it **can override** their settings.
- ---
- ## Schema
- The server/runtime config schema is defined in [**`opencode.ai/config.json`**](https://opencode.ai/config.json).
- TUI config uses [**`opencode.ai/tui.json`**](https://opencode.ai/tui.json).
- Your editor should be able to validate and autocomplete based on the schema.
- ---
- ### TUI
- Use a dedicated `tui.json` (or `tui.jsonc`) file for TUI-specific settings.
- ```json title="tui.json"
- {
- "$schema": "https://opencode.ai/tui.json",
- "scroll_speed": 3,
- "scroll_acceleration": {
- "enabled": true
- },
- "diff_style": "auto"
- }
- ```
- Use `OPENCODE_TUI_CONFIG` to point to a custom TUI config file.
- Legacy `theme`, `keybinds`, and `tui` keys in `opencode.json` are deprecated and automatically migrated when possible.
- [Learn more about TUI configuration here](/docs/tui#configure).
- ---
- ### Server
- You can configure server settings for the `opencode serve` and `opencode web` commands through the `server` option.
- ```json title="opencode.json"
- {
- "$schema": "https://opencode.ai/config.json",
- "server": {
- "port": 4096,
- "hostname": "0.0.0.0",
- "mdns": true,
- "mdnsDomain": "myproject.local",
- "cors": ["http://localhost:5173"]
- }
- }
- ```
- Available options:
- - `port` - Port to listen on.
- - `hostname` - Hostname to listen on. When `mdns` is enabled and no hostname is set, defaults to `0.0.0.0`.
- - `mdns` - Enable mDNS service discovery. This allows other devices on the network to discover your OpenCode server.
- - `mdnsDomain` - Custom domain name for mDNS service. Defaults to `opencode.local`. Useful for running multiple instances on the same network.
- - `cors` - Additional origins to allow for CORS when using the HTTP server from a browser-based client. Values must be full origins (scheme + host + optional port), eg `https://app.example.com`.
- [Learn more about the server here](/docs/server).
- ---
- ### Tools
- You can manage the tools an LLM can use through the `tools` option.
- ```json title="opencode.json"
- {
- "$schema": "https://opencode.ai/config.json",
- "tools": {
- "write": false,
- "bash": false
- }
- }
- ```
- [Learn more about tools here](/docs/tools).
- ---
- ### Models
- You can configure the providers and models you want to use in your OpenCode config through the `provider`, `model` and `small_model` options.
- ```json title="opencode.json"
- {
- "$schema": "https://opencode.ai/config.json",
- "provider": {},
- "model": "anthropic/claude-sonnet-4-5",
- "small_model": "anthropic/claude-haiku-4-5"
- }
- ```
- The `small_model` option configures a separate model for lightweight tasks like 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.
- Provider options can include `timeout`, `chunkTimeout`, and `setCacheKey`:
- ```json title="opencode.json"
- {
- "$schema": "https://opencode.ai/config.json",
- "provider": {
- "anthropic": {
- "options": {
- "timeout": 600000,
- "chunkTimeout": 30000,
- "setCacheKey": true
- }
- }
- }
- }
- ```
- - `timeout` - Request timeout in milliseconds (default: 300000). Set to `false` to disable.
- - `chunkTimeout` - Timeout in milliseconds between streamed response chunks. If no chunk arrives in time, the request is aborted.
- - `setCacheKey` - Ensure a cache key is always set for designated provider.
- You can also configure [local models](/docs/models#local). [Learn more](/docs/models).
- ---
- #### Provider-Specific Options
- Some providers support additional configuration options beyond the generic `timeout` and `apiKey` settings.
- ##### Amazon Bedrock
- Amazon Bedrock supports AWS-specific configuration:
- ```json title="opencode.json"
- {
- "$schema": "https://opencode.ai/config.json",
- "provider": {
- "amazon-bedrock": {
- "options": {
- "region": "us-east-1",
- "profile": "my-aws-profile",
- "endpoint": "https://bedrock-runtime.us-east-1.vpce-xxxxx.amazonaws.com"
- }
- }
- }
- }
- ```
- - `region` - AWS region for Bedrock (defaults to `AWS_REGION` env var or `us-east-1`)
- - `profile` - AWS named profile from `~/.aws/credentials` (defaults to `AWS_PROFILE` env var)
- - `endpoint` - Custom endpoint URL for VPC endpoints. This is an alias for the generic `baseURL` option using AWS-specific terminology. If both are specified, `endpoint` takes precedence.
- :::note
- Bearer tokens (`AWS_BEARER_TOKEN_BEDROCK` or `/connect`) take precedence over profile-based authentication. See [authentication precedence](/docs/providers#authentication-precedence) for details.
- :::
- [Learn more about Amazon Bedrock configuration](/docs/providers#amazon-bedrock).
- ---
- ### Themes
- Set your UI theme in `tui.json`.
- ```json title="tui.json"
- {
- "$schema": "https://opencode.ai/tui.json",
- "theme": "tokyonight"
- }
- ```
- [Learn more here](/docs/themes).
- ---
- ### Agents
- You can configure specialized agents for specific tasks through the `agent` option.
- ```jsonc title="opencode.jsonc"
- {
- "$schema": "https://opencode.ai/config.json",
- "agent": {
- "code-reviewer": {
- "description": "Reviews code for best practices and potential issues",
- "model": "anthropic/claude-sonnet-4-5",
- "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/agents/` or `.opencode/agents/`. [Learn more here](/docs/agents).
- ---
- ### Default agent
- You can set the default agent using the `default_agent` option. This determines which agent is used when none is explicitly specified.
- ```json title="opencode.json"
- {
- "$schema": "https://opencode.ai/config.json",
- "default_agent": "plan"
- }
- ```
- The default agent must be a primary agent (not a subagent). This can be a built-in agent like `"build"` or `"plan"`, or a [custom agent](/docs/agents) you've defined. If the specified agent doesn't exist or is a subagent, OpenCode will fall back to `"build"` with a warning.
- This setting applies across all interfaces: TUI, CLI (`opencode run`), desktop app, and GitHub Action.
- ---
- ### Sharing
- You can configure the [share](/docs/share) feature through the `share` option.
- ```json title="opencode.json"
- {
- "$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.
- ---
- ### Commands
- You can configure custom commands for repetitive tasks through the `command` option.
- ```jsonc title="opencode.jsonc"
- {
- "$schema": "https://opencode.ai/config.json",
- "command": {
- "test": {
- "template": "Run the full test suite with coverage report and show any failures.\nFocus on the failing tests and suggest fixes.",
- "description": "Run tests with coverage",
- "agent": "build",
- "model": "anthropic/claude-haiku-4-5",
- },
- "component": {
- "template": "Create a new React component named $ARGUMENTS with TypeScript support.\nInclude proper typing and basic structure.",
- "description": "Create a new component",
- },
- },
- }
- ```
- You can also define commands using markdown files in `~/.config/opencode/commands/` or `.opencode/commands/`. [Learn more here](/docs/commands).
- ---
- ### Keybinds
- Customize keybinds in `tui.json`.
- ```json title="tui.json"
- {
- "$schema": "https://opencode.ai/tui.json",
- "keybinds": {}
- }
- ```
- [Learn more here](/docs/keybinds).
- ---
- ### Autoupdate
- OpenCode will automatically download any new updates when it starts up. You can disable this with the `autoupdate` option.
- ```json title="opencode.json"
- {
- "$schema": "https://opencode.ai/config.json",
- "autoupdate": false
- }
- ```
- If you don't want updates but want to be notified when a new version is available, set `autoupdate` to `"notify"`.
- Notice that this only works if it was not installed using a package manager such as Homebrew.
- ---
- ### Formatters
- You can configure code formatters through the `formatter` option.
- ```json title="opencode.json"
- {
- "$schema": "https://opencode.ai/config.json",
- "formatter": {
- "prettier": {
- "disabled": true
- },
- "custom-prettier": {
- "command": ["npx", "prettier", "--write", "$FILE"],
- "environment": {
- "NODE_ENV": "development"
- },
- "extensions": [".js", ".ts", ".jsx", ".tsx"]
- }
- }
- }
- ```
- [Learn more about formatters here](/docs/formatters).
- ---
- ### Permissions
- By default, opencode **allows all operations** without requiring explicit approval. You can change this using the `permission` option.
- For example, to ensure that the `edit` and `bash` tools require user approval:
- ```json title="opencode.json"
- {
- "$schema": "https://opencode.ai/config.json",
- "permission": {
- "edit": "ask",
- "bash": "ask"
- }
- }
- ```
- [Learn more about permissions here](/docs/permissions).
- ---
- ### Compaction
- You can control context compaction behavior through the `compaction` option.
- ```json title="opencode.json"
- {
- "$schema": "https://opencode.ai/config.json",
- "compaction": {
- "auto": true,
- "prune": true,
- "reserved": 10000
- }
- }
- ```
- - `auto` - Automatically compact the session when context is full (default: `true`).
- - `prune` - Remove old tool outputs to save tokens (default: `true`).
- - `reserved` - Token buffer for compaction. Leaves enough window to avoid overflow during compaction
- ---
- ### Watcher
- You can configure file watcher ignore patterns through the `watcher` option.
- ```json title="opencode.json"
- {
- "$schema": "https://opencode.ai/config.json",
- "watcher": {
- "ignore": ["node_modules/**", "dist/**", ".git/**"]
- }
- }
- ```
- Patterns follow glob syntax. Use this to exclude noisy directories from file watching.
- ---
- ### MCP servers
- You can configure MCP servers you want to use through the `mcp` option.
- ```json title="opencode.json"
- {
- "$schema": "https://opencode.ai/config.json",
- "mcp": {}
- }
- ```
- [Learn more here](/docs/mcp-servers).
- ---
- ### Plugins
- [Plugins](/docs/plugins) extend OpenCode with custom tools, hooks, and integrations.
- Place plugin files in `.opencode/plugins/` or `~/.config/opencode/plugins/`. You can also load plugins from npm through the `plugin` option.
- ```json title="opencode.json"
- {
- "$schema": "https://opencode.ai/config.json",
- "plugin": ["opencode-helicone-session", "@my-org/custom-plugin"]
- }
- ```
- [Learn more here](/docs/plugins).
- ---
- ### Instructions
- You can configure the instructions for the model you're using through the `instructions` option.
- ```json title="opencode.json"
- {
- "$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](/docs/rules).
- ---
- ### 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.
- ```json title="opencode.json"
- {
- "$schema": "https://opencode.ai/config.json",
- "disabled_providers": ["openai", "gemini"]
- }
- ```
- :::note
- The `disabled_providers` takes priority over `enabled_providers`.
- :::
- 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 the `/connect` command.
- - The provider's models won't appear in the model selection list.
- ---
- ### Enabled providers
- You can specify an allowlist of providers through the `enabled_providers` option. When set, only the specified providers will be enabled and all others will be ignored.
- ```json title="opencode.json"
- {
- "$schema": "https://opencode.ai/config.json",
- "enabled_providers": ["anthropic", "openai"]
- }
- ```
- This is useful when you want to restrict OpenCode to only use specific providers rather than disabling them one by one.
- :::note
- The `disabled_providers` takes priority over `enabled_providers`.
- :::
- If a provider appears in both `enabled_providers` and `disabled_providers`, the `disabled_providers` takes priority for backwards compatibility.
- ---
- ### Experimental
- The `experimental` key contains options that are under active development.
- ```json title="opencode.json"
- {
- "$schema": "https://opencode.ai/config.json",
- "experimental": {}
- }
- ```
- :::caution
- Experimental options are not stable. They may change or be removed without notice.
- :::
- ---
- ## 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:
- ```json title="opencode.json"
- {
- "$schema": "https://opencode.ai/config.json",
- "model": "{env:OPENCODE_MODEL}",
- "provider": {
- "anthropic": {
- "models": {},
- "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:
- ```json title="opencode.json"
- {
- "$schema": "https://opencode.ai/config.json",
- "instructions": ["./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.
|