config.mdx 9.0 KB

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