config.mdx 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463
  1. ---
  2. title: "Config"
  3. ---
  4. You shouldn't have to configure OpenCode manually. Ask OpenCode to update its configuration for you.
  5. ## Format
  6. OpenCode supports both **JSON** and **JSONC** (JSON with Comments) configuration files.
  7. ```jsonc title="opencode.jsonc"
  8. {
  9. "$schema": "https://opencode.ai/config.json",
  10. "model": "openai/gpt-5.2-custom",
  11. "providers": {
  12. "openai": {
  13. "models": {
  14. "gpt-5.2-custom": {
  15. "modelID": "gpt-5.2",
  16. "name": "GPT-5.2 Custom",
  17. },
  18. },
  19. },
  20. },
  21. }
  22. ```
  23. ## Locations
  24. OpenCode loads global configuration from:
  25. ```text
  26. ~/.config/opencode/opencode.json(c)
  27. ```
  28. Project-specific configuration can use either form:
  29. ```text
  30. /home/user/projects/my-app/opencode.json(c)
  31. /home/user/projects/my-app/.opencode/opencode.json(c)
  32. ```
  33. When OpenCode starts, it searches for configuration files from the current
  34. directory upward to the project root. It merges direct `opencode.json(c)` files
  35. from the project root toward the current directory, then does the same for
  36. files inside `.opencode` directories. A `.opencode` config therefore overrides
  37. every direct config, even when the direct config is closer to the current
  38. directory. Avoid mixing the two forms across one project hierarchy unless this
  39. precedence is intentional.
  40. For example, consider a monorepo with OpenCode started from
  41. `/home/user/projects/acme/packages/web`:
  42. ```text
  43. ~/.config/opencode/opencode.json
  44. /home/user/projects/acme/
  45. ├── opencode.json
  46. └── packages/
  47. └── web/
  48. ├── opencode.json
  49. └── src/
  50. ```
  51. OpenCode applies these files from lowest to highest precedence:
  52. 1. `~/.config/opencode/opencode.json`
  53. 2. `/home/user/projects/acme/opencode.json`
  54. 3. `/home/user/projects/acme/packages/web/opencode.json`
  55. In this direct-config example, the package config overrides matching settings
  56. from the repository config, which overrides matching settings from the global
  57. config. Settings that do not conflict are preserved from every file.
  58. ## Schema
  59. The complete OpenCode configuration schema is available at
  60. [opencode.ai/config.json](https://opencode.ai/config.json).
  61. Add the `$schema` field to your configuration file to enable validation and
  62. autocomplete in editors that support JSON Schema:
  63. ```json title="opencode.json"
  64. {
  65. "$schema": "https://opencode.ai/config.json"
  66. }
  67. ```
  68. Use the schema as the source of truth for available fields, accepted values,
  69. and nested configuration shapes.
  70. ### Shell
  71. Set the shell used by the terminal and shell tools.
  72. ```jsonc
  73. {
  74. "shell": "/bin/zsh",
  75. }
  76. ```
  77. ### Model
  78. Set the default model in `provider/model` format. The root default currently
  79. does not retain a `#variant`; agent and command model references can select one.
  80. ```jsonc
  81. {
  82. "model": "anthropic/claude-sonnet-4-5",
  83. }
  84. ```
  85. See the [models guide](/models) for model selection and local models.
  86. ### Default agent
  87. Choose the primary agent used when a session does not select one explicitly.
  88. ```jsonc
  89. {
  90. "default_agent": "build",
  91. }
  92. ```
  93. See the [agents guide](/agents) for built-in and custom
  94. agents.
  95. ### Autoupdate
  96. Control automatic updates from the global config. Set this to `false` to
  97. disable updates. The current beta treats `true` and `"notify"` identically and
  98. automatically installs compatible non-major updates; project-level values are
  99. ignored.
  100. ```jsonc
  101. {
  102. "autoupdate": false,
  103. }
  104. ```
  105. ### Sharing
  106. Set the intended session sharing policy. V2 accepts this field, but session
  107. sharing is not implemented yet.
  108. ```jsonc
  109. {
  110. "share": "manual",
  111. }
  112. ```
  113. See the [sharing guide](/sharing) for more details.
  114. ### Username
  115. Set a username for future display behavior. V2 accepts this field but does not
  116. currently display it in conversations.
  117. ```jsonc
  118. {
  119. "username": "alice",
  120. }
  121. ```
  122. ### Permissions
  123. Define ordered rules that allow, deny, or ask before an agent uses a tool on a
  124. matching resource.
  125. ```jsonc
  126. {
  127. "permissions": [
  128. {
  129. "action": "shell",
  130. "resource": "git push *",
  131. "effect": "ask",
  132. },
  133. ],
  134. }
  135. ```
  136. See the [permissions guide](/permissions) for rule matching and available actions.
  137. ### Agents
  138. Override built-in agents or define specialized agents with their own model,
  139. instructions, mode, and permissions.
  140. ```jsonc
  141. {
  142. "agents": {
  143. "reviewer": {
  144. "description": "Review changes without editing files",
  145. "mode": "subagent",
  146. "system": "Focus on correctness, security, and missing tests.",
  147. "permissions": [{ "action": "edit", "resource": "*", "effect": "deny" }],
  148. },
  149. },
  150. }
  151. ```
  152. See the [agents guide](/agents) for all agent options and file-based agents.
  153. ### Snapshots
  154. Enable or disable filesystem snapshots used by undo and revert behavior.
  155. ```jsonc
  156. {
  157. "snapshots": false,
  158. }
  159. ```
  160. See the [snapshots guide](/snapshots) for undo and redo behavior.
  161. ### Watcher
  162. Ignore files and directories that should not trigger filesystem updates.
  163. ```jsonc
  164. {
  165. "watcher": {
  166. "ignore": ["dist/**", "coverage/**"],
  167. },
  168. }
  169. ```
  170. ### Formatter
  171. Define formatter settings for compatibility and future use. V2 accepts this
  172. field, but it does not run formatters yet.
  173. ```jsonc
  174. {
  175. "formatter": {
  176. "prettier": {
  177. "command": ["bunx", "prettier", "--write", "$FILE"],
  178. "extensions": [".js", ".ts", ".tsx"],
  179. },
  180. },
  181. }
  182. ```
  183. See the [formatters guide](/formatters) for accepted fields and current limitations.
  184. ### LSP
  185. Define language server settings for compatibility and future use. V2 accepts
  186. this field, but it does not start language servers yet.
  187. ```jsonc
  188. {
  189. "lsp": {
  190. "typescript": {
  191. "command": ["typescript-language-server", "--stdio"],
  192. "extensions": [".ts", ".tsx"],
  193. },
  194. },
  195. }
  196. ```
  197. See the [LSP guide](/lsp) for accepted fields and current limitations.
  198. ### Media
  199. Control how oversized images loaded by the `read` tool are resized or rejected
  200. before they are sent to a model.
  201. ```jsonc
  202. {
  203. "media": {
  204. "image": {
  205. "auto_resize": true,
  206. "max_width": 2000,
  207. "max_height": 2000,
  208. "max_base64_bytes": 5242880,
  209. },
  210. },
  211. }
  212. ```
  213. See the [attachments guide](/attachments) for image processing and limits.
  214. ### Tool output
  215. Set the maximum number of lines and bytes retained from a tool result.
  216. ```jsonc
  217. {
  218. "tool_output": {
  219. "max_lines": 2000,
  220. "max_bytes": 51200,
  221. },
  222. }
  223. ```
  224. ### MCP
  225. Configure local and remote Model Context Protocol servers. Global timeouts can
  226. be overridden by an individual server.
  227. ```jsonc
  228. {
  229. "mcp": {
  230. "servers": {
  231. "playwright": {
  232. "type": "local",
  233. "command": ["bunx", "@playwright/mcp"],
  234. },
  235. },
  236. },
  237. }
  238. ```
  239. See the [MCP guide](/mcp-servers) for remote servers, OAuth, environment variables, and timeouts.
  240. ### Compaction
  241. Control automatic context compaction and how much recent context it preserves.
  242. ```jsonc
  243. {
  244. "compaction": {
  245. "auto": true,
  246. "keep": {
  247. "tokens": 15000,
  248. },
  249. "buffer": 20000,
  250. },
  251. }
  252. ```
  253. See the [compaction guide](/compaction) for automatic context management.
  254. ### Session warming
  255. Keep recently active model sessions warm with periodic transient requests.
  256. Warming is disabled by default; set it to `true` to use the four-minute idle
  257. interval and 30-minute active window.
  258. ```jsonc
  259. {
  260. "warming": {
  261. "prompt": "Do not perform any work. Reply with exactly: OK",
  262. "interval": "4 minutes",
  263. "duration": "30 minutes",
  264. },
  265. }
  266. ```
  267. See the [session warming guide](/warming) for request behavior, customization,
  268. and cost considerations.
  269. ### Skills
  270. Add directories or URLs that OpenCode should search for agent skills.
  271. ```jsonc
  272. {
  273. "skills": ["./team-skills", "https://example.com/.well-known/skills/"],
  274. }
  275. ```
  276. See the [skills guide](/skills) for skill structure and automatic discovery under `.opencode/skills/`.
  277. ### Commands
  278. Define reusable slash commands as named prompt templates.
  279. ```jsonc
  280. {
  281. "commands": {
  282. "review": {
  283. "description": "Review the current changes",
  284. "template": "Review the current diff for correctness and missing tests.",
  285. },
  286. },
  287. }
  288. ```
  289. See the [commands guide](/commands) for arguments, models, agents, and file-based commands.
  290. ### Instructions
  291. Declare additional instruction files, globs, or URLs. V2 accepts this field,
  292. but does not load these entries yet; use `AGENTS.md` for active instructions.
  293. ```jsonc
  294. {
  295. "instructions": ["CONTRIBUTING.md", "docs/guidelines/*.md"],
  296. }
  297. ```
  298. See the [instructions guide](/instructions) for project instructions and `AGENTS.md`.
  299. ### References
  300. Make local directories or Git repositories available as named supporting
  301. context.
  302. ```jsonc
  303. {
  304. "references": {
  305. "docs": {
  306. "path": "../product-docs",
  307. "description": "Product behavior and terminology",
  308. },
  309. "effect": {
  310. "repository": "Effect-TS/effect",
  311. "branch": "main",
  312. },
  313. },
  314. }
  315. ```
  316. See the [references guide](/references) for shorthand, visibility, and path resolution.
  317. ### Plugins
  318. Load plugins from packages or local files. Use the object form when a plugin
  319. accepts options.
  320. ```jsonc
  321. {
  322. "plugins": [
  323. "opencode-example-plugin",
  324. {
  325. "package": "./plugins/local.ts",
  326. "options": {
  327. "enabled": true,
  328. },
  329. },
  330. ],
  331. }
  332. ```
  333. See the [plugins guide](/build/plugins) for plugin development and configuration.
  334. ### Providers
  335. Configure providers and add or override their models, request settings,
  336. headers, and model variants.
  337. ```jsonc
  338. {
  339. "providers": {
  340. "openai": {
  341. "models": {
  342. "gpt-5.2-custom": {
  343. "modelID": "gpt-5.2",
  344. "name": "GPT-5.2 Custom",
  345. "limit": {
  346. "context": 200000,
  347. "output": 32000,
  348. },
  349. },
  350. },
  351. },
  352. },
  353. }
  354. ```
  355. See the [providers guide](/providers) for credentials, custom endpoints, provider packages, and model configuration.