YouTip LogoYouTip

Opencode Setup File

\n\nOpenCode uses JSON format for configuration.\n\nLet's first look at the global configuration file at ~/.config/opencode/opencode.json:\n\ntouch ~/.config/opencode/opencode.json\n!(https://example.com/wp-content/uploads/2026/04/3961dc84-c1fd-4e4d-9939-f9745d397e0a.png)\n\nContains model provider and configuration information:\n\n{ // JSON Schema(Used for editor validation and auto-completion) "$schema": "https://opencode.ai/config.json", "provider": { // Custom Provider name (when using: deepseek/xxx) "deepseek": { // Use OpenAI-compatible adapter (for DeepSeek-style compatible APIs) "npm": "@ai-sdk/openai-compatible", "options": { // API Base URL (must be in OpenAI-compatible format) "baseURL": "https://api.deepseek.com/v1", // API Key "apiKey": "sk-xxxx", // Whether to force set cache key (improves cache hit rate, reduces costs) "setCacheKey": true }, "models": { // Local model alias (used in CLI/TUI: deepseek/Deepseek-v4) "Deepseek-v4": { // Actual model name invoked (API Layer) "name": "deepseek-v4-pro" } } } }}\n

A Minimal Working Configuration Example

\n\n{ "$schema": "https://opencode.ai/config.json", "model": "anthropic/claude-sonnet-4-5", "autoupdate": true, "theme": "default"}\nCommon global configuration items:\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
Configuration ItemTypeDescription
modelstringDefault main model
small_modelstringLightweight task model (e.g., for title generation)
autoupdateboolean / "notify"Auto-update policy
themestringUI theme
providerobjectModel provider configuration
\n\n

Provider example:

\n\n{ "provider": { "anthropic": { "options": { "timeout": 600000, "setCacheKey": true } } }}\n

Understanding the Configuration "Merge Mechanism"

\n\n

OpenCode's configuration is not overwritten, but layered and merged.

\n\n

Loading Order (from lowest to highest)

\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
OrderSourceDescription
1Remote .well-known/opencodeOrganization default configuration
2Global configuration~/.config/opencode/opencode.json
3Custom pathOPENCODE_CONFIG
4Project configurationopencode.json in the project
5.opencode/ directoryExtended capabilities
6Inline configurationOPENCODE_CONFIG_CONTENT
\n\n

Merge Rules

\n\n
    \n
  • Non-conflicting fields: all retained
  • \n
  • Conflicting fields: the latter overwrites the former
  • \n
\n\n

Example

\n\n

Global configuration:

\n\n{ "autoupdate": true}\n

Project configuration:

\n\n{ "model": "anthropic/claude-sonnet-4-5"}\n

Final result:

\n\n{ "autoupdate": true, "model": "anthropic/claude-sonnet-4-5"}\n\n
\n\n

Project Configuration

\n\n

Create in the project root directory:

\n\nopencode.json\n

Purpose:

\n\n
    \n
  • Define project-specific AI behavior
  • \n
  • Can be committed to Git
  • \n
  • Override global configuration
  • \n
\n\n

Example: Project-level Configuration

\n\n{ "$schema": "https://opencode.ai/config.json", "model": "anthropic/claude-sonnet-4-5", "tools": { "write": true, "bash": true }}\n\n
\n\n

Core Configuration Modules Explained

\n\n{ "model": "anthropic/claude-sonnet-4-5", "small_model": "anthropic/claude-haiku-4-5"}\n

Model and Provider

\n\n{ "model": "anthropic/claude-sonnet-4-5", "small_model": "anthropic/claude-haiku-4-5"}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
FieldDescription
modelMain task model
small_modelLow-cost task model
\n\n

Tool Control

\n\n{ "tools": { "write": false, "bash": false }}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
ToolPurpose
writeWrite files
bashExecute commands
\n\n

This is the first layer of security control.

\n\n

Permission Control

\n\n{ "permission": { "edit": "ask", "bash": "ask" }}\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n
ValueMeaning
allowAuto-execute
askConfirm each time
denyProhibit
\n\n

Agent (Core Capability)

\n\n{ "agent": { "code-reviewer": { "description": "Code review", "model": "anthropic/claude-sonnet-4-5", "prompt": "You are a code reviewer", "tools": { "write": false } } }}\n

Essence: Defining roles + capability scope for AI

\n\n

Command (Automated Prompt)

\n\n{ "command": { "test": { "template": "Run tests and fix failures", "description": "Run tests" } }}\n

Essence: Prompt template system

\n\n

TUI Configuration

\n\n{ "tui": { "scroll_speed": 3, "scroll_acceleration": { "enabled": true }, "diff_style": "auto" }}\n

Server Configuration (API / Web)

\n\n{ "server": { "port": 4096, "hostname": "0.0.0.0", "mdns": true }}\n

Context Compression (Token Optimization)

\n\n{ "compaction": { "auto": true, "prune": true, "reserved": 10000 }}\n

Plugin System

\n\n{ "plugin": [ "opencode-helicone-session", "@my-org/custom-plugin" ]}\n

MCP (Extended Ecosystem)

\n\n{ "mcp": {}}\n

Used to connect external tools (such as Jira, databases, etc.)

\n\n

Instruction System (AI Rules)

\n\n{ "instructions": [ "CONTRIBUTING.md", "docs/*.md" ]}\n

Provider Control

\n\n{ "enabled_providers": , "disabled_providers": }\n

Priority:

\n\n

disabled > enabled

\n\n

Variable System

\n\n

Environment Variables:

\n\n{ "model": "{env:OPENCODE_MODEL}"}\n

File Reference

\n\n{ "apiKey": "{file:~/.secrets/key}"}\n\n
\n\n

Directory Extension Mechanism

\n\n

OpenCode is not just JSON configuration, it also supports directory extensions:

\n\n.opencode/β”œβ”€β”€ agents/β”œβ”€β”€ commands/β”œβ”€β”€ plugins/β”œβ”€β”€ tools/β”œβ”€β”€ themes/\n

Purpose:

\n\n
    \n
  • Markdown-defined agents
  • \n
  • File-level commands
  • \n
  • Plugin extensions
  • \n
\n\n
\n\n

Recommended Starter Configuration

\n\n{ "$schema": "https://opencode.ai/config.json", "model": "anthropic/claude-sonnet-4-5", "small_model": "anthropic/claude-haiku-4-5", "autoupdate": "notify", "tools": { "write": true, "bash": true }, "permission": { "bash": "ask" }, "compaction": { "auto": true, "prune": true }}\n\n
\n\n

Summary (Architecture Perspective)

\n\n

You can understand OpenCode configuration as a four-layer structure:

\n\n

Configuration layer (multi-level merge)
\n↓
\nCapability layer (agent / tools / mcp)
\n↓
\nExecution layer (model / provider)
\n↓
\nInteraction layer (tui / server / web)

\n\n

Essentially, it is not a simple configuration file, but rather:

\n\n

A configuration center for a programmable AI Agent operating system

\n \n
← Assembly TutorialOpencode Oh My Openagent β†’