Skip to content

Config

You can configure OpenCode using the OpenCode config. It can be places in:

  • $HOME/.opencode.json
  • $XDG_CONFIG_HOME/opencode/.opencode.json

Or in the current directory, ./.opencode.json.

OpenCode config

The config file has the following structure.

.opencode.json
{
"data": {
"directory": ".opencode"
},
"providers": {
"openai": {
"apiKey": "your-api-key",
"disabled": false
},
"anthropic": {
"apiKey": "your-api-key",
"disabled": false
},
"groq": {
"apiKey": "your-api-key",
"disabled": false
},
"openrouter": {
"apiKey": "your-api-key",
"disabled": false
}
},
"agents": {
"primary": {
"model": "claude-3.7-sonnet",
"maxTokens": 5000
},
"task": {
"model": "claude-3.7-sonnet",
"maxTokens": 5000
},
"title": {
"model": "claude-3.7-sonnet",
"maxTokens": 80
}
},
"mcpServers": {
"example": {
"type": "stdio",
"command": "path/to/mcp-server",
"env": [],
"args": []
}
},
"lsp": {
"go": {
"disabled": false,
"command": "gopls"
}
},
"debug": false,
"debugLSP": false
}

Environment variables

For the providers, you can also specify the keys using environment variables.

Environment VariableModels
ANTHROPIC_API_KEYClaude
OPENAI_API_KEYOpenAI
GEMINI_API_KEYGoogle Gemini
GROQ_API_KEYGroq
AWS_ACCESS_KEY_IDAmazon Bedrock
AWS_SECRET_ACCESS_KEYAmazon Bedrock
AWS_REGIONAmazon Bedrock
AZURE_OPENAI_ENDPOINTAzure OpenAI
AZURE_OPENAI_API_KEYAzure OpenAI, optional when using Entra ID
AZURE_OPENAI_API_VERSIONAzure OpenAI