| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633 |
- ---
- title: Agents
- description: Configure and use specialized agents.
- ---
- Agents are specialized AI assistants that can be configured for specific tasks and workflows. They allow you to create focused tools with custom prompts, models, and tool access.
- :::tip
- Use the plan agent to analyze code and review suggestions without making any code changes.
- :::
- You can switch between agents during a session or invoke them with the `@` mention.
- ---
- ## Types
- There are two types of agents in opencode; primary agents and subagents.
- ---
- ### Primary agents
- Primary agents are the main assistants you interact with directly. You can cycle through them using the **Tab** key, or your configured `switch_agent` keybind. These agents handle your main conversation and can access all configured tools.
- :::tip
- You can use the **Tab** key to switch between primary agents during a session.
- :::
- opencode comes with two built-in primary agents, **Build** and **Plan**. We'll
- look at these below.
- ---
- ### Subagents
- Subagents are specialized assistants that primary agents can invoke for specific tasks. You can also manually invoke them by **@ mentioning** them in your messages.
- opencode comes with one built-in subagent, **General**. We'll look at this below.
- ---
- ## Built-in
- opencode comes with two built-in primary agents and one built-in subagent.
- ---
- ### Build
- _Mode_: `primary`
- Build is the **default** primary agent with all tools enabled. This is the standard agent for development work where you need full access to file operations and system commands.
- ---
- ### Plan
- _Mode_: `primary`
- A restricted agent designed for planning and analysis. We use a permission system to give you more control and prevent unintended changes.
- By default, all of the following are set to `ask`:
- - `file edits`: All writes, patches, and edits
- - `bash`: All bash commands
- This agent is useful when you want the LLM to analyze code, suggest changes, or create plans without making any actual modifications to your codebase.
- ---
- ### General
- _Mode_: `subagent`
- A general-purpose agent for researching complex questions, searching for code, and executing multi-step tasks. Use when searching for keywords or files and you're not confident you'll find the right match in the first few tries.
- ---
- ## Usage
- 1. For primary agents, use the **Tab** key to cycle through them during a session. You can also use your configured `switch_agent` keybind.
- 2. Subagents can be invoked:
- - **Automatically** by primary agents for specialized tasks based on their descriptions.
- - Manually by **@ mentioning** a subagent in your message. For example.
- ```txt frame="none"
- @general help me search for this function
- ```
- 3. **Navigation between sessions**: When subagents create their own child sessions, you can navigate between the parent session and all child sessions using:
- - **Ctrl+Right** (or your configured `session_child_cycle` keybind) to cycle forward through parent → child1 → child2 → ... → parent
- - **Ctrl+Left** (or your configured `session_child_cycle_reverse` keybind) to cycle backward through parent ← child1 ← child2 ← ... ← parent
- This allows you to seamlessly switch between the main conversation and specialized subagent work.
- ---
- ## Configure
- You can customize the built-in agents or create your own through configuration. Agents can be configured in two ways:
- ---
- ### JSON
- Configure agents in your `opencode.json` config file:
- ```json title="opencode.json"
- {
- "$schema": "https://opencode.ai/config.json",
- "agent": {
- "build": {
- "mode": "primary",
- "model": "anthropic/claude-sonnet-4-20250514",
- "prompt": "{file:./prompts/build.txt}",
- "tools": {
- "write": true,
- "edit": true,
- "bash": true
- }
- },
- "plan": {
- "mode": "primary",
- "model": "anthropic/claude-haiku-4-20250514",
- "tools": {
- "write": false,
- "edit": false,
- "bash": false
- }
- },
- "code-reviewer": {
- "description": "Reviews code for best practices and potential issues",
- "mode": "subagent",
- "model": "anthropic/claude-sonnet-4-20250514",
- "prompt": "You are a code reviewer. Focus on security, performance, and maintainability.",
- "tools": {
- "write": false,
- "edit": false
- }
- }
- }
- }
- ```
- ---
- ### Markdown
- You can also define agents using markdown files. Place them in:
- - Global: `~/.config/opencode/agent/`
- - Per-project: `.opencode/agent/`
- ```markdown title="~/.config/opencode/agent/review.md"
- ---
- description: Reviews code for quality and best practices
- mode: subagent
- model: anthropic/claude-sonnet-4-20250514
- temperature: 0.1
- tools:
- write: false
- edit: false
- bash: false
- ---
- You are in code review mode. Focus on:
- - Code quality and best practices
- - Potential bugs and edge cases
- - Performance implications
- - Security considerations
- Provide constructive feedback without making direct changes.
- ```
- The markdown file name becomes the agent name. For example, `review.md` creates a `review` agent.
- ---
- ## Options
- Let's look at these configuration options in detail.
- ---
- ### Description
- Use the `description` option to provide a brief description of what the agent does and when to use it.
- ```json title="opencode.json"
- {
- "agent": {
- "review": {
- "description": "Reviews code for best practices and potential issues"
- }
- }
- }
- ```
- This is a **required** config option.
- ---
- ### Temperature
- Control the randomness and creativity of the LLM's responses with the `temperature` config.
- Lower values make responses more focused and deterministic, while higher values increase creativity and variability.
- ```json title="opencode.json"
- {
- "agent": {
- "plan": {
- "temperature": 0.1
- },
- "creative": {
- "temperature": 0.8
- }
- }
- }
- ```
- Temperature values typically range from 0.0 to 1.0:
- - **0.0-0.2**: Very focused and deterministic responses, ideal for code analysis and planning
- - **0.3-0.5**: Balanced responses with some creativity, good for general development tasks
- - **0.6-1.0**: More creative and varied responses, useful for brainstorming and exploration
- ```json title="opencode.json"
- {
- "agent": {
- "analyze": {
- "temperature": 0.1,
- "prompt": "{file:./prompts/analysis.txt}"
- },
- "build": {
- "temperature": 0.3
- },
- "brainstorm": {
- "temperature": 0.7,
- "prompt": "{file:./prompts/creative.txt}"
- }
- }
- }
- ```
- If no temperature is specified, opencode uses model-specific defaults; typically 0 for most models, 0.55 for Qwen models.
- ---
- ### Disable
- Set to `true` to disable the agent.
- ```json title="opencode.json"
- {
- "agent": {
- "review": {
- "disable": true
- }
- }
- }
- ```
- ---
- ### Prompt
- Specify a custom system prompt file for this agent with the `prompt` config. The prompt file should contain instructions specific to the agent's purpose.
- ```json title="opencode.json"
- {
- "agent": {
- "review": {
- "prompt": "{file:./prompts/code-review.txt}"
- }
- }
- }
- ```
- This path is relative to where the config file is located. So this works for both the global opencode config and the project specific config.
- ---
- ### Model
- Use the `model` config to override the default model for this agent. Useful for using different models optimized for different tasks. For example, a faster model for planning, a more capable model for implementation.
- ```json title="opencode.json"
- {
- "agent": {
- "plan": {
- "model": "anthropic/claude-haiku-4-20250514"
- }
- }
- }
- ```
- ---
- ### Tools
- Control which tools are available in this agent with the `tools` config. You can enable or disable specific tools by setting them to `true` or `false`.
- ```json title="opencode.json"
- {
- "agent": {
- "readonly": {
- "tools": {
- "write": false,
- "edit": false,
- "bash": false,
- "read": true,
- "grep": true,
- "glob": true
- }
- }
- }
- }
- ```
- You can also use wildcards to control multiple tools at once. For example, to disable all tools from an MCP server:
- ```json title="opencode.json"
- {
- "agent": {
- "readonly": {
- "tools": {
- "mymcp_*": false,
- "write": false,
- "edit": false
- }
- }
- }
- }
- ```
- If no tools are specified, all tools are enabled by default.
- ---
- #### Available tools
- Here are all the tools can be controlled through the agent config.
- | Tool | Description |
- | ----------- | ----------------------- |
- | `bash` | Execute shell commands |
- | `edit` | Modify existing files |
- | `write` | Create new files |
- | `read` | Read file contents |
- | `grep` | Search file contents |
- | `glob` | Find files by pattern |
- | `list` | List directory contents |
- | `patch` | Apply patches to files |
- | `todowrite` | Manage todo lists |
- | `todoread` | Read todo lists |
- | `webfetch` | Fetch web content |
- ---
- ### Permissions
- Permissions control what actions an agent can take.
- - edit, bash, webfetch
- Each permission can be set to allow, ask, or deny.
- - allow, ask, deny
- Configure permissions globally in opencode.json.
- ```json title="opencode.json"
- {
- "$schema": "https://opencode.ai/config.json",
- "permission": {
- "edit": "ask",
- "bash": "allow",
- "webfetch": "deny"
- }
- }
- ```
- You can override permissions per agent in JSON.
- ```json title="opencode.json" {7-18}
- {
- "$schema": "https://opencode.ai/config.json",
- "agent": {
- "build": {
- "permission": {
- "edit": "allow",
- "bash": {
- "*": "allow",
- "git push": "ask",
- "terraform *": "deny"
- },
- "webfetch": "ask"
- }
- }
- }
- }
- ```
- You can also set permissions in Markdown agents.
- ```markdown title="~/.config/opencode/agent/review.md"
- ---
- description: Code review without edits
- mode: subagent
- permission:
- edit: deny
- bash: ask
- webfetch: deny
- ---
- Only analyze code and suggest changes.
- ```
- Bash permissions support granular patterns for fine-grained control.
- ```json title="Allow most, ask for risky, deny terraform"
- {
- "$schema": "https://opencode.ai/config.json",
- "permission": {
- "bash": {
- "*": "allow",
- "git push": "ask",
- "terraform *": "deny"
- }
- }
- }
- ```
- If you provide a granular bash map, the default becomes ask unless you set \* explicitly.
- ```json title="Granular defaults to ask"
- {
- "$schema": "https://opencode.ai/config.json",
- "permission": {
- "bash": {
- "git status": "allow"
- }
- }
- }
- ```
- Agent-level permissions merge over global settings.
- - Global sets defaults; agent overrides when specified
- Specific bash rules can override a global default.
- ```json title="Global ask, agent allows safe commands"
- {
- "$schema": "https://opencode.ai/config.json",
- "permission": { "bash": "ask" },
- "agent": {
- "build": {
- "permission": {
- "bash": { "git status": "allow", "*": "ask" }
- }
- }
- }
- }
- ```
- Permissions affect tool availability and prompts differently.
- - deny hides tools (edit also hides write/patch); ask prompts; allow runs
- For quick reference, here are common setups.
- ```json title="Read-only reviewer"
- {
- "$schema": "https://opencode.ai/config.json",
- "agent": {
- "review": {
- "permission": { "edit": "deny", "bash": "deny", "webfetch": "allow" }
- }
- }
- }
- ```
- ```json title="Planning agent that can browse but cannot change code"
- {
- "$schema": "https://opencode.ai/config.json",
- "agent": {
- "plan": {
- "permission": { "edit": "deny", "bash": "deny", "webfetch": "ask" }
- }
- }
- }
- ```
- See the full permissions guide for more patterns.
- - /docs/permissions
- ---
- ### Mode
- Control the agent's mode with the `mode` config. The `mode` option is used to determine how the agent can be used.
- ```json title="opencode.json"
- {
- "agent": {
- "review": {
- "mode": "subagent"
- }
- }
- }
- ```
- The `mode` option can be set to `primary`, `subagent`, or `all`. If no `mode` is specified, it defaults to `all`.
- ---
- ### Additional
- Any other options you specify in your agent configuration will be **passed through directly** to the provider as model options. This allows you to use provider-specific features and parameters.
- For example, with OpenAI's reasoning models, you can control the reasoning effort:
- ```json title="opencode.json" {6,7}
- {
- "agent": {
- "deep-thinker": {
- "description": "Agent that uses high reasoning effort for complex problems",
- "model": "openai/gpt-5",
- "reasoningEffort": "high",
- "textVerbosity": "low"
- }
- }
- }
- ```
- These additional options are model and provider-specific. Check your provider's documentation for available parameters.
- :::tip
- Run `opencode models` to see a list of the available models.
- :::
- ---
- ## Create agents
- You can create new agents using the following command:
- ```bash
- opencode agent create
- ```
- This interactive command will:
- 1. Ask where to save the agent; global or project-specific.
- 2. Description of what the agent should do.
- 3. Generate an appropriate system prompt and identifier.
- 4. Let you select which tools the agent can access.
- 5. Finally, create a markdown file with the agent configuration.
- ---
- ## Use cases
- Here are some common use cases for different agents.
- - **Build agent**: Full development work with all tools enabled
- - **Plan agent**: Analysis and planning without making changes
- - **Review agent**: Code review with read-only access plus documentation tools
- - **Debug agent**: Focused on investigation with bash and read tools enabled
- - **Docs agent**: Documentation writing with file operations but no system commands
- ---
- ## Examples
- Here are some examples agents you might find useful.
- :::tip
- Do you have an agent you'd like to share? [Submit a PR](https://github.com/sst/opencode).
- :::
- ---
- ### Documentation agent
- ```markdown title="~/.config/opencode/agent/docs-writer.md"
- ---
- description: Writes and maintains project documentation
- mode: subagent
- tools:
- bash: false
- ---
- You are a technical writer. Create clear, comprehensive documentation.
- Focus on:
- - Clear explanations
- - Proper structure
- - Code examples
- - User-friendly language
- ```
- ---
- ### Security auditor
- ```markdown title="~/.config/opencode/agent/security-auditor.md"
- ---
- description: Performs security audits and identifies vulnerabilities
- mode: subagent
- tools:
- write: false
- edit: false
- ---
- You are a security expert. Focus on identifying potential security issues.
- Look for:
- - Input validation vulnerabilities
- - Authentication and authorization flaws
- - Data exposure risks
- - Dependency vulnerabilities
- - Configuration security issues
- ```
|