Overview
Theagent command helps you create and manage custom agents with specialized system prompts and tool configurations. Agents can be:
- Primary agents: Act as the main assistant
- Subagents: Specialized agents invoked by other agents
- All-purpose: Can function in both roles
Usage
Subcommands
create
Generate a new custom agent
list
Show all available agents
create
Create a new agent with custom configuration.Usage
Interactive Flow
The command guides you through creating an agent:- Choose location: Global or project-specific
- Describe purpose: What the agent should do
- Generate configuration: LLM creates system prompt
- Select tools: Choose which tools to enable
- Set mode: Primary, subagent, or both
Example Session
Options
Directory path to generate the agent file
What the agent should do
Agent mode:
all, primary, or subagentComma-separated list of tools to enable. Empty string disables all tools.
Model to use for agent generation (format:
provider/model). Short form: -mNon-Interactive Mode
Provide all options to create an agent without prompts:list
Show all available agents.Usage
Example Output
- Agent name and mode
- Permission/tool configuration
- Whether agent is enabled
Agent Structure
Agents are Markdown files with YAML frontmatter:Frontmatter Fields
Brief description of when to use this agent. Shown to other agents when selecting subagents.
Agent mode:
all: Can be primary or subagentprimary: Only usable as main agentsubagent: Only for task delegation
Tool configuration. Omitted tools default to enabled. Set to
false to disable:Available Tools
- bash: Execute shell commands
- read: Read file contents
- write: Create new files
- edit: Modify existing files
- list: List directory contents
- glob: Find files by pattern
- grep: Search file contents
- webfetch: Fetch web pages
- task: Delegate to subagents
- todowrite: Manage task lists
- todoread: Read task lists
Agent Locations
Project Agents
Stored in.opencode/agent/ in your project:
Global Agents
Stored in~/.config/opencode/agent/:
Priority
Project agents override global agents with the same name.Using Agents
Primary Agent
Select agent when starting OpenCode:Subagent Delegation
Agents can invoke specialized subagents:- Identifies the need for specialized help
- Selects appropriate subagent based on descriptions
- Delegates the subtask
- Receives results and continues
Agent Generation
When you create an agent, OpenCode uses an LLM to generate:- Identifier: Filename-safe name (e.g.,
typescript-expert) - Description: When to use this agent
- System prompt: Detailed instructions and guidelines
Generation Model
By default, uses your configured default model. Override with--model:
Generation Quality
For best results:- Be specific in your description
- Mention key technologies or domains
- Include constraints or preferences
- Reference coding standards if applicable
Example Agents
Security Auditor
Documentation Writer
Test Specialist
Best Practices
Focused agents
Create specialized agents for specific domains rather than generalists
Clear descriptions
Write descriptions that help other agents know when to delegate
Minimal tools
Only enable tools the agent needs to reduce confusion
Consistent style
Follow the same structure across your agent files
Troubleshooting
Agent Not Found
Problem:agent "name" not found
Solutions:
- Run
opencode agent listto see available agents - Check filename matches agent name
- Verify file is in correct location (
.opencode/agent/or~/.config/opencode/agent/) - Ensure file has
.mdextension
Generation Failed
Problem: LLM fails to generate agent Solutions:- Check you’re authenticated:
opencode auth list - Try a different model with
--model - Make description more specific
- Check internet connectivity
Subagent Mode Error
Problem:agent "name" is a subagent, not a primary agent
Solutions:
- Use a different agent marked as
primaryorall - Change the agent’s mode to
allin its frontmatter - Run
opencode agent listto see agent modes
File Already Exists
Problem:Agent file already exists
Solutions:
- Delete or rename the existing agent file
- Use a different description that generates a unique identifier
- Manually create with a custom filename
Related Topics
Agents Concept
Learn about how agents work
Tools
Understand available tools
Permissions
Configure agent permissions
Configuration
Set default agent in config