Configure OpenCode agents with distinct duties and tool limits
Split review, doc edits and orchestration between primary and subagents, then check each agent's permissions rule by rule.
Prerequisites and input · Engineering checks · 1. List duties and the actions they need
At a glance
When one agent can read, edit and run commands, every extra duty makes a mistake harder to trace. This guide turns "code tasks with different duties and the tool sets each may use" into a division-of-labor and permission check: list duties, write one agent per duty, then check the merged rules. This guide follows the official OpenCode Agent and Permissions documentation; the product was not run.
Runtime and applicability
- Article type
- Engineering practice
- Verified
- Applies to
- OpenCode Configure OpenCode agents with distinct duties and tool limits
Execution locations and responsibilities
- OpenCode configuration loader and runtime Use the workflow below to distinguish responsibilities of the caller, runtime, and external actions.
Arrows show the order of checks in the guide. Follow each step’s prerequisites, branches and stop conditions; unexecuted steps are not completed work.
When to use
- An agent combines a system prompt, model preference, permissions and display details. Put duty boundaries in
permissions, not only in the prompt; a prompt is a request, permissions are rules.
When not to use
hidden: trueonly removes an agent from listings and the subagent catalog; it does not stop behavior and is not a permission.- The V2 runner does not yet send the
requestfield with model requests, so it is not a way to limit or tune anything; old top-level fields such aspermission,toolsandmaxStepsare not for new configuration. - This guide does not cover command approval or file-path conflict details, which the separate permissions page describes, and it makes no judgement about how well any model reviews code.
Prerequisites and input
- You have listed the code tasks to split, such as read-only review, documentation-only edits and orchestration, and can state what each must not do.
- You can edit the project's
.opencode/agents/directory oropencode.jsonc, and you know these files are read by the OpenCode configuration loader while the runtime executes the result. - You use only the V2 form here:
permissions,modeanddescription, not the old top-level fields.
Engineering checks
Duty and permission ownership — An agent combines a system prompt, model preference, permissions and display details. Put duty boundaries in permissions, not only in the prompt; a prompt is a request, permissions are rules.
Parent-child relation and launch rights — mode decides whether an agent runs as primary, as a subagent, or as either. Which subagents a primary agent may launch is controlled by its own subagent rules, and a subagent runs only with its own configured permissions.
The merged effective configuration — Several definitions merge in configuration order: later scalars replace earlier ones, permission rules append, global rules come before agent rules, and the last matching rule wins. You check the merged result, not one file.
1. List duties and the actions they need
Where: a planning table; no configuration written yet. Input: the list of code tasks. Action: map each duty to the documented actions read, glob, grep, edit, shell, subagent, webfetch, websearch and skill, with an "allowed" and an "explicitly denied" column. Done when: every duty has both columns, and no duty holds both edit and shell without a written reason. Stop if: a duty needs a capability not in those actions; pause and re-read the documentation instead of inventing an action name.
2. Fix file location, ID and mode
Where: ~/.config/opencode/agents/<name>.md, .opencode/agents/<name>.md, or agents in opencode.jsonc. Input: the duty table. Action: one agent per duty; the Markdown body is the system prompt; nested directories become part of the agent ID, such as team/reviewer. Write mode explicitly, because a new custom agent defaults to primary when it is omitted; give every subagent a description, because it is shown to the model that chooses which agent to launch. Done when: each ID, mode and description is listed. Stop if: the same ID appears in several places and you cannot state the merge order; resolve that first.
3. Write ordered permissions rules
Where: each agent's permissions list. Input: the two-column table from step 1. Action: broad rules first, exceptions after, for example deny the * action on * resources and then allow read on src/**. Each rule has action, resource and effect, where effect is allow, ask or deny. Done when: every "explicitly denied" item, run through the list, ends on a deny as the last match. Stop if: you plan to use hidden or a "do not edit files" prompt in place of permissions, because hidden controls visibility only and is not a security measure; the agents page also does not state what a custom agent permits when no rule matches, so write the baseline explicitly.
4. Limit which subagents the primary agent may launch
Where: the orchestrating primary agent permissions. Input: the responsibility table and subagent IDs. Custom agents start from a base policy allowing all actions, so first deny all actions and then allow only the named subagent choices. If task files must be read, add a separately justified read scope instead of merely denying unknown subagents while leaving edit and shell available. Every subagent has its own permissions; configure each rather than treating it as a subset of parent permissions. Completion: every effective action has a responsibility reason, named subagents are available, and undeclared edits and shell commands remain denied. Stop on any undeclared permission and trace its source.
5. Check model, step limit and request fields
Where: each agent's model, steps and request. Input: cost and duration constraints. Action: write model as provider/model, optionally with #variant; a subagent without one inherits the parent session's model. steps is a positive integer; on the final step tools are removed and the model is asked to summarize in text, and new user input resets the allowance. The request headers and body are preserved by the V2 session runner but not yet sent with model requests, so do not rely on them for control. Done when: each agent's model source is recorded as configured or inherited. Stop if: you need request to tune a parameter; move that to the provider, model or variant configuration.
6. Verify the merged result and default entry
Where: the result after the configuration loader merges everything, and session selection. Input: all configuration files and their order. Action: write out each agent's final rule sequence; override a built-in agent by using the same ID; the agent named by default_agent must exist, be visible and support primary use, otherwise OpenCode uses build, then the first visible primary-capable agent; changing it does not replace the agent stored on an existing session. Done when: every agent has a walk-through from configuration to expected decision. Stop if: any rule's source cannot be traced; do not declare the configuration complete.
Task example
Original demonstration, not an observed run. Suppose a project needs three duties: orchestrator is a primary agent that only splits tasks; reviewer is a subagent that reads only src/**; doc-writer is a subagent that edits only documentation. orchestrator first denies all actions, then denies all subagent requests, then allows reviewer and doc-writer. reviewer denies every action first, then allows read on src/**. doc-writer denies every action first, then allows read and edit on the documentation directory. Expected paper walk-through: a request from orchestrator for reviewer is allowed and for any other ID is denied; edit and shell for reviewer both land on the leading deny; edit on src/** for doc-writer is denied as well. These are deductions from the documentation and have not been observed in a real session.
Completion checks
- Input ownership: every code task points to exactly one agent and to the actions it may and may not use.
- Execution location: you can say that rules are merged by the configuration loader and applied by the runtime in the child session, not guaranteed by prompts.
- Result contract and stop: each agent has a walk-through table; the launch list, the
default_agentfallback and the step limit are recorded, and you stopped on any rule of unknown origin.
Verification scope
Official OpenCode Agent and Permissions documentation was read. OpenCode was not installed, no sign-in or product API execution was performed, and no real tool output was observed. Examples are original unexecuted walkthroughs.
Sources
All links are official pages; verification dates are listed per source, and links point to the version checked.