Configuration Files
System-Level Configuration
Location:~/.config/opencode/opencode.json
The CLI fetches available models from MegaLLM and adds them to the
provider.anthropic.models section automatically.Project-Level Configuration
Location:./opencode.json (in project root)
Manual Setup
System-Level Manual Setup
Project-Level Manual Setup
Configuration Priority
OpenCode loads configuration in this order (highest to lowest priority):1
Environment Variables
MEGALLM_API_KEY environment variable (referenced via {env:MEGALLM_API_KEY} in config)2
Project-Level Config
./opencode.json in current directory3
System-Level Config
~/.config/opencode/opencode.json in home directoryConfiguration Options
Provider Settings
The CLI automatically fetches and populates the
models object from the MegaLLM API. You can also manually add or override specific models.Tool Settings
gpt-5- Latest GPT modelgpt-4- GPT-4claude-opus-4-1-20250805- Claude Opusclaude-sonnet-4- Claude Sonnetgemini-2.5-pro- Gemini Pro- See Models Catalog for full list
Complete Example
Team Configuration
For team projects, use environment variables to keep API keys out of version control: Shared Configuration (opencode.json - committed to git):
.gitignore:
README.md):
{env:MEGALLM_API_KEY}.
Add to your shell configuration:
Verify Environment Variables
Verification
Check Configuration Files
Validate JSON Syntax
Test API Connection
Test OpenCode
Troubleshooting
Configuration not loading
Configuration not loading
Check file locations:Validate JSON syntax:Check you’re in the right directory:
API key not recognized
API key not recognized
Check environment variable:If empty, set it:Verify key format:
- Must start with
sk-mega- - At least 20 characters
- No extra spaces or quotes
Wrong base URL
Wrong base URL
Check config:Common mistakes:
Project config not overriding system config
Project config not overriding system config
Verify you have project config:Ensure proper JSON structure:
Project config should use the same structure as system config with
provider.anthropic.options.JSON syntax errors
JSON syntax errors
Common JSON mistakes:Validate:
Best Practices
Use Local Config for API Keys
Keep API keys in
opencode.local.json and add to .gitignoreShare Base Config
Commit
opencode.json without API keys for team consistencyProject-Specific Settings
Use project-level config for project-specific context and settings
Validate JSON
Always validate JSON syntax after manual edits
Advanced Usage
Multiple Profiles
CI/CD Configuration
Next Steps
Claude Code Config
Configure Claude Code
Codex Config
Configure Codex/Windsurf
Examples
See practical examples
All Agents Config
Configure all CLI and GUI agents
Models Catalog
Browse available models

