Konfiguration
OpenCode verwendet ein JSON-Konfigurationssystem zur Anpassung. Das Konfigurationsschema ist unter opencode.ai/config.json definiert und ermöglicht Editor-Validierung und Autovervollständigung.
Format-Unterstützung
OpenCode akzeptiert sowohl JSON als auch JSONC (JSON mit Kommentaren) Formate.
{
"$schema": "https://opencode.ai/config.json",
"theme": "opencode",
"model": "anthropic/claude-sonnet-4-5",
"autoupdate": true
}Konfigurationsorte & Priorität
Einstellungen werden zusammengeführt statt ersetzt. Die Ladereihenfolge (spätere Quellen überschreiben Konflikte):
- Remote-Konfiguration – Organisationsstandards von
.well-known/opencode - Globale Konfiguration – Benutzereinstellungen unter
~/.config/opencode/opencode.json - Benutzerdefinierte Konfiguration –
OPENCODE_CONFIGUmgebungsvariable - Projekt-Konfiguration –
opencode.jsonim Projektstammverzeichnis .opencode-Verzeichnisse – Agenten, Befehle, Plugins- Inline-Konfiguration –
OPENCODE_CONFIG_CONTENTUmgebungsvariable
Globale Konfiguration
Platzieren Sie benutzerweite Einstellungen in ~/.config/opencode/opencode.json:
{
"theme": "catppuccin",
"model": "anthropic/claude-sonnet-4-5"
}Projekt-Konfiguration
Fügen Sie opencode.json zu Ihrem Projektstammverzeichnis für projektspezifische Einstellungen hinzu.
Benutzerdefinierter Pfad
export OPENCODE_CONFIG=/path/to/config.json
opencode run "Hello world"Konfigurationsschema
TUI-Einstellungen
{
"tui": {
"scroll_speed": 3,
"scroll_acceleration": {
"enabled": true
},
"diff_style": "auto"
}
}Server-Einstellungen
{
"server": {
"port": 4096,
"hostname": "0.0.0.0",
"mdns": true,
"cors": ["http://localhost:5173"]
}
}Werkzeug-Konfiguration
{
"tools": {
"write": false,
"bash": false
}
}Modelle & Anbieter
{
"provider": {},
"model": "anthropic/claude-sonnet-4-5",
"small_model": "anthropic/claude-haiku-4-5"
}Agenten
{
"agent": {
"code-reviewer": {
"description": "Reviews code for best practices",
"model": "anthropic/claude-sonnet-4-5",
"prompt": "You are a code reviewer...",
"tools": {
"write": false,
"edit": false
}
}
}
}Benutzerdefinierte Befehle
{
"command": {
"test": {
"template": "Run full test suite with coverage report.",
"description": "Run tests with coverage",
"agent": "build"
}
}
}Berechtigungen
{
"permission": {
"edit": "ask",
"bash": "ask"
}
}Kontext-Komprimierung
{
"compaction": {
"auto": true,
"prune": true
}
}MCP-Server
{
"mcp": {}
}Plugins
{
"plugin": ["opencode-helicone-session", "@my-org/custom-plugin"]
}Variablensubstitution
Umgebungsvariablen
{
"model": "{env:OPENCODE_MODEL}",
"provider": {
"anthropic": {
"options": {
"apiKey": "{env:ANTHROPIC_API_KEY}"
}
}
}
}Dateiinhalte
{
"provider": {
"openai": {
"options": {
"apiKey": "{file:~/.secrets/openai-key}"
}
}
}
}