OpenCode Configuration
Configure OpenCode via opencode.json and AGENTS.md with deterministic provider setup, model selection, permission policies, formatter behavior, and environment variable handling; use when editing opencode configuration, setting model/provider defaults, tightening agent permissions, or troubleshooting OpenCode config behavior.
npx skills add github:pantheon-org/tekhne --skill agentic-harness--opencode-toolkit--configureNavigation hub for OpenCode configuration tasks.
Information Architecture
- Quick Start — working provider + AGENTS.md in under 2 minutes
- When to Use / Scope — what this skill covers
- Mindset — mental model before diving into config fields
- Workflow — step-by-step approach
- Configuration Examples — copy-paste provider and AGENTS.md templates
- Gotchas & Production Caveats — field quirks and safety constraints
- Anti-Patterns — common mistakes with WHY/BAD/GOOD
Quick Start
Add a provider — create/edit opencode.json in your project root:
{
"providers": [
{
"id": "anthropic",
"baseEnv": "ANTHROPIC_API_KEY",
"models": [
{ "id": "claude-sonnet-4-5", "default": true }
]
}
]
}
Add project instructions — create AGENTS.md in project root:
## Workflow Rules
- Run `npm test` after every code change.
- Never modify `package.json` without user confirmation.
Validate config:
jq . opencode.json && opencode run "test"
When to Use
- Adding or updating providers and model preferences.
- Editing permissions for tools, shell commands, or file access.
- Updating formatter or instruction configuration in
opencode.json. - Creating or refining
AGENTS.mdinstructions. - Diagnosing configuration precedence or behavior mismatches.
When Not to Use
- General coding implementation tasks.
- Plugin/tool development outside standard config fields.
- Agent personality design unrelated to config structure.
Mindset
- Prefer explicit, minimal configuration changes over broad rewrites.
- Treat permissions and secrets as security-critical defaults.
- Validate behavior immediately after each meaningful config edit.
Scope
| File | Purpose |
|---|---|
opencode.json |
Main OpenCode runtime configuration |
AGENTS.md |
Project-level behavior and workflow rules |
.env/shell env |
Provider keys and environment-backed configuration |
references/*.md |
Deep configuration guidance |
Out of scope: plugin authoring and custom tool SDK development.
Workflow
- Identify target config file(s) from request intent.
- Read current config state and precedence (project vs global).
- Apply minimal configuration edits with explicit rationale.
- Validate syntax:
jq . opencode.json >/dev/null && rg -n "API_KEY|baseEnv|permission" opencode.json .env* - Run a smoke test:
opencode run "test" - Confirm expected behavior and document key constraints. If errors surface, re-read config precedence before widening permissions.
Quick Commands
rg -n "model|provider|permission|instructions" opencode.json AGENTS.md
opencode run "test"
jq . opencode.json >/dev/null
rg -n "API_KEY|baseEnv|permission" opencode.json .env*
Configuration Examples
Minimal opencode.json — provider with baseEnv pattern
{
"providers": [
{
"id": "openai",
"baseEnv": "OPENAI_API_KEY",
"models": [
{ "id": "gpt-4o-2024-08-06", "default": true }
]
}
],
"permissions": {
"filesystem": { "read": ["./src", "./docs"], "write": ["./src"] },
"shell": { "allow": ["npm test", "jq"] }
},
"formatter": { "enabled": true }
}
Minimal AGENTS.md template
# Project Agent Instructions
## Scope
- Work only within `src/` and `docs/` unless explicitly told otherwise.
## Workflow Rules
- Run `npm test` after every code change.
- Never modify `opencode.json` directly; propose changes for human review.
## Constraints
- Do not execute destructive shell commands (rm -rf, git push --force).
- Prefer read operations before any write or delete action.
Gotchas
- Provider order matters when multiple providers can satisfy a model name.
- Agent-level permissions can be stricter than global defaults.
- Environment precedence is typically shell > dotenv loader > config defaults.
- Model identifiers must match provider format exactly.
Production Caveats
- NEVER commit raw API keys to repository config files.
- Prefer least-privilege permissions and widen only when required.
- Re-test config after permission or provider edits.
Anti-Patterns
NEVER commit API keys directly in config
- WHY: secret leakage through source control history is irreversible.
- BAD:
"apiKey": "sk-...". - GOOD:
"baseEnv": "OPENAI_API_KEY". - CONSEQUENCE: a leaked key is billed to you until it is rotated, and every clone and fork keeps a copy.
NEVER use broad filesystem or shell permissions by default
- WHY: permissive defaults increase blast radius of mistakes.
- BAD: root-level read/write and unrestricted shell.
- GOOD: scoped paths and explicit command allowlists.
- CONSEQUENCE: a mistaken or injected command can delete files or run arbitrary shell outside the project.
NEVER use ambiguous model names
- WHY: providers may resolve generic model aliases differently.
- BAD:
"model": "gpt-4". - GOOD: provider-qualified or exact model identifiers.
- CONSEQUENCE: the same config can pick different models across providers or releases, changing cost and behaviour without a visible edit.
NEVER skip verification after permission changes
- WHY: permission regressions are often silent until runtime.
- BAD: edit-and-commit without test.
- GOOD: run
opencode run "test"and validate behavior. - CONSEQUENCE: a broken permission or provider only fails mid-task, after other edits are already made.
NEVER put AGENTS.md instructions in opencode.json and vice versa
- WHY:
opencode.jsonis runtime config (providers, permissions, tools).AGENTS.mdis behavioral guidance for the agent. Mixing them causes ignored instructions or broken config parsing. - BAD: putting
instructions:blocks insideopencode.json, or adding JSON config snippets insideAGENTS.md. - GOOD: runtime settings →
opencode.json; workflow rules, constraints, conventions →AGENTS.md. - CONSEQUENCE: the agent silently ignores the misplaced content, so a rule you thought was enforced is not.
NEVER use global config for project-specific settings
- WHY: global config (
~/.config/opencode/opencode.json) bleeds into unrelated projects, causing unexpected behavior across your entire environment. - BAD: adding a project’s
npm testto the global shell allowlist, or setting a project-specific model globally. - GOOD: put project-specific config in project-root
opencode.json. Reserve global config for cross-project defaults (personal API keys viabaseEnv, editor preferences). - CONSEQUENCE: a project’s allowlist or model leaks into every unrelated repository on the machine, widening permissions everywhere.
NEVER configure provider models with only default: true and no ID
- WHY:
default: truewithout a modelidfield is silently ignored or resolves to provider defaults, which may change between releases. - BAD:
{ "default": true }with noidkey. - GOOD: always pair
default: truewith a fully-qualifiedid:{ "id": "claude-sonnet-4-5", "default": true }. - CONSEQUENCE: the default model can change between releases, so results and cost drift with no change in your config.
NEVER ignore the precedence order when diagnosing config issues
- WHY: OpenCode applies config in layers: shell environment >
.envloader > projectopencode.json> globalopencode.json. Debugging config mismatches without knowing this order leads to wasted time. - BAD: Editing project
opencode.jsonto fix an issue caused by a shell env override. - GOOD: Audit from the top of the precedence chain first (
echo $OPENAI_API_KEY), then work downward. - CONSEQUENCE: you edit the wrong layer, the override still wins, and the fix changes nothing.
Eval Scenarios
- Scenario 0: Configure Anthropic provider with env variable
- Scenario 1: Place behavioral rules in AGENTS.md vs opencode.json
- Scenario 2: Fix global vs project-level config scope issue
References
| Topic | Reference | When to Use |
|---|---|---|
| Provider setup and model mapping | references/provider-configuration.md | When adding or changing a provider or default model |
| Permission structure and patterns | references/permission-schema.md | When editing filesystem, shell or tool permissions |
| Full config field reference | references/config-schema.md | When a field’s name, type or default is in question |
| Official OpenCode documentation | OpenCode Docs | For anything the references above do not cover |
Explicit NEVER/WHY/consequence triplets with side-by-side bad/good examples. Generic warnings score low — concrete failure modes with real impact (security, correctness, performance) score high.
Runtime validation via eval scenarios proving the skill actually changes agent behaviour. Requires evals/ directory, instructions.json, ≥3 scenarios, and ≥80% instruction coverage in summary.json.
Appropriate rigidity for the skill type: strict rules for critical/security skills, balanced steps for process skills, flexible options for tool skills. Mismatched calibration (too rigid or too loose) reduces score.
Expert-only knowledge the AI couldn't derive on its own — domain-specific patterns, production gotchas, decision frameworks, and non-obvious tool behaviour. High scores mean <5% redundancy with what the model already knows.
A clear philosophy plus numbered step-by-step workflows with explicit entry/exit points. Should answer: what is the core principle, how to execute it, and when (and when not) to apply it.
Rich activation keywords and trigger scenarios in the description so the skill fires when needed. Best descriptions read like an exhaustive list of the tasks and concepts that should invoke this skill.
Copy-paste-ready code, complete runnable examples, real file paths and commands. Pseudocode and abstract descriptions score low — concrete, executable content scores high.
SKILL.md as a <100-line navigation hub pointing to focused references/ files. Content should be lazy-loaded on demand, not front-loaded. Includes actionable 'When to Use' conditions per reference.
Proper frontmatter, single-task focus, activation keywords, and cross-harness portability. Skills must work across 40+ agentic harnesses without hardcoded paths or agent-specific references.
Explicit NEVER/WHY/consequence triplets with side-by-side bad/good examples. Generic warnings score low — concrete failure modes with real impact (security, correctness, performance) score high.
Runtime validation via eval scenarios proving the skill actually changes agent behaviour. Requires evals/ directory, instructions.json, ≥3 scenarios, and ≥80% instruction coverage in summary.json.
Appropriate rigidity for the skill type: strict rules for critical/security skills, balanced steps for process skills, flexible options for tool skills. Mismatched calibration (too rigid or too loose) reduces score.
Expert-only knowledge the AI couldn't derive on its own — domain-specific patterns, production gotchas, decision frameworks, and non-obvious tool behaviour. High scores mean <5% redundancy with what the model already knows.
A clear philosophy plus numbered step-by-step workflows with explicit entry/exit points. Should answer: what is the core principle, how to execute it, and when (and when not) to apply it.
Rich activation keywords and trigger scenarios in the description so the skill fires when needed. Best descriptions read like an exhaustive list of the tasks and concepts that should invoke this skill.
Copy-paste-ready code, complete runnable examples, real file paths and commands. Pseudocode and abstract descriptions score low — concrete, executable content scores high.
SKILL.md as a <100-line navigation hub pointing to focused references/ files. Content should be lazy-loaded on demand, not front-loaded. Includes actionable 'When to Use' conditions per reference.
Proper frontmatter, single-task focus, activation keywords, and cross-harness portability. Skills must work across 40+ agentic harnesses without hardcoded paths or agent-specific references.
Expert-only knowledge the AI couldn't derive on its own — domain-specific patterns, production gotchas, decision frameworks, and non-obvious tool behaviour. High scores mean <5% redundancy with what the model already knows.
A clear philosophy plus numbered step-by-step workflows with explicit entry/exit points. Should answer: what is the core principle, how to execute it, and when (and when not) to apply it.
Explicit NEVER/WHY/consequence triplets with side-by-side bad/good examples. Generic warnings score low — concrete failure modes with real impact (security, correctness, performance) score high.
Proper frontmatter, single-task focus, activation keywords, and cross-harness portability. Skills must work across 40+ agentic harnesses without hardcoded paths or agent-specific references.
SKILL.md as a <100-line navigation hub pointing to focused references/ files. Content should be lazy-loaded on demand, not front-loaded. Includes actionable 'When to Use' conditions per reference.
Appropriate rigidity for the skill type: strict rules for critical/security skills, balanced steps for process skills, flexible options for tool skills. Mismatched calibration (too rigid or too loose) reduces score.
Rich activation keywords and trigger scenarios in the description so the skill fires when needed. Best descriptions read like an exhaustive list of the tasks and concepts that should invoke this skill.
Copy-paste-ready code, complete runnable examples, real file paths and commands. Pseudocode and abstract descriptions score low — concrete, executable content scores high.
Runtime validation via eval scenarios proving the skill actually changes agent behaviour. Requires evals/ directory, instructions.json, ≥3 scenarios, and ≥80% instruction coverage in summary.json.
Expert-only knowledge the AI couldn't derive on its own — domain-specific patterns, production gotchas, decision frameworks, and non-obvious tool behaviour. High scores mean <5% redundancy with what the model already knows.
A clear philosophy plus numbered step-by-step workflows with explicit entry/exit points. Should answer: what is the core principle, how to execute it, and when (and when not) to apply it.
Explicit NEVER/WHY/consequence triplets with side-by-side bad/good examples. Generic warnings score low — concrete failure modes with real impact (security, correctness, performance) score high.
Proper frontmatter, single-task focus, activation keywords, and cross-harness portability. Skills must work across 40+ agentic harnesses without hardcoded paths or agent-specific references.
SKILL.md as a <100-line navigation hub pointing to focused references/ files. Content should be lazy-loaded on demand, not front-loaded. Includes actionable 'When to Use' conditions per reference.
Appropriate rigidity for the skill type: strict rules for critical/security skills, balanced steps for process skills, flexible options for tool skills. Mismatched calibration (too rigid or too loose) reduces score.
Rich activation keywords and trigger scenarios in the description so the skill fires when needed. Best descriptions read like an exhaustive list of the tasks and concepts that should invoke this skill.
Copy-paste-ready code, complete runnable examples, real file paths and commands. Pseudocode and abstract descriptions score low — concrete, executable content scores high.
Runtime validation via eval scenarios proving the skill actually changes agent behaviour. Requires evals/ directory, instructions.json, ≥3 scenarios, and ≥80% instruction coverage in summary.json.
Expert-only knowledge the AI couldn't derive on its own — domain-specific patterns, production gotchas, decision frameworks, and non-obvious tool behaviour. High scores mean <5% redundancy with what the model already knows.
A clear philosophy plus numbered step-by-step workflows with explicit entry/exit points. Should answer: what is the core principle, how to execute it, and when (and when not) to apply it.
Explicit NEVER/WHY/consequence triplets with side-by-side bad/good examples. Generic warnings score low — concrete failure modes with real impact (security, correctness, performance) score high.
Proper frontmatter, single-task focus, activation keywords, and cross-harness portability. Skills must work across 40+ agentic harnesses without hardcoded paths or agent-specific references.
SKILL.md as a <100-line navigation hub pointing to focused references/ files. Content should be lazy-loaded on demand, not front-loaded. Includes actionable 'When to Use' conditions per reference.
Appropriate rigidity for the skill type: strict rules for critical/security skills, balanced steps for process skills, flexible options for tool skills. Mismatched calibration (too rigid or too loose) reduces score.
Rich activation keywords and trigger scenarios in the description so the skill fires when needed. Best descriptions read like an exhaustive list of the tasks and concepts that should invoke this skill.
Copy-paste-ready code, complete runnable examples, real file paths and commands. Pseudocode and abstract descriptions score low — concrete, executable content scores high.
Runtime validation via eval scenarios proving the skill actually changes agent behaviour. Requires evals/ directory, instructions.json, ≥3 scenarios, and ≥80% instruction coverage in summary.json.
Expert-only knowledge the AI couldn't derive on its own — domain-specific patterns, production gotchas, decision frameworks, and non-obvious tool behaviour. High scores mean <5% redundancy with what the model already knows.
A clear philosophy plus numbered step-by-step workflows with explicit entry/exit points. Should answer: what is the core principle, how to execute it, and when (and when not) to apply it.
Explicit NEVER/WHY/consequence triplets with side-by-side bad/good examples. Generic warnings score low — concrete failure modes with real impact (security, correctness, performance) score high.
Proper frontmatter, single-task focus, activation keywords, and cross-harness portability. Skills must work across 40+ agentic harnesses without hardcoded paths or agent-specific references.
SKILL.md as a <100-line navigation hub pointing to focused references/ files. Content should be lazy-loaded on demand, not front-loaded. Includes actionable 'When to Use' conditions per reference.
Appropriate rigidity for the skill type: strict rules for critical/security skills, balanced steps for process skills, flexible options for tool skills. Mismatched calibration (too rigid or too loose) reduces score.
Rich activation keywords and trigger scenarios in the description so the skill fires when needed. Best descriptions read like an exhaustive list of the tasks and concepts that should invoke this skill.
Copy-paste-ready code, complete runnable examples, real file paths and commands. Pseudocode and abstract descriptions score low — concrete, executable content scores high.
No eval scenarios available.
OpenCode Configuration Schema Reference
This document defines the schema and valid values for opencode.json. Run opencode models to list models currently available to your installation, or browse the full registry at https://models.dev/ (API: curl https://models.dev/api.json). The Model ID field in that registry is the identifier format used in OpenCode config.
top_level_options
{
"$schema": "https://opencode.ai/config.json",
// Model Configuration
"model": "provider/model-id",
"small_model": "provider/model-id",
"provider": {},
"disabled_providers": ["openai", "gemini"],
// UI & Updates
"theme": "opencode",
"autoupdate": true,
"tui": { "scroll_speed": 3 },
"keybinds": {},
// Sharing
"share": "manual", // "manual" | "auto" | "disabled"
// Tools & Permissions
"tools": {},
"permission": {},
// Agents & Commands
"agent": {},
"command": {},
// Instructions & MCP
"instructions": [],
"mcp": {},
// Formatters
"formatter": {},
}
model_configuration
model / small_model
{
"model": "anthropic/claude-3-5-sonnet-20241022",
"small_model": "anthropic/claude-3-5-haiku-20241022",
}
Format: provider/model-id. Run opencode models to list available models, or look up the Model ID field at https://models.dev/ (machine-readable: curl https://models.dev/api.json).
provider
Configure custom providers or override settings:
{
"provider": {
"anthropic": {
"models": {},
"options": {
"apiKey": "{env:ANTHROPIC_API_KEY}",
},
},
},
}
disabled_providers
Prevent providers from loading even if credentials exist:
{
"disabled_providers": ["openai", "gemini"],
}
tools_configuration
Enable/disable tools globally:
{
"tools": {
"bash": true,
"edit": true,
"write": true,
"read": true,
"glob": true,
"grep": true,
"list": true,
"patch": true,
"webfetch": true,
"todowrite": true,
"todoread": true,
"skill": true,
},
}
Wildcards supported for MCP tools:
{
"tools": {
"mymcp_*": false,
},
}
permissions
Simple Permissions
{
"permission": {
"edit": "allow", // "allow" | "ask" | "deny"
"webfetch": "ask",
},
}
Pattern-Based Bash Permissions
{
"permission": {
"bash": {
"*": "allow", // Default for all
"rm *": "ask", // Ask before delete
"rm -rf *": "deny", // Block recursive delete
"sudo *": "deny", // Block sudo
"git push": "ask", // Ask before push
"npm run *": "allow", // Allow npm scripts
},
},
}
Skill Permissions
{
"permission": {
"skill": {
"*": "allow",
"dangerous-*": "deny",
"experimental-*": "ask",
},
},
}
agent_configuration
Define agents in config:
{
"agent": {
"my-agent": {
"description": "What triggers this agent",
"mode": "subagent",
"model": "anthropic/claude-3-5-sonnet-20241022",
"prompt": "System prompt or {file:./prompt.txt}",
"temperature": 0.3,
"maxSteps": 25,
"disable": false,
"tools": {
"bash": false,
},
"permission": {
"edit": "ask",
},
},
},
}
commands
Custom slash commands:
{
"command": {
"test": {
"template": "Run tests and show failures. $ARGUMENTS",
"description": "Run test suite",
"agent": "build",
"model": "anthropic/claude-3-5-sonnet-20241022",
},
},
}
Use $ARGUMENTS for user input after command.
instructions
Include additional instruction files:
{
"instructions": [
"CONTRIBUTING.md",
"docs/guidelines.md",
".cursor/rules/*.md",
"packages/*/AGENTS.md",
],
}
Supports glob patterns.
formatters
Configure code formatters:
{
"formatter": {
"prettier": {
"disabled": true,
},
"custom": {
"command": ["npx", "prettier", "--write", "$FILE"],
"environment": { "NODE_ENV": "development" },
"extensions": [".js", ".ts", ".jsx", ".tsx"],
},
},
}
mcp_servers
Configure Model Context Protocol servers:
{
"mcp": {
"my-server": {
"type": "local",
"command": ["npx", "-y", "@org/package"],
"environment": { "KEY": "VALUE" },
},
"remote-name": {
"type": "remote",
"url": "https://api.example.com/mcp",
"headers": { "Authorization": "Bearer ..." },
},
},
}
model_variants
Model Variants (ctrl+t)
Variants allow you to define multiple parameter sets for a single model, cycleable via ctrl+t.
{
"provider": {
"openai": {
"models": {
"gpt-4o": {
"variants": {
"high": {
"reasoningEffort": "high",
"reasoningSummary": "detailed",
},
"low": {
"reasoningEffort": "low",
"textVerbosity": "low",
},
},
},
},
},
},
}
Functional Variant Properties
| Property | Provider | Values |
| —————— | —————– | —————————————–– | —–– |
| reasoningEffort | OpenAI/Azure | minimal, low, medium, high, xhigh |
| reasoningSummary | OpenAI/Azure | auto, detailed |
| textVerbosity | OpenAI Compatible | low, medium, high |
| thinking | Anthropic | { type: "enabled", budgetTokens: number } |
| thinkingLevel | Google | "low" | "high" |
| include | OpenAI/Azure | ["reasoning.encrypted_content"] |
variable_substitution
Environment Variables
{
"model": "{env:OPENCODE_MODEL}",
"provider": {
"openai": {
"options": {
"apiKey": "{env:OPENAI_API_KEY}",
},
},
},
}
File Contents
{
"agent": {
"custom": {
"prompt": "{file:./prompts/custom.txt}",
},
},
"provider": {
"anthropic": {
"options": {
"apiKey": "{file:~/.secrets/anthropic-key}",
},
},
},
}
misc_options
TUI Options
{
"tui": {
"scroll_speed": 3,
},
}
Sharing Options
{
"share": "manual", // "manual" | "auto" | "disabled"
}
manual- Share via/sharecommand (default)auto- Auto-share new conversationsdisabled- No sharing
Permission Schema Patterns
Use this reference for safe, maintainable OpenCode permission configuration.
Permission Strategy
- Start from restrictive defaults.
- Allow only required commands and file scopes.
- Separate local development convenience from CI/production safeguards.
Example Pattern
{
"permission": {
"edit": "ask",
"webfetch": "allow",
"bash": {
"npm *": "allow",
"git *": "allow",
"rm *": "ask",
"*": "ask"
}
}
}
Common Patterns
- Use command-pattern granularity for
bashrules. - Keep file access scoped to repository paths when configurable.
- Re-test after each permission block change.
Provider Configuration
Use this reference for provider setup patterns and model routing.
Provider Setup Principles
- Keep provider entries explicit and minimal.
- Use environment-backed secrets (
baseEnv) instead of inline keys. - Prefer deterministic model identifiers.
Example Pattern
{
"providers": [
{
"name": "openai",
"baseEnv": "OPENAI_API_KEY"
},
{
"name": "anthropic",
"baseEnv": "ANTHROPIC_API_KEY"
}
],
"model": "openai/gpt-4.1"
}
Notes
- If provider order affects resolution, document ordering rationale.
- Keep fallback models explicit for reliability in degraded provider scenarios.