docs: edit mode

This commit is contained in:
Jay V 2025-07-10 13:18:48 -04:00
commit afc53afb35
2 changed files with 144 additions and 103 deletions

View file

@ -3,12 +3,9 @@ title: Config
description: Using the opencode JSON config.
---
You can configure opencode using a JSON config file that can be placed in:
You can configure opencode using a JSON config file.
- Globally under `~/.config/opencode/config.json`.
- Your project root under `opencode.json`. This is safe to be checked into Git and uses the same schema as the global one.
```json
```json title="opencode config"
{
"$schema": "https://opencode.ai/config.json",
"theme": "opencode",
@ -18,60 +15,23 @@ You can configure opencode using a JSON config file that can be placed in:
}
```
In most cases, you'll want to use the global config for things like themes, providers, or keybinds. Having a config per project is useful if you are using different providers for your company.
When opencode starts up, it looks for a config file in the current directory or traverse up to the nearest Git directory.
This can be used to configure opencode globally or for a specific project.
---
## Variable substitution
### Global
You can use variable substitution in your config files to reference environment variables and file contents.
Place your global opencode config in `~/.config/opencode/config.json`. You'll want to use the global config for things like themes, providers, or keybinds.
### Environment variables
---
Use `{env:VARIABLE_NAME}` to substitute environment variables:
### Per project
```json title="opencode.json"
{
"$schema": "https://opencode.ai/config.json",
"model": "{env:OPENCODE_MODEL}",
"provider": {
"anthropic": {
"api_key": "{env:ANTHROPIC_API_KEY}"
}
}
}
```
You can also add a `opencode.json` in your project. This is useful for configuring providers or modes specific to your project.
If the environment variable is not set, it will be replaced with an empty string.
When opencode starts up, it looks for a config file in the current directory or traverse up to the nearest Git directory.
### File contents
Use `{file:path/to/file}` to substitute the contents of a file:
```json title="opencode.json"
{
"$schema": "https://opencode.ai/config.json",
"instructions": ["{file:./custom-instructions.md}"],
"provider": {
"openai": {
"api_key": "{file:~/.secrets/openai-key}"
}
}
}
```
File paths can be:
- Relative to the config file directory
- Absolute paths (starting with `/` or `~`)
This is useful for:
- Keeping sensitive data like API keys in separate files
- Including large instruction files without cluttering your config
- Sharing common configuration snippets across multiple config files
This is also safe to be checked into Git and uses the same schema as the global one.
---
@ -268,3 +228,58 @@ The `disabled_providers` option accepts an array of provider IDs. When a provide
- It won't be loaded even if environment variables are set
- It won't be loaded even if API keys are configured through `opencode auth login`
- The provider's models won't appear in the model selection list
---
## Variables
You can use variable substitution in your config files to reference environment variables and file contents.
---
### Env vars
Use `{env:VARIABLE_NAME}` to substitute environment variables:
```json title="opencode.json"
{
"$schema": "https://opencode.ai/config.json",
"model": "{env:OPENCODE_MODEL}",
"provider": {
"anthropic": {
"api_key": "{env:ANTHROPIC_API_KEY}"
}
}
}
```
If the environment variable is not set, it will be replaced with an empty string.
---
### Files
Use `{file:path/to/file}` to substitute the contents of a file:
```json title="opencode.json"
{
"$schema": "https://opencode.ai/config.json",
"instructions": ["{file:./custom-instructions.md}"],
"provider": {
"openai": {
"api_key": "{file:~/.secrets/openai-key}"
}
}
}
```
File paths can be:
- Relative to the config file directory
- Or absolute paths starting with `/` or `~`
These are useful for:
- Keeping sensitive data like API keys in separate files.
- Including large instruction files without cluttering your config.
- Sharing common configuration snippets across multiple config files.