AgentSkillsCN

opencode-agents

为OpenCode智能代理定义并配置恰当的权限、工具与行为模式。无论是代理的创建、工具访问控制、权限分配,还是模式选择,此功能都可助你事半功倍。 当用户提出“创建代理”、“代理权限”、“工具访问”、“子代理”、“限制代理权限”,或询问代理配置时,应主动运用此功能。 示例: - 用户输入:“创建安全审查员代理” → 设计具有只读权限与合适技能的代理 - 用户输入:“如何限制bash的访问权限?” → 通过allow/ask/deny等权限.bash模式,详细讲解权限配置 - 用户输入:“让代理使用问答工具” → 配置tools.question:“启用”或确保工具未被限制 - 用户输入:“主代理与子代理有何不同?” → 解释多种模式选项

SKILL.md
--- frontmatter
name: opencode-agents
description: |-
  Define and configure OpenCode agents with proper permissions, tools, and behaviors. Use for agent creation, tool access control, permission patterns, and mode selection.
  
  Use proactively when user says "create an agent", "agent permissions", "tool access", "subagent", "restrict agent", or asks about agent configuration.
  
  Examples:
  - user: "Create a security reviewer agent" → design agent with read-only permissions, appropriate skills
  - user: "How do I restrict bash access?" → explain permission.bash patterns with allow/ask/deny
  - user: "Make an agent use the question tool" → configure tools.question: "enabled" or ensure no tools restrictions
  - user: "What's the difference between primary and subagent?" → explain mode options
<overview>

Define specialized agents with precise tool access and permissions.

</overview> <rules>

Agent Fundamentals

Location

ScopePath
Project.opencode/agent/<name>.md
Global~/.config/opencode/agent/<name>.md

Agents MAY also be defined in opencode.json:

jsonc
{
  "agent": {
    "my-agent": {
      "description": "Brief description",
      "mode": "subagent",
      "model": "anthropic/claude-sonnet-4-20250514"
    }
  }
}

Frontmatter Schema

FieldTypeDefaultDescription
descriptionstringREQUIREDTrigger description (see below)
modestring"all"primary, subagent, or all
modelstringinheritedModel override (e.g., anthropic/claude-opus-4-5)
temperaturenumber1.00.0-2.0, lower = deterministic
maxStepsnumber100Maximum tool calls per turn
disablebooleanfalseDisable without deleting
toolsobjectall enabledTool-specific enable/disable
permissionobjectall allowedPermission restrictions
</rules> <guidelines>

Agent Modes

ModeVisible in MenuTask Tool TargetUse Case
primaryYesNoUser-facing, main agents
subagentNoYesOrchestrated by other agents
allYesYesVersatile, both contexts

Description Guidelines

ModeDescription Style
primary3 words max (shown in TUI menu)
subagentMUST include trigger examples for task tool routing
allBoth: short label + trigger examples

Subagent description example:

yaml
description: |-
  Security vulnerability scanner. Use for code audits, dependency checks, and security reviews.
  
  Examples:
  - user: "Review this code for security issues" → scan for vulnerabilities
  - user: "Check for hardcoded secrets" → search for credentials
</guidelines> <rules>

Permission System

CRITICAL: By default, agents have ALL tools and permissions. Only add permission blocks to RESTRICT access.

Permission Structure

yaml
permission:
  edit: "deny"           # deny all file edits
  bash: 
    "*": "ask"           # ask before any bash
    "npm test": "allow"  # but allow npm test
    "rm -rf *": "deny"   # never allow rm -rf
  webfetch: "allow"      # allow web fetching
  skill:
    "*": "deny"          # deny all skills by default
    "security-*": "allow" # allow security-prefixed skills

Permission Levels

LevelBehavior
allowExecute without confirmation
askPrompt user before executing
denyBlock entirely

Bash Pattern Matching

Patterns are matched in order of specificity:

  1. Exact match: "npm test": "allow"
  2. Prefix match: "npm *": "ask"
  3. Wildcard: "*": "deny"
yaml
permission:
  bash:
    "*": "deny"              # Default deny
    "git *": "allow"         # Allow git commands
    "npm *": "allow"         # Allow npm commands
    "rm *": "ask"            # Ask for rm
    "rm -rf *": "deny"       # MUST NOT allow rm -rf
</rules> <guidelines>

Tools Configuration

Enable or disable specific tools:

yaml
tools:
  question: "enabled"    # Force enable question tool
  webfetch: "disabled"   # Disable web fetching
  task: "disabled"       # Prevent delegation

Key Tools

ToolPurpose
questionInteractive Q&A with user (clarification)
delegateAsync background task delegation
taskSync subagent delegation
todowriteTask list management
todoreadRead current task list
skillLoad specialized skills
</guidelines> <examples>

Agent Archetypes

Analyzer (Read-Only)

yaml
---
description: Code analysis expert
mode: subagent
temperature: 0.1
permission:
  edit: "deny"
  bash:
    "*": "deny"
    "git log *": "allow"
    "git diff *": "allow"
---

Builder (Full Access)

yaml
---
description: Implementation specialist
mode: subagent
model: anthropic/claude-sonnet-4-20250514
temperature: 0.4
---
# No permission block = full access

Researcher (Web + Read)

yaml
---
description: Documentation researcher
mode: subagent
temperature: 0.2
permission:
  edit: "deny"
  bash:
    "*": "deny"
---

Specialist (Skill-Based)

yaml
---
description: |-
  Security vulnerability scanner. Use for audits and reviews.
mode: subagent
temperature: 0.2
permission:
  edit: "deny"
  bash:
    "*": "deny"
  skill:
    "*": "deny"
    "security-*": "allow"
---

System Prompt Structure

The markdown body becomes the agent's system prompt:

markdown
---
description: My agent
mode: primary
---

# Role

You are a [specific role] specializing in [domain].

## Objective

[Clear mission statement]

## Instructions

- MUST [required behavior]
- SHOULD [recommended behavior]
- MAY [optional behavior]
- MUST NOT [prohibited behavior]

## Workflow

1. [First step]
2. [Second step]
3. [Third step]

## Output Format

[Expected output structure]
</examples> <constraints>

Validation

After creating an agent:

bash
opencode run "test"

Then test by routing to it:

  • If primary: Select from agent menu
  • If subagent: Use task tool to invoke
</constraints>