config.mdx 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. ---
  2. title: Config
  3. description: Using the OpenCode JSON config.
  4. ---
  5. You can configure OpenCode using a JSON config file.
  6. ---
  7. ## Format
  8. OpenCode supports both **JSON** and **JSONC** (JSON with Comments) formats.
  9. ```jsonc title="opencode.jsonc"
  10. {
  11. "$schema": "https://opencode.ai/config.json",
  12. "model": "anthropic/claude-sonnet-4-5",
  13. "autoupdate": true,
  14. "server": {
  15. "port": 4096,
  16. },
  17. }
  18. ```
  19. ---
  20. ## Locations
  21. You can place your config in a couple of different locations and they have a
  22. different order of precedence.
  23. :::note
  24. Configuration files are **merged together**, not replaced.
  25. :::
  26. 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.
  27. 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.
  28. ---
  29. ### Precedence order
  30. Config sources are loaded in this order (later sources override earlier ones):
  31. 1. **Remote config** (from `.well-known/opencode`) - organizational defaults
  32. 2. **Global config** (`~/.config/opencode/opencode.json`) - user preferences
  33. 3. **Custom config** (`OPENCODE_CONFIG` env var) - custom overrides
  34. 4. **Project config** (`opencode.json` in project) - project-specific settings
  35. 5. **`.opencode` directories** - agents, commands, plugins
  36. 6. **Inline config** (`OPENCODE_CONFIG_CONTENT` env var) - runtime overrides
  37. This means project configs can override global defaults, and global configs can override remote organizational defaults.
  38. :::note
  39. 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.
  40. :::
  41. ---
  42. ### Remote
  43. Organizations can provide default configuration via the `.well-known/opencode` endpoint. This is fetched automatically when you authenticate with a provider that supports it.
  44. Remote config is loaded first, serving as the base layer. All other config sources (global, project) can override these defaults.
  45. For example, if your organization provides MCP servers that are disabled by default:
  46. ```json title="Remote config from .well-known/opencode"
  47. {
  48. "mcp": {
  49. "jira": {
  50. "type": "remote",
  51. "url": "https://jira.example.com/mcp",
  52. "enabled": false
  53. }
  54. }
  55. }
  56. ```
  57. You can enable specific servers in your local config:
  58. ```json title="opencode.json"
  59. {
  60. "mcp": {
  61. "jira": {
  62. "type": "remote",
  63. "url": "https://jira.example.com/mcp",
  64. "enabled": true
  65. }
  66. }
  67. }
  68. ```
  69. ---
  70. ### Global
  71. Place your global OpenCode config in `~/.config/opencode/opencode.json`. Use global config for user-wide server/runtime preferences like providers, models, and permissions.
  72. For TUI-specific settings, use `~/.config/opencode/tui.json`.
  73. Global config overrides remote organizational defaults.
  74. ---
  75. ### Per project
  76. Add `opencode.json` in your project root. Project config has the highest precedence among standard config files - it overrides both global and remote configs.
  77. For project-specific TUI settings, add `tui.json` alongside it.
  78. :::tip
  79. Place project specific config in the root of your project.
  80. :::
  81. When OpenCode starts up, it looks for a config file in the current directory or traverse up to the nearest Git directory.
  82. This is also safe to be checked into Git and uses the same schema as the global one.
  83. ---
  84. ### Custom path
  85. Specify a custom config file path using the `OPENCODE_CONFIG` environment variable.
  86. ```bash
  87. export OPENCODE_CONFIG=/path/to/my/custom-config.json
  88. opencode run "Hello world"
  89. ```
  90. Custom config is loaded between global and project configs in the precedence order.
  91. ---
  92. ### Custom directory
  93. Specify a custom config directory using the `OPENCODE_CONFIG_DIR`
  94. environment variable. This directory will be searched for agents, commands,
  95. modes, and plugins just like the standard `.opencode` directory, and should
  96. follow the same structure.
  97. ```bash
  98. export OPENCODE_CONFIG_DIR=/path/to/my/config-directory
  99. opencode run "Hello world"
  100. ```
  101. The custom directory is loaded after the global config and `.opencode` directories, so it **can override** their settings.
  102. ---
  103. ## Schema
  104. The server/runtime config schema is defined in [**`opencode.ai/config.json`**](https://opencode.ai/config.json).
  105. TUI config uses [**`opencode.ai/tui.json`**](https://opencode.ai/tui.json).
  106. Your editor should be able to validate and autocomplete based on the schema.
  107. ---
  108. ### TUI
  109. Use a dedicated `tui.json` (or `tui.jsonc`) file for TUI-specific settings.
  110. ```json title="tui.json"
  111. {
  112. "$schema": "https://opencode.ai/tui.json",
  113. "scroll_speed": 3,
  114. "scroll_acceleration": {
  115. "enabled": true
  116. },
  117. "diff_style": "auto"
  118. }
  119. ```
  120. Use `OPENCODE_TUI_CONFIG` to point to a custom TUI config file.
  121. Legacy `theme`, `keybinds`, and `tui` keys in `opencode.json` are deprecated and automatically migrated when possible.
  122. [Learn more about TUI configuration here](/docs/tui#configure).
  123. ---
  124. ### Server
  125. You can configure server settings for the `opencode serve` and `opencode web` commands through the `server` option.
  126. ```json title="opencode.json"
  127. {
  128. "$schema": "https://opencode.ai/config.json",
  129. "server": {
  130. "port": 4096,
  131. "hostname": "0.0.0.0",
  132. "mdns": true,
  133. "mdnsDomain": "myproject.local",
  134. "cors": ["http://localhost:5173"]
  135. }
  136. }
  137. ```
  138. Available options:
  139. - `port` - Port to listen on.
  140. - `hostname` - Hostname to listen on. When `mdns` is enabled and no hostname is set, defaults to `0.0.0.0`.
  141. - `mdns` - Enable mDNS service discovery. This allows other devices on the network to discover your OpenCode server.
  142. - `mdnsDomain` - Custom domain name for mDNS service. Defaults to `opencode.local`. Useful for running multiple instances on the same network.
  143. - `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`.
  144. [Learn more about the server here](/docs/server).
  145. ---
  146. ### Tools
  147. You can manage the tools an LLM can use through the `tools` option.
  148. ```json title="opencode.json"
  149. {
  150. "$schema": "https://opencode.ai/config.json",
  151. "tools": {
  152. "write": false,
  153. "bash": false
  154. }
  155. }
  156. ```
  157. [Learn more about tools here](/docs/tools).
  158. ---
  159. ### Models
  160. You can configure the providers and models you want to use in your OpenCode config through the `provider`, `model` and `small_model` options.
  161. ```json title="opencode.json"
  162. {
  163. "$schema": "https://opencode.ai/config.json",
  164. "provider": {},
  165. "model": "anthropic/claude-sonnet-4-5",
  166. "small_model": "anthropic/claude-haiku-4-5"
  167. }
  168. ```
  169. 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.
  170. Provider options can include `timeout`, `chunkTimeout`, and `setCacheKey`:
  171. ```json title="opencode.json"
  172. {
  173. "$schema": "https://opencode.ai/config.json",
  174. "provider": {
  175. "anthropic": {
  176. "options": {
  177. "timeout": 600000,
  178. "chunkTimeout": 30000,
  179. "setCacheKey": true
  180. }
  181. }
  182. }
  183. }
  184. ```
  185. - `timeout` - Request timeout in milliseconds (default: 300000). Set to `false` to disable.
  186. - `chunkTimeout` - Timeout in milliseconds between streamed response chunks. If no chunk arrives in time, the request is aborted.
  187. - `setCacheKey` - Ensure a cache key is always set for designated provider.
  188. You can also configure [local models](/docs/models#local). [Learn more](/docs/models).
  189. ---
  190. #### Provider-Specific Options
  191. Some providers support additional configuration options beyond the generic `timeout` and `apiKey` settings.
  192. ##### Amazon Bedrock
  193. Amazon Bedrock supports AWS-specific configuration:
  194. ```json title="opencode.json"
  195. {
  196. "$schema": "https://opencode.ai/config.json",
  197. "provider": {
  198. "amazon-bedrock": {
  199. "options": {
  200. "region": "us-east-1",
  201. "profile": "my-aws-profile",
  202. "endpoint": "https://bedrock-runtime.us-east-1.vpce-xxxxx.amazonaws.com"
  203. }
  204. }
  205. }
  206. }
  207. ```
  208. - `region` - AWS region for Bedrock (defaults to `AWS_REGION` env var or `us-east-1`)
  209. - `profile` - AWS named profile from `~/.aws/credentials` (defaults to `AWS_PROFILE` env var)
  210. - `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.
  211. :::note
  212. Bearer tokens (`AWS_BEARER_TOKEN_BEDROCK` or `/connect`) take precedence over profile-based authentication. See [authentication precedence](/docs/providers#authentication-precedence) for details.
  213. :::
  214. [Learn more about Amazon Bedrock configuration](/docs/providers#amazon-bedrock).
  215. ---
  216. ### Themes
  217. Set your UI theme in `tui.json`.
  218. ```json title="tui.json"
  219. {
  220. "$schema": "https://opencode.ai/tui.json",
  221. "theme": "tokyonight"
  222. }
  223. ```
  224. [Learn more here](/docs/themes).
  225. ---
  226. ### Agents
  227. You can configure specialized agents for specific tasks through the `agent` option.
  228. ```jsonc title="opencode.jsonc"
  229. {
  230. "$schema": "https://opencode.ai/config.json",
  231. "agent": {
  232. "code-reviewer": {
  233. "description": "Reviews code for best practices and potential issues",
  234. "model": "anthropic/claude-sonnet-4-5",
  235. "prompt": "You are a code reviewer. Focus on security, performance, and maintainability.",
  236. "tools": {
  237. // Disable file modification tools for review-only agent
  238. "write": false,
  239. "edit": false,
  240. },
  241. },
  242. },
  243. }
  244. ```
  245. You can also define agents using markdown files in `~/.config/opencode/agents/` or `.opencode/agents/`. [Learn more here](/docs/agents).
  246. ---
  247. ### Default agent
  248. You can set the default agent using the `default_agent` option. This determines which agent is used when none is explicitly specified.
  249. ```json title="opencode.json"
  250. {
  251. "$schema": "https://opencode.ai/config.json",
  252. "default_agent": "plan"
  253. }
  254. ```
  255. 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.
  256. This setting applies across all interfaces: TUI, CLI (`opencode run`), desktop app, and GitHub Action.
  257. ---
  258. ### Sharing
  259. You can configure the [share](/docs/share) feature through the `share` option.
  260. ```json title="opencode.json"
  261. {
  262. "$schema": "https://opencode.ai/config.json",
  263. "share": "manual"
  264. }
  265. ```
  266. This takes:
  267. - `"manual"` - Allow manual sharing via commands (default)
  268. - `"auto"` - Automatically share new conversations
  269. - `"disabled"` - Disable sharing entirely
  270. By default, sharing is set to manual mode where you need to explicitly share conversations using the `/share` command.
  271. ---
  272. ### Commands
  273. You can configure custom commands for repetitive tasks through the `command` option.
  274. ```jsonc title="opencode.jsonc"
  275. {
  276. "$schema": "https://opencode.ai/config.json",
  277. "command": {
  278. "test": {
  279. "template": "Run the full test suite with coverage report and show any failures.\nFocus on the failing tests and suggest fixes.",
  280. "description": "Run tests with coverage",
  281. "agent": "build",
  282. "model": "anthropic/claude-haiku-4-5",
  283. },
  284. "component": {
  285. "template": "Create a new React component named $ARGUMENTS with TypeScript support.\nInclude proper typing and basic structure.",
  286. "description": "Create a new component",
  287. },
  288. },
  289. }
  290. ```
  291. You can also define commands using markdown files in `~/.config/opencode/commands/` or `.opencode/commands/`. [Learn more here](/docs/commands).
  292. ---
  293. ### Keybinds
  294. Customize keybinds in `tui.json`.
  295. ```json title="tui.json"
  296. {
  297. "$schema": "https://opencode.ai/tui.json",
  298. "keybinds": {}
  299. }
  300. ```
  301. [Learn more here](/docs/keybinds).
  302. ---
  303. ### Autoupdate
  304. OpenCode will automatically download any new updates when it starts up. You can disable this with the `autoupdate` option.
  305. ```json title="opencode.json"
  306. {
  307. "$schema": "https://opencode.ai/config.json",
  308. "autoupdate": false
  309. }
  310. ```
  311. If you don't want updates but want to be notified when a new version is available, set `autoupdate` to `"notify"`.
  312. Notice that this only works if it was not installed using a package manager such as Homebrew.
  313. ---
  314. ### Formatters
  315. You can configure code formatters through the `formatter` option.
  316. ```json title="opencode.json"
  317. {
  318. "$schema": "https://opencode.ai/config.json",
  319. "formatter": {
  320. "prettier": {
  321. "disabled": true
  322. },
  323. "custom-prettier": {
  324. "command": ["npx", "prettier", "--write", "$FILE"],
  325. "environment": {
  326. "NODE_ENV": "development"
  327. },
  328. "extensions": [".js", ".ts", ".jsx", ".tsx"]
  329. }
  330. }
  331. }
  332. ```
  333. [Learn more about formatters here](/docs/formatters).
  334. ---
  335. ### Permissions
  336. By default, opencode **allows all operations** without requiring explicit approval. You can change this using the `permission` option.
  337. For example, to ensure that the `edit` and `bash` tools require user approval:
  338. ```json title="opencode.json"
  339. {
  340. "$schema": "https://opencode.ai/config.json",
  341. "permission": {
  342. "edit": "ask",
  343. "bash": "ask"
  344. }
  345. }
  346. ```
  347. [Learn more about permissions here](/docs/permissions).
  348. ---
  349. ### Compaction
  350. You can control context compaction behavior through the `compaction` option.
  351. ```json title="opencode.json"
  352. {
  353. "$schema": "https://opencode.ai/config.json",
  354. "compaction": {
  355. "auto": true,
  356. "prune": true,
  357. "reserved": 10000
  358. }
  359. }
  360. ```
  361. - `auto` - Automatically compact the session when context is full (default: `true`).
  362. - `prune` - Remove old tool outputs to save tokens (default: `true`).
  363. - `reserved` - Token buffer for compaction. Leaves enough window to avoid overflow during compaction
  364. ---
  365. ### Watcher
  366. You can configure file watcher ignore patterns through the `watcher` option.
  367. ```json title="opencode.json"
  368. {
  369. "$schema": "https://opencode.ai/config.json",
  370. "watcher": {
  371. "ignore": ["node_modules/**", "dist/**", ".git/**"]
  372. }
  373. }
  374. ```
  375. Patterns follow glob syntax. Use this to exclude noisy directories from file watching.
  376. ---
  377. ### MCP servers
  378. You can configure MCP servers you want to use through the `mcp` option.
  379. ```json title="opencode.json"
  380. {
  381. "$schema": "https://opencode.ai/config.json",
  382. "mcp": {}
  383. }
  384. ```
  385. [Learn more here](/docs/mcp-servers).
  386. ---
  387. ### Plugins
  388. [Plugins](/docs/plugins) extend OpenCode with custom tools, hooks, and integrations.
  389. Place plugin files in `.opencode/plugins/` or `~/.config/opencode/plugins/`. You can also load plugins from npm through the `plugin` option.
  390. ```json title="opencode.json"
  391. {
  392. "$schema": "https://opencode.ai/config.json",
  393. "plugin": ["opencode-helicone-session", "@my-org/custom-plugin"]
  394. }
  395. ```
  396. [Learn more here](/docs/plugins).
  397. ---
  398. ### Instructions
  399. You can configure the instructions for the model you're using through the `instructions` option.
  400. ```json title="opencode.json"
  401. {
  402. "$schema": "https://opencode.ai/config.json",
  403. "instructions": ["CONTRIBUTING.md", "docs/guidelines.md", ".cursor/rules/*.md"]
  404. }
  405. ```
  406. This takes an array of paths and glob patterns to instruction files. [Learn more
  407. about rules here](/docs/rules).
  408. ---
  409. ### Disabled providers
  410. 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.
  411. ```json title="opencode.json"
  412. {
  413. "$schema": "https://opencode.ai/config.json",
  414. "disabled_providers": ["openai", "gemini"]
  415. }
  416. ```
  417. :::note
  418. The `disabled_providers` takes priority over `enabled_providers`.
  419. :::
  420. The `disabled_providers` option accepts an array of provider IDs. When a provider is disabled:
  421. - It won't be loaded even if environment variables are set.
  422. - It won't be loaded even if API keys are configured through the `/connect` command.
  423. - The provider's models won't appear in the model selection list.
  424. ---
  425. ### Enabled providers
  426. 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.
  427. ```json title="opencode.json"
  428. {
  429. "$schema": "https://opencode.ai/config.json",
  430. "enabled_providers": ["anthropic", "openai"]
  431. }
  432. ```
  433. This is useful when you want to restrict OpenCode to only use specific providers rather than disabling them one by one.
  434. :::note
  435. The `disabled_providers` takes priority over `enabled_providers`.
  436. :::
  437. If a provider appears in both `enabled_providers` and `disabled_providers`, the `disabled_providers` takes priority for backwards compatibility.
  438. ---
  439. ### Experimental
  440. The `experimental` key contains options that are under active development.
  441. ```json title="opencode.json"
  442. {
  443. "$schema": "https://opencode.ai/config.json",
  444. "experimental": {}
  445. }
  446. ```
  447. :::caution
  448. Experimental options are not stable. They may change or be removed without notice.
  449. :::
  450. ---
  451. ## Variables
  452. You can use variable substitution in your config files to reference environment variables and file contents.
  453. ---
  454. ### Env vars
  455. Use `{env:VARIABLE_NAME}` to substitute environment variables:
  456. ```json title="opencode.json"
  457. {
  458. "$schema": "https://opencode.ai/config.json",
  459. "model": "{env:OPENCODE_MODEL}",
  460. "provider": {
  461. "anthropic": {
  462. "models": {},
  463. "options": {
  464. "apiKey": "{env:ANTHROPIC_API_KEY}"
  465. }
  466. }
  467. }
  468. }
  469. ```
  470. If the environment variable is not set, it will be replaced with an empty string.
  471. ---
  472. ### Files
  473. Use `{file:path/to/file}` to substitute the contents of a file:
  474. ```json title="opencode.json"
  475. {
  476. "$schema": "https://opencode.ai/config.json",
  477. "instructions": ["./custom-instructions.md"],
  478. "provider": {
  479. "openai": {
  480. "options": {
  481. "apiKey": "{file:~/.secrets/openai-key}"
  482. }
  483. }
  484. }
  485. }
  486. ```
  487. File paths can be:
  488. - Relative to the config file directory
  489. - Or absolute paths starting with `/` or `~`
  490. These are useful for:
  491. - Keeping sensitive data like API keys in separate files.
  492. - Including large instruction files without cluttering your config.
  493. - Sharing common configuration snippets across multiple config files.