Agent
A specialized AI assistant configured for specific tasks and workflows.
What it is
An agent is an autonomous AI assistant that can reason, plan, and use tools to accomplish goals. It's not a chatbot — it's a configured entity with permissions, tools, a system prompt, and a model.
Agent = Configuration + Identity
What it is in real OpenCode terms
In OpenCode, an agent is a named configuration. Every interaction happens through an agent. Two categories:
Built-in Primary Agents
Built-in Subagents
Switch primary agents with Tab. Invoke subagents with @name.
Why it exists
Without agents, you would have one generic AI assistant doing everything — coding, debugging, researching, planning — with the same permissions and the same prompt. This leads to:
- Accidental file edits when you only wanted analysis
- No specialization — the AI doesn't know it should act differently for planning vs. building
- No way to delegate subtasks to parallel workers
Agents solve this by letting you configure who does the work, what they can do, and how they should approach it. A Plan agent won't accidentally overwrite your code. A Scout agent focuses only on external research. Each agent has a clear purpose.
Anatomy / main elements
Every agent configuration includes some or all of these fields:
| Field | Purpose |
|---|---|
description |
Short text explaining what the agent does. Shown in agent selection. |
model |
The LLM model the agent uses (e.g., anthropic/claude-sonnet-4). Falls back to the global config model if omitted. |
prompt |
System prompt or instructions that define the agent's behavior and personality. |
permissions |
Controls which actions the agent can take: read, edit, bash, task, etc. |
mode |
Set to primary, subagent, or all. Determines how the agent is invoked. |
temperature |
Controls randomness in responses. Lower = more deterministic. |
steps |
Limits how many sequential steps the agent can take before pausing. |
Where it lives
Agent configurations can live in two places:
.opencode/agents/my-agent.md
User-level (global):
~/.config/opencode/agents/my-agent.md
They can also be defined inline in your opencode.json config file:
{
"agent": {
"my-agent": {
"description": "A custom agent for refactoring",
"mode": "primary",
"model": "anthropic/claude-sonnet-4",
"prompt": "You are a refactoring specialist.",
"permissions": {
"edit": true,
"bash": false
}
}
}
}
Or as a Markdown file with YAML frontmatter:
---
name: refactor
description: A refactoring specialist
mode: primary
model: anthropic/claude-sonnet-4
---
You are a refactoring specialist. Your job is to improve code
quality without changing behavior. Focus on:
- Removing duplication
- Improving naming
- Simplifying control flow
- Applying SOLID principles
How to create one
- Decide if this should be a primary agent (you interact with it directly) or a subagent (other agents invoke it).
- Create a Markdown file in
.opencode/agents/named after your agent (e.g.,reviewer.md). - Add YAML frontmatter with at minimum
name,description, andmode. - Write the system prompt in the body of the Markdown file.
- Restart OpenCode or reload config. The agent appears in the agent selector (for primary agents) or becomes available to
@mention (for subagents).
Minimal example
Create a read-only reviewer agent that can only read files and suggest changes:
---
name: reviewer
description: Read-only code reviewer that suggests improvements
mode: primary
permissions:
read: true
edit: false
bash: false
---
You are a code reviewer. You can read the codebase but never
modify it. For each file you examine, output:
1. Issues found (bugs, anti-patterns, security concerns)
2. Suggested improvements with specific code snippets
3. A severity rating: critical / warning / nit
Be concise. Prioritize real problems over style preferences.
Save this as .opencode/agents/reviewer.md. After reloading, press Tab to switch to the reviewer agent. It will be able to read your code but will refuse any edit or shell commands.
Related concepts
Common confusion
@) delegate work to. You cannot switch to a subagent with Tab — subagents run in their own child sessions.