Skip to main content

Overview

The agent 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:
  1. Choose location: Global or project-specific
  2. Describe purpose: What the agent should do
  3. Generate configuration: LLM creates system prompt
  4. Select tools: Choose which tools to enable
  5. Set mode: Primary, subagent, or both

Example Session

Options

--path
string
Directory path to generate the agent file
--description
string
What the agent should do
--mode
string
Agent mode: all, primary, or subagent
--tools
string
Comma-separated list of tools to enable. Empty string disables all tools.
--model
string
Model to use for agent generation (format: provider/model). Short form: -m

Non-Interactive Mode

Provide all options to create an agent without prompts:
The command outputs the created file path:

list

Show all available agents.

Usage

Example Output

Shows:
  • Agent name and mode
  • Permission/tool configuration
  • Whether agent is enabled

Agent Structure

Agents are Markdown files with YAML frontmatter:

Frontmatter Fields

description
string
required
Brief description of when to use this agent. Shown to other agents when selecting subagents.
mode
string
default:"all"
Agent mode:
  • all: Can be primary or subagent
  • primary: Only usable as main agent
  • subagent: Only for task delegation
tools
object
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:
Available only in this project.

Global Agents

Stored in ~/.config/opencode/agent/:
Available in all projects.

Priority

Project agents override global agents with the same name.

Using Agents

Primary Agent

Select agent when starting OpenCode:
Or in configuration:
Switch agents mid-session:

Subagent Delegation

Agents can invoke specialized subagents:
The main agent:
  1. Identifies the need for specialized help
  2. Selects appropriate subagent based on descriptions
  3. Delegates the subtask
  4. 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 descriptions:

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 list to see available agents
  • Check filename matches agent name
  • Verify file is in correct location (.opencode/agent/ or ~/.config/opencode/agent/)
  • Ensure file has .md extension

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 primary or all
  • Change the agent’s mode to all in its frontmatter
  • Run opencode agent list to 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

Agents Concept

Learn about how agents work

Tools

Understand available tools

Permissions

Configure agent permissions

Configuration

Set default agent in config