OpenCode: OpenCode Agent Mode

Last updated: 2026-08-31

--- title: OpenCode Agents description: Understand the agent system with built-in agents, custom agents, and subagent configuration order: 13 lang: en

Agents are specialized AI assistants in OpenCode, each configurable with independent prompts, models, tools, and permissions.

1. What You Will Learn


2. Agent Types

Type Description Switching
Primary agent Main assistant for direct interaction Tab key
Subagent Specialized assistant called by primary @agent_name or auto-called

3. Built-in Agents

Agent Type Description
Build Primary Default agent with all tools enabled
Plan Primary Analysis and planning only—edits/bash set to ask
General Subagent Full tools, can modify files
Explore Subagent Read-only, cannot modify files

System agents (hidden): Compaction, Title, Summary


4. Switching and Calling Agents


5. Custom Agent Configuration

JSON config:

JSON
{
  "agent": {
    "code-reviewer": {
      "description": "Reviews code for best practices",
      "mode": "subagent",
      "model": "anthropic/claude-sonnet-4-20250514",
      "prompt": "You are a code reviewer. Focus on security and performance.",
      "tools": { "write": false, "edit": false }
    }
  }
}

Markdown file:

Place in ~/.config/opencode/agents/ (global) or .opencode/agents/ (project). Filename becomes the agent name.


6. Configuration Options

Option Description
description Agent function description (required)
mode primary / subagent / all
model Specify model (provider/model-id)
prompt System prompt, supports {file:./path}
temperature Output randomness (0.0-1.0)
steps Maximum iteration count
tools Tool access permissions
permission Fine-grained permission control
hidden Hide from @ menu
color UI display color
disable Disable agent

7. Quick Create

BASH
opencode agent create

Interactive guided agent creation.


❓ FAQ

Q When to use Plan instead of Build?
A When you want AI to analyze and advise without modifying files. Plan's edit/bash permissions are set to ask.
Q Can subagents call subagents?
A Yes, via Task tool. Avoid circular calls. Use permission.task to control.

📖 Summary


📝 Exercises

  1. Basic: Switch between Build and Plan agents in TUI using Tab.

  2. Intermediate: Create a read-only code review agent with low temperature and appropriate tool permissions.

  3. Advanced: Design a complete agent system (primary + subagents) for a full development workflow.

Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏