Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

OpenCode Agent (Agent)

OpenCode Agent (Agent) Configuration Details

Agents are specialized AI assistants in OpenCode. Each agent can be configured with its own system prompt, model, tool access permissions, and behavior constraints to handle specific types of tasks and workflows. You can switch agents at any time during a session, or via @代理名称 to directly invoke a specific agent.


Agent types

Agents in OpenCode are divided into two types, which differ in how they are invoked and their responsibilities:

Type Description Switching Method
Primary agent (primary) The main assistant you interact with directly, handling the main conversation flow. Tool access permissions are cycled through via permission Configure Press Tab key, or use the configured agent_cycle Keyboard shortcut
Subagent (subagent) An assistant invoked by the primary agent to perform specialized tasks, running in an independent sub-session without affecting the main session context Automatically invoked by the primary agent, or in a message using @代理名称 Manual invocation

Built-in agents

OpenCode includes 4 ready-to-use agents out of the box, as well as 3 automatically running system agents:

1. Build (primary agent)

The default primary agent with all tools enabled, suitable for everyday development work that requires full file operations and system command access. This is the agent you will use most often.

2. Plan (primary agent)

A restricted agent designed for code analysis and planning. By default, the following operations trigger approval prompts (set to ask):

When you want the LLM to analyze code, offer suggestions, or create an execution plan, but do not want it to make any actual changes to the codebase, switch to the Plan agent.

3. General (subagent)

A general-purpose subagent with full tool access (except the todo tool), which can modify files. Suitable for researching complex issues and performing multi-step tasks; multiple independent units of work can also be run in parallel.

4. Explore (subagent)

A read-only subagent that cannot modify any files. Suitable for quickly finding files, searching code keywords, or answering questions about codebase structure; it is fast and has no side effects.

5. System agents (hidden)

The following three agents are managed automatically by OpenCode,and do not appear in the agent switching list, and cannot be selected manually (nor is there any need to):

Agent name Responsibility Trigger Timing
Compaction Compress overly long contexts into smaller summaries to prevent exceeding the model context limit Runs automatically when the context length reaches a threshold
Title Generate a short title for the session Runs automatically after a new session starts
Summary Create a summary for the session Runs automatically when a session summary is needed

How to use agents

1. Switch primary agents

During a session, press Tab to cycle through all primary agents, press Shift+Tab to switch in the reverse direction. You can also use a to open the agent list and select directly.

2. Invoke subagents

There are two ways to invoke subagents:

@general help me search for this function across the codebase

3. Navigate between parent and child sessions

When a subagent runs, it creates an independent sub-session; you can use shortcuts to navigate between the parent session and each sub-session:

Keyboard shortcut Operation
+→(session_child_cycle) Cycle forward: parent session → sub-session 1 → sub-session 2 → … → parent session
+←(session_child_cycle_reverse) Cycle backward: parent session ← sub-session 1 ← sub-session 2 ← … ← parent session
+↑(session_parent) Return directly to the parent session

Two configuration methods

Agents can be defined either through JSON configuration or Markdown files; both have the same effect; choose as needed:

Method 1: Configure in opencode.json

Example

{

 

"$schema"

:

"https://opencode.ai/config.json"

,

 

"agent"

:

{

   

"build"

:

{

                                         

// Override the configuration of the built-in build agent

     

"mode"

:

"primary"

,

     

"model"

:

"anthropic/claude-sonnet-4-20250514"

,

     

"prompt"

:

"{file:./prompts/build.txt}"

,

         

// Load the system prompt from a file

     

"tools"

:

{

       

"write"

:

true

,

       

"edit"

:

true

,

       

"bash"

:

true

     

}

   

}

,

   

"code-reviewer"

:

{

                                 

// Custom subagent

     

"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

     

}

   

}

 

}

}

Method 2: Markdown files

Create in the following path .md file,the filename is the agent name(such as review.md Corresponding agent name review):

Example

File path: ~/.config/opencode/agents/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

:

Provide constructive feedback without making direct changes.


Configuration options in detail

description (description)

The agent's function description, shown in the agent list and @ the autocomplete menu, helping users and the primary agent determine when to invoke the agent. For custom agents, this item isRequired:

Example

{

 

"agent"

:

{

   

"review"

:

{

     

"description"

:

"Reviews code for best practices and potential issues"

   

}

 

}

}

mode (mode)

Controls how the agent is used; can be set to the following three values:

Value Description
"primary" Primary agent, appears in the Tab switching list, used for the main conversation
"subagent" Subagent, does not appear in the Tab switching list, invoked by the primary agent or manually via @
"all" Used as both primary agent and subagent (the default when mode is not specified)

Example

{

 

"agent"

:

{

   

"review"

:

{

     

"mode"

:

"subagent"

   

// Used only as a subagent, does not appear in the primary agent switching list

   

}

 

}

}

model (model)

Specify a particular model for the agent, overriding the globally configured default model. The format is provider/model-id. Suitable for using different models for different tasks, e.g., a faster small model for planning tasks and a more powerful large model for code generation:

Example

{

 

"agent"

:

{

   

"plan"

:

{

     

"model"

:

"anthropic/claude-haiku-4-20250514"

   

// Use the faster Haiku model for planning tasks

   

}

,

   

"build"

:

{

     

"model"

:

"anthropic/claude-sonnet-4-20250514"

 

// Use the more capable Sonnet model for development tasks

   

}

 

}

}

If the model, the primary agent uses the globally configured default model, and the subagent inherits the model used by the primary agent that invoked it. Run opencode models to view the list of all available models.

prompt (system prompt)

Specify a custom system prompt for the agent; you can write a string directly, or through {file:./路径} syntax to load from an external file. The path is relative to the location of the configuration file:

Example

{

 

"agent"

:

{

   

"review"

:

{

     

"prompt"

:

"{file:./prompts/code-review.txt}"

     

// Read the prompt from prompts/code-review.txt in the same directory as opencode.json

     

// Suitable when the prompt content is long; maintain it separately in a text file

   

}

 

}

}

temperature (temperature)

Controls the randomness of model output. Lower values produce more deterministic output, suitable for tasks requiring precise results; higher values produce more diverse output, suitable for creative tasks:

Temperature range Output characteristics Applicable scenarios
0.0 – 0.2 Highly focused and strongly deterministic Code analysis, planning, debugging, review
0.3 – 0.5 Balanced, combining accuracy and flexibility General development tasks, documentation writing
0.6 – 1.0 More creative and diverse Brainstorming, solution exploration, creative writing

Example

{

 

"agent"

:

{

   

"analyze"

:

{

     

"temperature"

:

0.1

,

                         

// Analysis tasks: high determinism

     

"prompt"

:

"{file:./prompts/analysis.txt}"

   

}

,

   

"build"

:

{

     

"temperature"

:

0.3

                         

// Development tasks: balanced

   

}

,

   

"brainstorm"

:

{

     

"temperature"

:

0.7

,

                         

// Brainstorming: more creative

     

"prompt"

:

"{file:./prompts/creative.txt}"

   

}

 

}

}

Not specified temperature When not specified, OpenCode uses the model's default value—most models default to 0, Qwen series models default to 0.55。

steps (maximum steps)

Controls the maximum number of iterations (i.e., rounds of tool calls) an agent can perform before being forced to respond with plain text. Suitable for scenarios requiring cost control or preventing infinite agent loops:

Example

{

 

"agent"

:

{

   

"quick-thinker"

:

{

     

"description"

:

"Fast reasoning with limited iterations"

,

     

"prompt"

:

"You are a quick thinker. Solve problems with minimal steps."

,

     

"steps"

:

5

   

// Perform at most 5 iterations; beyond that, the agent outputs a summary of current progress and remaining suggested tasks

   

}

 

}

}

Not set steps When not specified, the agent continues iterating until the model stops on its own or the user manually interrupts.

Legacy maxSteps field is deprecated; please use uniformly steps。

tools (tool access)

Controls which tools the agent can use; set tool names to true or false. Agent-level configurationoverrides global configuration:

Example

{

 

"$schema"

:

"https://opencode.ai/config.json"

,

 

"tools"

:

{

   

"write"

:

true

,

   

// Global: allow writing files

   

"bash"

:

true

     

// Global: allow bash commands

 

}

,

 

"agent"

:

{

   

"plan"

:

{

     

"tools"

:

{

       

"write"

:

false

,

   

// plan agent: override global settings, disable file writing

       

"bash"

:

false

     

// plan agent: override global settings, disable bash

     

}

   

}

 

}

}

You can also use wildcards to control tools in bulk, e.g., disable all tools of a certain MCP server:

Example

{

 

"agent"

:

{

   

"readonly"

:

{

     

"tools"

:

{

       

"mymcp_*"

:

false

,

   

// Disable all tools of the mymcp server (Glob matching)

       

"write"

:

false

,

       

"edit"

:

false

     

}

   

}

 

}

}

permission (permission)

Configure finer-grained permission control for the agent; you can set for each operation "allow"(allow),"ask"(ask) or "deny"(deny):

Example

{

 

"$schema"

:

"https://opencode.ai/config.json"

,

 

"permission"

:

{

   

"edit"

:

"deny"

       

// Global: deny all file edits by default

 

}

,

 

"agent"

:

{

   

"build"

:

{

     

"permission"

:

{

       

"edit"

:

"ask"

     

// build agent: override global settings, approval required before editing

     

}

   

}

 

}

}

For bash tools can also be fine-grained down to specific commands, support Glob wildcards, andthe last matching rule takes precedence(It is recommended to put * wildcard rules first and specific rules later):

Example

{

 

"agent"

:

{

   

"build"

:

{

     

"permission"

:

{

       

"bash"

:

{

         

"*"

:

"ask"

,

           

// Fallback: all bash commands require approval by default

         

"git status *"

:

"allow"

,

// git status-related commands are directly allowed (more specific, matched first)

         

"grep *"

:

"allow"

     

// grep search commands are directly allowed

       

}

     

}

   

}

 

}

}

In Markdown agent files, permissions can also be configured in the frontmatter:

Example

File path: ~/.config/opencode/agents/review.md


description

:

Code review without edits

mode

:

subagent

permission

:

  edit

:

deny          

Deny all file edits

  bash

:

    "*"

:

ask          

bash commands require approval by default

    "git diff"

:

allow

Allow git diff

    "git log*"

:

allow

Allow git log and its variants

    "grep *"

:

allow  

Allow grep search

  webfetch

:

deny      

Deny access to external URLs


Only analyze code and suggest changes.

permission.task (task permission)

Controls which subagents the agent can invoke via the Task tool, supporting Glob matching. Set to "deny" When set, the subagent is completely removed from the Task tool description and the model will not attempt to invoke it:

Example

{

 

"agent"

:

{

   

"orchestrator"

:

{

     

"mode"

:

"primary"

,

     

"permission"

:

{

       

"task"

:

{

         

"*"

:

"deny"

,

                 

// Fallback: deny invocation of all subagents by default

         

"orchestrator-*"

:

"allow"

,

 

// Allow invocation of subagents starting with orchestrator-

         

"code-reviewer"

:

"ask"

       

// User confirmation required before invoking code-reviewer

         

// The last matching rule takes precedence: orchestrator-planner matches both * and orchestrator-*,

         

// because orchestrator-* comes later, the result is allow

       

}

     

}

   

}

 

}

}

hidden (hidden)

Hide subagents from the @ autocomplete menu, allowing only programmatic invocation via the Task tool; suitable for tool agents that should only be invoked internally by other agents:

Example

{

 

"agent"

:

{

   

"internal-helper"

:

{

     

"mode"

:

"subagent"

,

   

// hidden is only effective for subagents

     

"hidden"

:

true

       

// Once hidden, this agent does not appear in the user's @ completion menu,

                             

// but when permissions allow, the model can still invoke it via the Task tool

   

}

 

}

}

color (color)

The display color of the custom agent in the UI. Supports hexadecimal color values or theme color keywords (primary、secondary、accent、success、warning、error、info):

Example

{

 

"agent"

:

{

   

"creative"

:

{

     

"color"

:

"#ff6b6b"

     

// Use hexadecimal colors

   

}

,

   

"code-reviewer"

:

{

     

"color"

:

"accent"

     

// Use theme color keywords

   

}

 

}

}

top_p (sampling diversity)

top_p Is temperature is another parameter that controls output diversity, with a value range of 0.0 – 1.0; the lower the value, the more focused the output, and the higher the value, the more diverse the output:

Example

{

 

"agent"

:

{

   

"brainstorm"

:

{

     

"top_p"

:

0.9

   

// Higher top_p increases output diversity

   

}

 

}

}

disable (disabled)

Set the agent to a disabled state; once disabled, the agent will not appear in the selection list:

Example

{

 

"agent"

:

{

   

"review"

:

{

     

"disable"

:

true

   

// Disable this agent without affecting other agents

   

}

 

}

}

Other model parameters

Any unrecognized fields in the agent configuration are passed directly to the service provider as model parameters. This allows you to use provider-specific advanced features:

Example

{

 

"agent"

:

{

   

"deep-thinker"

:

{

     

"description"

:

"Agent that uses high reasoning effort for complex problems"

,

     

"model"

:

"openai/gpt-5"

,

     

"reasoningEffort"

:

"high"

,

   

// OpenAI reasoning effort parameter, passed through directly to the OpenAI API

     

"textVerbosity"

:

"low"

       

// OpenAI response verbosity parameter

   

}

 

}

}

Pass-through parameters vary by service provider and model; please consult the corresponding provider's API documentation to confirm the available parameter names.


Quickly create an agent

In addition to manually writing configuration files, you can also use an interactive command-line tool to quickly generate an agent:

opencode agent create

This command will guide you through the following steps in order:

  1. Choose where to save the agent (global ~/.config/opencode/agents/ or project-level .opencode/agents/)
  2. Describe the agent's responsibilities and goals
  3. Automatically generate a suitable system prompt and agent identifier
  4. Select the tools the agent can access
  5. Generate a Markdown file with the complete configuration in the chosen location

Agent examples

Documentation writing agent

Example

File path: ~/.config/opencode/agents/docs-writer.md


description

:

Writes and maintains project documentation

mode

:

subagent

tools

:

  bash

:

false    

Disable bash, since documentation writing does not require executing commands


You are a technical writer. Create clear, comprehensive documentation.

Focus on

:

Security audit agent

Example

File path: ~/.config/opencode/agents/security-auditor.md


description

:

Performs security audits and identifies vulnerabilities

mode

:

subagent

tools

:

  write

:

false    

Read-only: do not write files

  edit

:

false    

Read-only: do not edit files


You are a security expert. Focus on identifying potential security issues.

Look for

:


Common usage scenarios

Scenario Recommended agent configurations
Daily development, requires full tool permissions Use the built-in Build Proxy / agent
Analyze code and devise plans without modifying files Switch to the built-in Plan Proxy / agent
Read-only queries of codebase structure or keywords Pass @explore Invoke the built-in Explore subagent
Execute multiple independent tasks in parallel Pass @general Invoke multiple General subagents for parallel processing
Perform security or quality reviews of code Custom read-only subagent (disable write/edit) with a low temperature setting (0.1)
Control costs by limiting the number of AI execution steps Configure steps the parameter limits the maximum number of iterations