AgentSkillsCN

customizing-opencode

通过 opencode.json 配置 OpenCode,包括代理、命令、MCP 服务器、自定义工具、插件、主题、快捷键以及权限设置。适用于在配置或修改 OpenCode 配置时使用。

SKILL.md
--- frontmatter
name: customizing-opencode
description: Configure OpenCode via opencode.json, agents, commands, MCP servers, custom tools, plugins, themes, keybinds, and permissions. Use when setting up or modifying OpenCode configuration.

Customizing OpenCode

Configure OpenCode behavior through config files, agents, commands, and extensions.

Config File Locations

LocationPathPurpose
Global~/.config/opencode/opencode.jsonUser-wide preferences
Project./opencode.jsonProject-specific settings
Custom$OPENCODE_CONFIG env varOverride path

Precedence (later overrides earlier): Remote .well-known/opencode < Global < Custom < Project

Quick Reference

TaskWhereReference
Set theme, model, autoupdateopencode.jsonconfig-schema.md
Define specialized agents.opencode/agents/*.md or configagents.md
Create slash commands.opencode/commands/*.md or configcommands.md
Add external tools via MCPopencode.json mcp sectionmcp-servers.md
Write custom tool functions.opencode/tools/*.tscustom-tools.md
Extend with plugins/hooks.opencode/plugins/*.ts or npmplugins.md
Control tool accessopencode.json permission sectionpermissions.md
Customize keyboard shortcutsopencode.json keybinds sectionkeybinds.md
Change colors/appearanceopencode.json theme or custom JSONthemes.md

Directory Structure

code
~/.config/opencode/           # Global config
├── opencode.json
├── AGENTS.md                 # Global rules
├── agents/                   # Global agents
├── commands/                 # Global commands
├── plugins/                  # Global plugins
├── skills/                   # Global skills
├── tools/                    # Global custom tools
└── themes/                   # Global custom themes

.opencode/                    # Project config (same structure)
├── agents/
├── commands/
├── plugins/
├── skills/
├── tools/
└── themes/

When to Use What

NeedSolution
Change model/theme for all projectsGlobal opencode.json
Project-specific agent behaviorProject .opencode/agents/
Reusable prompt templatesCommands (.opencode/commands/)
External service integrationMCP servers
Custom logic the LLM can callCustom tools
React to OpenCode eventsPlugins
Restrict dangerous operationsPermissions

Variable Substitution

Use in any config value:

jsonc
{
  "model": "{env:OPENCODE_MODEL}",           // Environment variable
  "instructions": ["{file:./rules.md}"]      // File contents
}

Rules (AGENTS.md)

Project instructions loaded into LLM context:

FileScope
./AGENTS.mdProject (traverses up to git root)
~/.config/opencode/AGENTS.mdGlobal
instructions array in configAdditional files/globs
jsonc
{
  "instructions": ["CONTRIBUTING.md", "docs/*.md"]
}

Docs

Full documentation: https://opencode.ai/docs/config/