Skip to main content

Overview

OpenCode uses a JSON configuration file to customize behavior, AI models, providers, integrations, and more. The configuration system supports both global and local (project-specific) settings with automatic merging.

Configuration locations

OpenCode searches for configuration files in the following order:
macOS/Linux:
  • ~/.opencode.json (primary location)
  • $XDG_CONFIG_HOME/opencode/.opencode.json
  • ~/.config/opencode/.opencode.json
Windows:
  • %USERPROFILE%\.opencode.json
  • %LOCALAPPDATA%\opencode\.opencode.json

Configuration structure

Here’s a complete example configuration file:

Configuration options

Data storage

string
default:".opencode"
Directory where OpenCode stores session data, history, and databases.

Working directory

string
Override the default working directory for OpenCode operations.

Agents

Agents are specialized AI assistants for different tasks. OpenCode supports three agent types:
Main coding agent for writing, editing, and debugging code.
string
required
Model ID for the coder agent (e.g., claude-4-sonnet, gpt-4.1)
integer
default:"5000"
Maximum tokens for coder agent responses
string
Reasoning effort level for models that support it (OpenAI o-series, Anthropic extended thinking)Options: low, medium, high
Task agent for code search, analysis, and exploration.
string
required
Model ID for the task agent (typically a faster/cheaper model)
integer
default:"5000"
Maximum tokens for task agent responses
string
Reasoning effort level (if supported by model)
Title agent for generating conversation summaries (auto-configured, maxTokens locked to 80).
string
required
Model ID for the title agent

Providers

Configure API credentials for AI providers. See AI Models for supported providers.
string
API key for the provider. Can also be set via environment variables.
boolean
default:"false"
Disable this provider even if credentials are available.
Supported providers:
  • anthropic - Anthropic API (Claude models)
  • openai - OpenAI API (GPT, o-series models)
  • gemini - Google Gemini API
  • groq - Groq API (Llama, Qwen models)
  • azure - Azure OpenAI Service
  • bedrock - AWS Bedrock
  • vertexai - Google Cloud Vertex AI
  • openrouter - OpenRouter (multi-provider proxy)
  • copilot - GitHub Copilot (uses GitHub token)

MCP servers

Model Context Protocol servers extend OpenCode with additional capabilities.
string
required
Command to execute the MCP server
array
Command-line arguments for the MCP server
array
Environment variables for the MCP server (format: KEY=value)
string
default:"stdio"
MCP server typeOptions: stdio, sse
string
URL for SSE-type MCP servers
object
HTTP headers for SSE-type MCP servers
Example MCP server configurations:

LSP (Language Server Protocol)

Configure language servers for enhanced code intelligence.
string
required
Command to start the language server
array
Command-line arguments for the language server
boolean
default:"false"
Disable this language server
object
Additional LSP server options
Example LSP configurations:

Context paths

array
Files and directories to automatically include as context for the AI.Default paths:
  • .github/copilot-instructions.md
  • .cursorrules
  • .cursor/rules/
  • CLAUDE.md, CLAUDE.local.md
  • opencode.md, opencode.local.md
  • OpenCode.md, OpenCode.local.md
  • OPENCODE.md, OPENCODE.local.md

Terminal UI (TUI)

string
default:"opencode"
Visual theme for the terminal interfaceAvailable themes:
  • opencode (default)
  • catppuccin
  • dracula
  • flexoki
  • gruvbox
  • monokai
  • onedark
  • tokyonight
  • tron

Shell configuration

string
default:"$SHELL or /bin/bash"
Path to the shell used by the bash tool
array
default:"[\"-l\"]"
Arguments passed to the shell

Debug options

boolean
default:"false"
Enable debug mode for verbose logging
boolean
default:"false"
Enable LSP debug mode for language server diagnostics
boolean
default:"true"
Automatically compact conversation history to manage context size

Environment variables

OpenCode supports environment variables for sensitive data:

Provider API keys

Debug options

Configuration precedence

OpenCode merges configuration from multiple sources in this order (later sources override earlier ones):
  1. Built-in defaults - Hardcoded defaults in the application
  2. Global config file - ~/.opencode.json or XDG config directory
  3. Environment variables - API keys and debug flags
  4. Local config file - .opencode.json in project directory
  5. Command-line flags - Runtime flags (e.g., --debug)

Auto-configuration

OpenCode automatically configures default models based on available providers, checking in this order:
  1. GitHub Copilot (if GitHub token found)
  2. Anthropic (if ANTHROPIC_API_KEY set)
  3. OpenAI (if OPENAI_API_KEY set)
  4. Google Gemini (if GEMINI_API_KEY set)
  5. Groq (if GROQ_API_KEY set)
  6. OpenRouter (if OPENROUTER_API_KEY set)
  7. AWS Bedrock (if AWS credentials available)
  8. Azure OpenAI (if AZURE_OPENAI_ENDPOINT set)
  9. Google Cloud Vertex AI (if VERTEXAI_PROJECT and VERTEXAI_LOCATION set)
If no providers are configured, OpenCode will prompt you to set up credentials.

Validation

OpenCode validates your configuration on startup:
  • Model IDs - Ensures configured models are supported
  • Provider credentials - Checks that required API keys are present
  • Token limits - Validates maxTokens doesn’t exceed model context windows
  • LSP servers - Verifies LSP command paths exist
  • MCP servers - Validates MCP server configurations
Invalid configurations are automatically corrected with warnings logged to help you fix issues.

Example configurations

Set your API key via environment:
  • AI Models - Complete list of supported models and providers
  • Architecture - How OpenCode’s configuration system works internally