AgentSkillsCN

opencode-config

编辑opencode.json、AGENTS.md以及配置文件。无论是供应商设置、权限调整、模型配置、格式化规则,还是环境变量的管理,此功能都能助你事半功倍。 示例: - 用户输入:“添加Anthropic作为供应商” → 编辑opencode.json中的供应商条目,添加API密钥的基础环境变量,通过opencode run test进行验证 - 用户输入:“限制该代理的权限” → 在代理配置中添加权限块,为工具与fileAccess设置deny/allow规则 - 用户输入:“将GPT-5设为默认模型” → 编辑全局或代理级别的模型偏好,确保模型名称的格式符合规范 - 用户输入:“禁用gofmt格式化器” → 编辑格式化器部分,将languages.gofmt.enabled = false

SKILL.md
--- frontmatter
name: opencode-config
description: |-
  Edit opencode.json, AGENTS.md, and config files. Use proactively for provider setup, permission changes, model config, formatter rules, or environment variables.
  
  Examples:
  - user: "Add Anthropic as a provider" → edit opencode.json providers, add API key baseEnv var, verify with opencode run test
  - user: "Restrict this agent's permissions" → add permission block to agent config, set deny/allow for tools/fileAccess
  - user: "Set GPT-5 as default model" → edit global or agent-level model preference, verify model name format
  - user: "Disable gofmt formatter" → edit formatters section, set languages.gofmt.enabled = false
<overview> Help users configure OpenCode through guided setup of config files and rules. </overview> <guidelines>

Question Tool Usage

Batching Rule: Use only for 2+ related questions; single questions use plain text.

Syntax Constraints: header max 12 chars, labels 1-5 words, mark defaults with (Recommended).

Purpose: Clarify config scope (models/permissions/rules), validate approach, and handle multiple valid options.

</guidelines> <reference>

File Locations

TypeGlobalProject
Config~/.config/opencode/opencode.json./opencode.json
Rules~/.config/opencode/AGENTS.md./AGENTS.md

Precedence: Project > Global. Configs are merged, not replaced.

</reference> <workflow> <phase name="clarify">

Clarify Intent

Ask the user what they want to configure:

  1. "What would you like to set up?"
    • Config file (models, tools, permissions, theme)
    • Rules (project instructions via AGENTS.md)

When to ask: Vague request ("configure opencode"), permission/security changes, or multiple valid options exist.

Then guide them through the relevant section below.

</phase> </workflow> <rules>

Config File (opencode.json)

Basic Setup

jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "model": "anthropic/claude-sonnet-4-20250514",
  "theme": "opencode",
  "autoupdate": true
}

Key Options

OptionPurposeExample
modelDefault model"anthropic/claude-sonnet-4-20250514"
small_modelLightweight tasks"anthropic/claude-3-5-haiku-20241022"
themeUI theme"opencode", "catppuccin", "dracula"
autoupdateAuto-update OpenCodetrue / false
shareSession sharing"manual" / "auto" / "disabled"

Permissions

Control what requires approval using the permission field.

jsonc
{
  "permission": {
    "edit": "allow",           // "allow" | "ask" | "deny"
    "bash": {
      "npm *": "allow",        // pattern matching
      "git *": "allow",
      "rm *": "ask",
      "*": "ask"               // default for this tool
    },
    "webfetch": "allow",
    "skill": {
      "*": "allow",
      "dangerous-*": "deny"
    }
  }
}

Legacy Configuration

Agents MAY occasionally work on legacy projects using outdated configuration fields (e.g., tools, maxSteps). You MUST correct these to the modern permission and steps fields when encountered.

Custom Instructions

Include additional instruction files:

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

Full schema reference: See references/config-schema.md

</rules> <rules>

Rules (AGENTS.md)

Project instructions for all agents. Similar to CLAUDE.md or Cursor rules.

Create with /init

Run /init in OpenCode to auto-generate based on project analysis.

Manual Creation

markdown
# Project Name

This is a [framework] project using [language].

## Project Structure
- `src/` - Source code
- `tests/` - Test files

## Code Standards
- Use TypeScript strict mode
- Prefer functional patterns
- Write tests for all features

## Commands
- `npm run build` - Build project
- `npm test` - Run tests

Tips

  • You SHOULD be specific about your project's patterns
  • You SHOULD include common commands
  • You SHOULD document any non-obvious conventions
  • You SHOULD keep it concise (agents have limited context)
</rules> <guidelines>

Comment Out, Don't Delete

OpenCode supports JSONC (JSON with comments). You SHOULD comment out unused configs instead of deleting:

jsonc
{
  "plugin": [
    "opencode-openai-codex-auth@latest",
    //"@tarquinen/opencode-dcp@latest",     // disabled for now
    //"@howaboua/pickle-thinker@0.4.0",     // only for GLM-4.6
    "@ramtinj95/opencode-tokenscope@latest"
  ]
}

Why: You might want to re-enable later. Keeps a record of what you've tried.

Validate After Major Changes

After editing opencode.json, you MUST run this validation (not just suggest it):

bash
opencode run "test"

Execute it yourself using the Bash tool before telling the user the change is complete.

If broken, you'll see a clear error with line number:

code
Error: Config file at ~/.config/opencode/opencode.json is not valid JSON(C):
--- Errors ---
CommaExpected at line 464, column 5
   Line 464:     "explore": {
              ^
--- End ---

Common JSONC mistakes:

  • Missing comma after object (especially after adding new sections)
  • Trailing comma before }
  • Unclosed brackets
</guidelines> <examples>

Minimal Safe Config

jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "model": "anthropic/claude-sonnet-4-20250514",
  "permission": {
    "edit": "ask",
    "bash": "ask"
  }
}

Power User Config

jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "model": "anthropic/claude-sonnet-4-20250514",
  "autoupdate": true,
  "permission": {
    "edit": "allow",
    "bash": {
      "*": "allow",
      "rm -rf *": "deny",
      "sudo *": "ask"
    }
  },
  "instructions": ["CONTRIBUTING.md"]
}

Team Project Config

jsonc
{
  "$schema": "https://opencode.ai/config.json",
  "model": "anthropic/claude-sonnet-4-20250514",
  "share": "auto",
  "instructions": [
    "docs/development.md",
    "docs/api-guidelines.md"
  ]
}
</examples> <reference>

Troubleshooting

IssueSolution
Config not loadingCheck JSON syntax, ensure valid path
Skill not foundVerify SKILL.md (uppercase), check frontmatter
Permission denied unexpectedlyCheck global vs project config precedence

References

  • references/config-schema.md - Full config options
</reference>