Skip to main content
OpenCode uses JSON configuration format and supports both system-level (global) and project-level (local) configuration.

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)
Use project-level configuration to customize settings per project while keeping a global default. The {env:MEGALLM_API_KEY} syntax references the environment variable.

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 directory
3

System-Level Config

~/.config/opencode/opencode.json in home directory

Configuration 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

Available models:
  • gpt-5 - Latest GPT model
  • gpt-4 - GPT-4
  • claude-opus-4-1-20250805 - Claude Opus
  • claude-sonnet-4 - Claude Sonnet
  • gemini-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):
Add to .gitignore:
Setup Instructions for Team (README.md):
Add to your shell config (~/.bashrc or ~/.zshrc) to make it permanent.
This environment variable is referenced in the OpenCode configuration using {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

Check file locations:
Validate JSON syntax:
Check you’re in the right directory:
Check environment variable:
If empty, set it:
Verify key format:
  • Must start with sk-mega-
  • At least 20 characters
  • No extra spaces or quotes
Test the key:
Check config:
Common mistakes:
Verify you have project config:
Ensure proper JSON structure: Project config should use the same structure as system config with provider.anthropic.options.
Common JSON mistakes:
Validate:

Best Practices

Use Local Config for API Keys

Keep API keys in opencode.local.json and add to .gitignore

Share Base Config

Commit opencode.json without API keys for team consistency

Project-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

Other Agents

Configure other CLI and GUI agents

Models Catalog

Browse available models