Start typing to search the documentation.

Docs navigation

Config

You shouldn’t have to configure OpenCode manually. Ask OpenCode to update its configuration for you.

Format

OpenCode supports both JSON and JSONC (JSON with Comments) configuration files.

opencode.jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "model": "openai/gpt-5.2-custom",
  "providers": {
    "openai": {
      "models": {
        "gpt-5.2-custom": {
          "modelID": "gpt-5.2",
          "name": "GPT-5.2 Custom",
        },
      },
    },
  },
}

Locations

OpenCode loads global configuration from:

~/.config/opencode/opencode.json(c)

Project-specific configuration can use either form:

/home/user/projects/my-app/opencode.json(c)
/home/user/projects/my-app/.opencode/opencode.json(c)

During ordinary project discovery, OpenCode searches for configuration files from the current Location directory through every ancestor to the filesystem root, including directories above the detected project or repository root. It merges direct opencode.json(c) files from the farthest ancestor toward the current directory, then does the same for files inside .opencode directories. A discovered .opencode config therefore overrides every discovered direct config, even when the direct config is closer to the current directory. Avoid mixing the two forms across one directory hierarchy unless this precedence is intentional.

For example, consider a monorepo with OpenCode started from /home/user/projects/acme/packages/web:

~/.config/opencode/opencode.json

/home/user/projects/acme/
├── opencode.json
└── packages/
    └── web/
        ├── opencode.json
        └── src/

OpenCode applies these files from lowest to highest precedence:

  1. ~/.config/opencode/opencode.json
  2. /home/user/projects/acme/opencode.json
  3. /home/user/projects/acme/packages/web/opencode.json

In this direct-config example, the package config overrides matching settings from the repository config, which overrides matching settings from the global config. Settings that do not conflict are preserved from every file.

Schema

The complete OpenCode configuration schema is available at opencode.ai/config.json.

Add the $schema field to your configuration file to enable validation and autocomplete in editors that support JSON Schema:

opencode.json
{
  "$schema": "https://opencode.ai/config.json"
}

Use the schema as the source of truth for available fields, accepted values, and nested configuration shapes.

Shell

Set the shell used by the terminal and shell tools.

{
  "shell": "/bin/zsh",
}

Model

Set the default model in provider/model format. The root default currently does not retain a #variant; agent and command model references can select one.

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

See the models guide for model selection and local models.

Default agent

Choose the primary agent used when a session does not select one explicitly.

{
  "default_agent": "build",
}

See the agents guide for built-in and custom agents.

Updates

Control update checks from the global config. Set update to "disable" to skip them, "notify" to show available updates before installing them, or "auto" to install updates automatically. When omitted, update defaults to "notify".

Automatic installation does not restart a running server. Restart it manually to activate the installed update. Project-level values are ignored.

{
  "update": "notify",
}

Sharing

Set the intended session sharing policy. V2 accepts this field, but session sharing is not implemented yet.

{
  "share": "manual",
}

See the sharing guide for more details.

Username

Set a username for future display behavior. V2 accepts this field but does not currently display it in conversations.

{
  "username": "alice",
}

Permissions

Define ordered rules that allow, deny, or ask before an agent uses a tool on a matching resource.

{
  "permissions": [
    {
      "action": "shell",
      "resource": "git push *",
      "effect": "ask",
    },
  ],
}

See the permissions guide for rule matching and available actions.

Agents

Override built-in agents or define specialized agents with their own model, instructions, mode, and permissions.

{
  "agents": {
    "reviewer": {
      "description": "Review changes without editing files",
      "mode": "subagent",
      "system": "Focus on correctness, security, and missing tests.",
      "permissions": [{ "action": "edit", "resource": "*", "effect": "deny" }],
    },
  },
}

See the agents guide for all agent options and file-based agents.

Snapshots

Enable or disable filesystem snapshots used by undo and revert behavior.

{
  "snapshots": false,
}

See the snapshots guide for undo and redo behavior.

Watcher

Ignore files and directories that should not trigger filesystem updates.

{
  "watcher": {
    "ignore": ["dist/**", "coverage/**"],
  },
}

Formatter

Define formatter settings for compatibility and future use. V2 accepts this field, but it does not run formatters yet.

{
  "formatter": {
    "prettier": {
      "command": ["bunx", "prettier", "--write", "$FILE"],
      "extensions": [".js", ".ts", ".tsx"],
    },
  },
}

See the formatters guide for accepted fields and current limitations.

LSP

Define language server settings for compatibility and future use. V2 accepts this field, but it does not start language servers yet.

{
  "lsp": {
    "typescript": {
      "command": ["typescript-language-server", "--stdio"],
      "extensions": [".ts", ".tsx"],
    },
  },
}

See the LSP guide for accepted fields and current limitations.

Media

Control how oversized images loaded by the read tool are resized or rejected before they are sent to a model.

{
  "media": {
    "image": {
      "auto_resize": true,
      "max_width": 2000,
      "max_height": 2000,
      "max_base64_bytes": 5242880,
    },
  },
}

See the attachments guide for image processing and limits.

Tool output

Set the maximum number of lines and bytes retained from a tool result.

{
  "tool_output": {
    "max_lines": 2000,
    "max_bytes": 51200,
  },
}

Use "random" to randomly choose a search provider for each session and keep using it until it returns HTTP 429. OpenCode then retries the query with another available provider.

{
  "websearch": {
    "provider": "random",
  },
}
  • Rate-limited providers cool down for Retry-After, or 60 seconds if it is missing or invalid.
  • When every provider is cooling down, the search fails without waiting.
  • Each session remembers its preferred provider; cooldowns are shared within a Location.
  • State is kept in memory. Moving a session or restarting its Location services resets its preference.
  • API and plugin queries without session context share a Location-level preference.
  • Set provider to a provider ID to disable automatic switching, or set websearch to false to disable search.

MCP

Configure local and remote Model Context Protocol servers. Global timeouts can be overridden by an individual server.

{
  "mcp": {
    "servers": {
      "playwright": {
        "type": "local",
        "command": ["bunx", "@playwright/mcp"],
      },
    },
  },
}

See the MCP guide for remote servers, OAuth, environment variables, and timeouts.

Compaction

Control automatic context compaction and how much recent context it preserves.

{
  "compaction": {
    "auto": true,
    "keep": {
      "tokens": 15000,
    },
    "buffer": 20000,
  },
}

Local summaries remain the default. Opt into native provider compaction for both automatic and manual requests with a provider or model policy:

{
  "providers": {
    "openai": {
      "compaction": { "mode": "provider", "threshold": 120000 },
      "models": {
        "gpt-4.1": { "compaction": { "mode": "local" } },
      },
    },
  },
}

A model policy replaces the whole provider policy. The optional positive integer threshold defaults to the selected model’s usable input budget and cannot exceed its safe ceiling. Provider checkpoints keep recent user messages within the same compaction.tokens budget that local summaries use for their retained tail. Top-level compaction.auto: false disables new automatic compaction without discarding installed checkpoints. See the compaction guide for budgeting and overflow recovery.

Session warming

Keep recently active model sessions warm with periodic transient requests. Warming is disabled by default; set it to true to use the four-minute idle interval and 30-minute active window.

{
  "warming": {
    "prompt": "Do not perform any work. Reply with exactly: OK",
    "interval": "4 minutes",
    "duration": "30 minutes",
  },
}

See the session warming guide for request behavior, customization, and cost considerations.

Skills

Add directories or URLs that OpenCode should search for agent skills.

{
  "skills": ["./team-skills", "https://example.com/.well-known/skills/"],
}

See the skills guide for skill structure and automatic discovery under .opencode/skills/.

Commands

Define reusable slash commands as named prompt templates.

{
  "commands": {
    "review": {
      "description": "Review the current changes",
      "template": "Review the current diff for correctness and missing tests.",
    },
  },
}

See the commands guide for arguments, models, agents, and file-based commands.

Instructions

Declare additional instruction files, globs, or URLs. V2 accepts this field, but does not load these entries yet; use AGENTS.md for active instructions.

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

See the instructions guide for project instructions and AGENTS.md.

References

Make local directories or Git repositories available as named supporting context.

{
  "references": {
    "docs": {
      "path": "../product-docs",
      "description": "Product behavior and terminology",
    },
    "effect": {
      "repository": "Effect-TS/effect",
      "branch": "main",
    },
  },
}

See the references guide for shorthand, visibility, and path resolution.

Worktrees

Set the parent directory for new local worktrees. OpenCode appends the requested or generated worktree name.

{
  "worktree": {
    "directory": "../worktrees",
  },
}

Relative paths resolve against the project’s primary checkout, including when called from a subdirectory or linked worktree. This applies to global and project configuration alike; absolute paths are used as-is, and ~/ resolves against the user’s home directory.

For example, this global configuration places new worktrees under each project’s own .lane/trees/ directory:

{
  "worktree": {
    "directory": ".lane/trees",
  },
}

Without this setting, creation uses the server’s data directory under worktree/<first-six-project-ID-characters>. Configuration applies to the caller’s location, not every clone sharing a project ID. Changing it does not move existing worktrees.

Git is the built-in default. A plugin that registers a strategy automatically becomes the default for its location. Strategy-specific options belong to that plugin, not the worktree config object.

Plugins

Load plugins from packages or local plugin directories. Use the object form when a plugin accepts options.

{
  "plugins": [
    "opencode-example-plugin",
    {
      "package": "./plugins/local",
      "options": {
        "enabled": true,
      },
    },
  ],
}

See the plugins guide for plugin loading and configuration.

Providers

Configure providers and add or override their models, request settings, headers, and model variants.

{
  "providers": {
    "openai": {
      "models": {
        "gpt-5.2-custom": {
          "modelID": "gpt-5.2",
          "name": "GPT-5.2 Custom",
          "limit": {
            "context": 200000,
            "output": 32000,
          },
        },
      },
    },
  },
}

websocket: true on a provider or model opts into its supported session WebSocket; a model policy overrides the provider policy.

See the providers guide for credentials, custom endpoints, provider packages, the WebSocket transport, and model configuration.