config.mdx 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444
  1. ---
  2. title: "Config"
  3. description: "Configure OpenCode."
  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. The files are merged, and configuration
  38. closer to the current directory takes precedence.
  39. For example, consider a monorepo with OpenCode started from
  40. `/home/user/projects/acme/packages/web`:
  41. ```text
  42. ~/.config/opencode/opencode.json
  43. /home/user/projects/acme/
  44. ├── opencode.json
  45. └── packages/
  46. └── web/
  47. ├── opencode.json
  48. └── src/
  49. ```
  50. OpenCode applies these files from lowest to highest precedence:
  51. 1. `~/.config/opencode/opencode.json`
  52. 2. `/home/user/projects/acme/opencode.json`
  53. 3. `/home/user/projects/acme/packages/web/opencode.json`
  54. Settings in the package config override matching settings from the repository
  55. config, which override matching settings from the global config. Settings that
  56. do not conflict are preserved from every file.
  57. ## Schema
  58. The complete OpenCode configuration schema is available at
  59. [opencode.ai/config.json](https://opencode.ai/config.json).
  60. Add the `$schema` field to your configuration file to enable validation and
  61. autocomplete in editors that support JSON Schema:
  62. ```json title="opencode.json"
  63. {
  64. "$schema": "https://opencode.ai/config.json"
  65. }
  66. ```
  67. Use the schema as the source of truth for available fields, accepted values,
  68. and nested configuration shapes.
  69. ### Shell
  70. Set the shell used by the terminal and shell tools.
  71. ```jsonc
  72. {
  73. "shell": "/bin/zsh"
  74. }
  75. ```
  76. ### Model
  77. Set the default model in `provider/model` format. Add `#variant` to select a
  78. specific model variant.
  79. ```jsonc
  80. {
  81. "model": "anthropic/claude-sonnet-4-5#high"
  82. }
  83. ```
  84. See the [models guide](https://opencode.ai/docs/models/) for model selection
  85. 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](https://opencode.ai/docs/agents/) for built-in and custom
  94. agents.
  95. ### Autoupdate
  96. Control automatic updates. Set this to `false` to disable updates or `"notify"`
  97. to receive update notifications.
  98. ```jsonc
  99. {
  100. "autoupdate": false
  101. }
  102. ```
  103. ### Sharing
  104. Control whether sessions can be shared manually, shared automatically, or not
  105. shared at all.
  106. ```jsonc
  107. {
  108. "share": "manual"
  109. }
  110. ```
  111. See the [sharing guide](https://opencode.ai/docs/share/) for more details.
  112. ### Username
  113. Set the username displayed in conversations.
  114. ```jsonc
  115. {
  116. "username": "alice"
  117. }
  118. ```
  119. ### Permissions
  120. Define ordered rules that allow, deny, or ask before an agent uses a tool on a
  121. matching resource.
  122. ```jsonc
  123. {
  124. "permissions": [
  125. {
  126. "action": "bash",
  127. "resource": "git push *",
  128. "effect": "ask"
  129. }
  130. ]
  131. }
  132. ```
  133. See the [permissions guide](https://opencode.ai/docs/permissions/) for rule
  134. matching and available actions.
  135. ### Agents
  136. Override built-in agents or define specialized agents with their own model,
  137. instructions, mode, and permissions.
  138. ```jsonc
  139. {
  140. "agents": {
  141. "reviewer": {
  142. "description": "Review changes without editing files",
  143. "mode": "subagent",
  144. "system": "Focus on correctness, security, and missing tests.",
  145. "permissions": [
  146. { "action": "edit", "resource": "*", "effect": "deny" }
  147. ]
  148. }
  149. }
  150. }
  151. ```
  152. See the [agents guide](https://opencode.ai/docs/agents/) for all agent options
  153. and file-based agents.
  154. ### Snapshots
  155. Enable or disable the snapshots used by undo and revert behavior.
  156. ```jsonc
  157. {
  158. "snapshots": false
  159. }
  160. ```
  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. Enable built-in formatters, disable formatting entirely, or configure formatter
  172. commands by name.
  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](https://opencode.ai/docs/formatters/) for built-in
  184. formatters and custom commands.
  185. ### LSP
  186. Enable built-in language servers, disable them, or configure servers by name.
  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](https://opencode.ai/docs/lsp/) for language server setup.
  198. ### Attachments
  199. Control how oversized image attachments are resized or rejected before they are
  200. sent to a model.
  201. ```jsonc
  202. {
  203. "attachments": {
  204. "image": {
  205. "auto_resize": true,
  206. "max_width": 2000,
  207. "max_height": 2000,
  208. "max_base64_bytes": 5242880
  209. }
  210. }
  211. }
  212. ```
  213. ### Tool output
  214. Set the maximum number of lines and bytes retained from a tool result.
  215. ```jsonc
  216. {
  217. "tool_output": {
  218. "max_lines": 2000,
  219. "max_bytes": 51200
  220. }
  221. }
  222. ```
  223. ### MCP
  224. Configure local and remote Model Context Protocol servers. Global timeouts can
  225. be overridden by an individual server.
  226. ```jsonc
  227. {
  228. "mcp": {
  229. "servers": {
  230. "playwright": {
  231. "type": "local",
  232. "command": ["bunx", "@playwright/mcp"]
  233. }
  234. }
  235. }
  236. }
  237. ```
  238. See the [MCP guide](https://opencode.ai/docs/mcp-servers/) for remote servers,
  239. 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": 8000
  248. },
  249. "buffer": 20000
  250. }
  251. }
  252. ```
  253. ### Skills
  254. Add directories or URLs that OpenCode should search for agent skills.
  255. ```jsonc
  256. {
  257. "skills": ["./team-skills", "https://example.com/.well-known/skills/"]
  258. }
  259. ```
  260. See the [skills guide](https://opencode.ai/docs/skills/) for skill structure and
  261. automatic discovery under `.opencode/skills/`.
  262. ### Commands
  263. Define reusable slash commands as named prompt templates.
  264. ```jsonc
  265. {
  266. "commands": {
  267. "review": {
  268. "description": "Review the current changes",
  269. "template": "Review the current diff for correctness and missing tests."
  270. }
  271. }
  272. }
  273. ```
  274. See the [commands guide](https://opencode.ai/docs/commands/) for arguments,
  275. models, agents, and file-based commands.
  276. ### Instructions
  277. Load additional instruction files, globs, or URLs into the agent's context.
  278. ```jsonc
  279. {
  280. "instructions": ["CONTRIBUTING.md", "docs/guidelines/*.md"]
  281. }
  282. ```
  283. See the [rules guide](https://opencode.ai/docs/rules/) for project instructions
  284. and `AGENTS.md`.
  285. ### References
  286. Make local directories or Git repositories available as named supporting
  287. context.
  288. ```jsonc
  289. {
  290. "references": {
  291. "docs": {
  292. "path": "../product-docs",
  293. "description": "Product behavior and terminology"
  294. },
  295. "effect": {
  296. "repository": "Effect-TS/effect",
  297. "branch": "main"
  298. }
  299. }
  300. }
  301. ```
  302. See the [references guide](https://opencode.ai/docs/references/) for shorthand,
  303. visibility, and path resolution.
  304. ### Plugins
  305. Load plugins from packages or local files. Use the object form when a plugin
  306. accepts options.
  307. ```jsonc
  308. {
  309. "plugins": [
  310. "opencode-example-plugin",
  311. {
  312. "package": "./plugins/local.ts",
  313. "options": {
  314. "enabled": true
  315. }
  316. }
  317. ]
  318. }
  319. ```
  320. See the [plugins guide](/plugins) for plugin development and configuration.
  321. ### Providers
  322. Configure providers and add or override their models, request settings,
  323. headers, and model variants.
  324. ```jsonc
  325. {
  326. "providers": {
  327. "openai": {
  328. "models": {
  329. "gpt-5.2-custom": {
  330. "modelID": "gpt-5.2",
  331. "name": "GPT-5.2 Custom",
  332. "limit": {
  333. "context": 200000,
  334. "output": 32000
  335. }
  336. }
  337. }
  338. }
  339. }
  340. }
  341. ```
  342. See the [providers guide](https://opencode.ai/docs/providers/) for credentials,
  343. custom endpoints, provider packages, and model configuration.