Create Agent
Create custom OpenCode agents using markdown files with YAML frontmatter - the preferred method for readability and version control.
Markdown Format (Recommended)
Create ~/.config/opencode/agents/my-agent.md:
markdown--- description: What this agent does mode: subagent | primary temperature: 0.3 permission: edit: deny --- System prompt here...
File locations:
- Global:
~/.config/opencode/agents/*.md - Project:
.opencode/agents/*.md
Key Configuration
| Option | Description | Example |
|---|---|---|
description | When to use this agent (required) | "Code reviewer" |
mode | primary (Tab-switchable) or subagent (@mention) | subagent |
permission | Tool access control: allow, ask, or deny | edit: deny |
temperature | 0.0-1.0 (lower=focused) | 0.3 |
Common Patterns
Read-Only Research Agent
markdown--- description: Research assistant with web access mode: subagent permission: read: allow webfetch: allow websearch: allow edit: deny bash: deny ---
Restricted Primary Agent
markdown--- description: Planning mode without file changes mode: primary permission: read: allow edit: deny bash: deny ---
Code Review Subagent
markdown--- description: Reviews code for quality and best practices mode: subagent permission: read: allow grep: allow glob: allow edit: deny bash: '*': ask 'git *': allow ---
Prompt Design
Effective prompts include:
- Clear role: "You are a..."
- Responsibilities: "Your tasks are..."
- Constraints: "You MUST NOT..."
- Output format: "Structure responses as..."
- Examples: 1-2 sample interactions
- Tone guidelines: "Be concise and professional."
Tool Reference
Common permissions to configure:
read/grep/glob- Code explorationedit/bash- File operations (deny for safety)webfetch/websearch- Internet accesstask- Invoking other subagentsquestion- Interactive user prompts
Use allow, ask, or deny values. Use object syntax for granular control:
yamlpermission: bash: '*': ask 'git status': allow 'rm *': deny
Permissions
Control approvals in YAML:
yamlpermission: edit: ask # Prompt before edit bash: '*': ask # Ask all commands 'git status': allow # Except git status
Permission Key for File Writes
Important: The
editkey controls ALL file modification tools:edit,write,patch, andmultiedit. There is no separatewrite:key — it is silently ignored if present. Always useedit:to restrict file writes.
Wildcard Path Patterns
Gotcha:
**is NOT a true globstar — it requires a literal/separator to work. Use*.mdfor files directly inside a directory; use**/*.mdonly when files are guaranteed to be in subdirectories.
yamlpermission: edit: "*": deny "~/.config/opencode/memory/*.md": allow # correct — files directly in memory/ # "~/.config/opencode/memory/**/*.md": allow # WRONG — never matches flat files
Rule Evaluation Order
Last matching rule wins. Always put the "*" catch-all first, specific overrides after:
yamlpermission: edit: "*": deny # catch-all first "~/safe/subdir/*.md": allow # specific override last — this wins for matching paths bash: "*": ask # catch-all first "git status": allow # specific override last
external_directory and edit: Are Independent
Gotcha:
external_directoryonly gates access to out-of-project paths. Theedit:permission rules still run independently on top. You must configure both for agents that write to paths outside the project.
yamlpermission: external_directory: "~/.config/opencode": allow # gates out-of-project access edit: "*": deny "~/.config/opencode/memory/*.md": allow # still required — edit rules apply independently
Best Practices
- Start restrictive: Read-only by default
- Use
edit: denyto block all file writes (notwrite: deny— that key doesn't exist) - Use
*.mdnot**/*.mdfor files directly inside a directory - Configure both
external_directoryandedit:when writing outside the project root - Specific descriptions: Help model know when to invoke
- Test incrementally: Verify tool access works
- Iterate: Refine prompts based on usage
Full Example
markdown--- description: Security auditor that identifies vulnerabilities mode: subagent temperature: 0.2 permission: read: allow grep: allow glob: allow edit: deny bash: deny --- You are a security auditor. Focus on: - Input validation vulnerabilities - Authentication flaws - Data exposure risks - Dependency vulnerabilities Provide specific recommendations with code examples. Never modify files - only report findings.


