config.mdx 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. ---
  2. title: Config
  3. description: Using the opencode JSON config.
  4. ---
  5. You can configure opencode using a JSON config file.
  6. ```json title="opencode.json"
  7. {
  8. "$schema": "https://opencode.ai/config.json",
  9. "theme": "opencode",
  10. "model": "anthropic/claude-sonnet-4-20250514",
  11. "autoshare": false,
  12. "autoupdate": true
  13. }
  14. ```
  15. This can be used to configure opencode globally or for a specific project.
  16. ---
  17. ### Global
  18. Place your global opencode config in `~/.config/opencode/opencode.json`. You'll want to use the global config for things like themes, providers, or keybinds.
  19. ---
  20. ### Per project
  21. You can also add a `opencode.json` in your project. This is useful for configuring providers or modes specific to your project.
  22. When opencode starts up, it looks for a config file in the current directory or traverse up to the nearest Git directory.
  23. This is also safe to be checked into Git and uses the same schema as the global one.
  24. ---
  25. ## Schema
  26. The config file has a schema that's defined in [**`opencode.ai/config.json`**](https://opencode.ai/config.json).
  27. Your editor should be able to validate and autocomplete based on the schema.
  28. ---
  29. ### Modes
  30. opencode comes with two built-in modes: _build_, the default with all tools enabled. And _plan_, restricted mode with file modification tools disabled. You can override these built-in modes or define your own custom modes with the `mode` option.
  31. ```json title="opencode.json"
  32. {
  33. "$schema": "https://opencode.ai/config.json",
  34. "mode": {
  35. "build": { },
  36. "plan": { },
  37. "my-custom-mode": { }
  38. }
  39. }
  40. ```
  41. [Learn more here](/docs/modes).
  42. ---
  43. ### Models
  44. You can configure the providers and models you want to use in your opencode config through the `provider` and `model` options.
  45. ```json title="opencode.json"
  46. {
  47. "$schema": "https://opencode.ai/config.json",
  48. "provider": {},
  49. "model": ""
  50. }
  51. ```
  52. You can also configure [local models](/docs/models#local). [Learn more](/docs/models).
  53. ---
  54. ### Themes
  55. You can configure the theme you want to use in your opencode config through the `theme` option.
  56. ```json title="opencode.json"
  57. {
  58. "$schema": "https://opencode.ai/config.json",
  59. "theme": ""
  60. }
  61. ```
  62. [Learn more here](/docs/themes).
  63. ---
  64. ### Logging
  65. Logs are written to:
  66. - **macOS/Linux**: `~/.local/share/opencode/log/`
  67. - **Windows**: `%APPDATA%\opencode\log\`
  68. You can configure the minimum log level through the `log_level` option.
  69. ```json title="opencode.json"
  70. {
  71. "$schema": "https://opencode.ai/config.json",
  72. "log_level": "INFO"
  73. }
  74. ```
  75. With the following options:
  76. | Level | Description |
  77. | ------- | ---------------------------------------- |
  78. | `DEBUG` | All messages including debug information |
  79. | `INFO` | Informational messages and above |
  80. | `WARN` | Warnings and errors only |
  81. | `ERROR` | Errors only |
  82. The **default** log level is `INFO`. If you are running opencode locally in
  83. development mode it's set to `DEBUG`.
  84. ---
  85. ### Keybinds
  86. You can customize your keybinds through the `keybinds` option.
  87. ```json title="opencode.json"
  88. {
  89. "$schema": "https://opencode.ai/config.json",
  90. "keybinds": {}
  91. }
  92. ```
  93. [Learn more here](/docs/keybinds).
  94. ---
  95. ### MCP servers
  96. You can configure MCP servers you want to use through the `mcp` option.
  97. ```json title="opencode.json"
  98. {
  99. "$schema": "https://opencode.ai/config.json",
  100. "mcp": {}
  101. }
  102. ```
  103. [Learn more here](/docs/mcp-servers).
  104. ---
  105. ### Disabled providers
  106. 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.
  107. ```json title="opencode.json"
  108. {
  109. "$schema": "https://opencode.ai/config.json",
  110. "disabled_providers": ["openai", "gemini"]
  111. }
  112. ```
  113. The `disabled_providers` option accepts an array of provider IDs. When a provider is disabled:
  114. - It won't be loaded even if environment variables are set
  115. - It won't be loaded even if API keys are configured through `opencode auth login`
  116. - The provider's models won't appear in the model selection list
  117. ---
  118. ## Variables
  119. You can use variable substitution in your config files to reference environment variables and file contents.
  120. ---
  121. ### Env vars
  122. Use `{env:VARIABLE_NAME}` to substitute environment variables:
  123. ```json title="opencode.json"
  124. {
  125. "$schema": "https://opencode.ai/config.json",
  126. "model": "{env:OPENCODE_MODEL}",
  127. "provider": {
  128. "anthropic": {
  129. "api_key": "{env:ANTHROPIC_API_KEY}"
  130. }
  131. }
  132. }
  133. ```
  134. If the environment variable is not set, it will be replaced with an empty string.
  135. ---
  136. ### Files
  137. Use `{file:path/to/file}` to substitute the contents of a file:
  138. ```json title="opencode.json"
  139. {
  140. "$schema": "https://opencode.ai/config.json",
  141. "instructions": ["{file:./custom-instructions.md}"],
  142. "provider": {
  143. "openai": {
  144. "api_key": "{file:~/.secrets/openai-key}"
  145. }
  146. }
  147. }
  148. ```
  149. File paths can be:
  150. - Relative to the config file directory
  151. - Or absolute paths starting with `/` or `~`
  152. These are useful for:
  153. - Keeping sensitive data like API keys in separate files.
  154. - Including large instruction files without cluttering your config.
  155. - Sharing common configuration snippets across multiple config files.