Overview
OpenCode uses JSON and JSONC (JSON with Comments) configuration files. Settings are merged from multiple locations, with local configuration taking precedence.File Format
Configuration Locations (Merged)
| Priority | Location | Description |
|---|---|---|
| 1 | ~/.config/opencode/opencode.jsonc | Global settings |
| 2 | opencode.jsonc (project root) | Project settings |
| 3 | OPENCODE_CONFIG env var | Custom file path |
| 4 | OPENCODE_CONFIG_DIR env var | Custom directory |
Core Options
| Option | Type | Description |
|---|---|---|
$schema | string | Schema URL for validation |
theme | string | UI theme name |
model | string | Default model (provider/model-id) |
small_model | string | Model for lightweight tasks |
auto_update | boolean / "notify" | Auto-update behavior |
default_agent | string | Default primary agent |
share | "manual" / "auto" / "disabled" | Session sharing mode |
Tools Configuration
Globally enable or disable tools:Provider Configuration
TUI Configuration
Server Configuration
Compaction Configuration
File Watcher Configuration
Formatter Configuration
Commands Configuration
JSONC Format
Markdown Format
.opencode/command/test.md
Command Placeholders
| Placeholder | Description |
|---|---|
$ARGUMENTS | All arguments |
$1, $2, … | Positional arguments |
!`command` | Shell output injection |
@filepath | File content inclusion |
Variable Substitution
Environment Variables
File Contents
Built-in Tools
| Tool | Description |
|---|---|
bash | Execute shell commands |
edit | Modify files via string replacement |
write | Create/overwrite files |
read | Read file contents |
grep | Search file contents (regex) |
glob | Find files by pattern |
list | List directory contents |
patch | Apply patches |
skill | Load skill definitions |
todowrite | Manage todo lists |
todoread | Read todo lists |
webfetch | Fetch web content |
lsp | (Experimental) LSP integration |
OpenCode CLI
| Command | Description |
|---|---|
opencode | Start TUI |
opencode run [message] | Non-interactive mode |
opencode serve | Start headless server |
opencode web | Start server with web interface |
opencode agent create | Create new agent |
opencode agent list | List agents |
opencode auth login | Configure API keys |
opencode auth list | List authenticated providers |
opencode auth logout | Remove credentials |
opencode mcp add | Add MCP server |
opencode mcp list | List MCP servers |
opencode session list | List sessions |
opencode models | List available models |
opencode stats | Show usage statistics |
opencode upgrade | Update OpenCode |
Global Flags
| Flag | Description |
|---|---|
--help, -h | Display help |
--version, -v | Print version |
--print-logs | Print logs to stderr |
--log-level | DEBUG, INFO, WARN, ERROR |
Environment Variables
| Variable | Description |
|---|---|
OPENCODE_CONFIG | Custom config file path |
OPENCODE_CONFIG_DIR | Custom config directory |
OPENCODE_PERMISSION | Inline JSON permissions |
OPENCODE_DISABLE_AUTOUPDATE | Disable updates |
OPENCODE_EXPERIMENTAL | Enable experimental features |
SDK Reference
Installation
Create Instance
Client Only
Key APIs
See Also
- Agents — Agent types and configuration.
- Permissions — Fine-grained access control.
- Profiles Configuration — Profile-level settings.