Claude Code agents workflow: an orchestrator setup guide

One coordinator, a few narrow subagents, and hand-offs written where the next agent will read them.

By · Published

A Claude Code agents workflow is a main conversation that acts as an orchestrator and delegates scoped tasks to subagents. Each subagent is defined in a Markdown file, runs in its own context window with its own instructions and tools, and returns only a summary, so the main conversation keeps room for planning while the detailed work happens elsewhere.

This guide shows how to define subagents, how to hand work between them, how to combine them with tests, and when a single agent is the better choice.

When do you need several agents?

Use subagents when a task has parts that can run independently, when exploration would fill the main context with search results, or when a risky step should run with fewer tools. Stay with one agent when the task fits in one conversation and its parts are tightly linked.

How do you set up an orchestrator and subagents?

Subagents are Markdown files with YAML frontmatter, stored in .claude/agents/ for the project or ~/.claude/agents/ for every project (Claude Code subagents documentation). Only name and description are required. tools limits what the subagent may use; without it, the subagent inherits the available tools. model chooses sonnet, opus, haiku, a full model name or inherit.

A minimal .claude/agents/coder.md:

---
name: coder
description: Implements one ticket from its spec. Use after the planner has written the spec and its failing tests.
tools: Read, Edit, Write, Bash
---
Implement one ticket at a time. Read the spec and the failing tests named in the hand-off.
Change only the files listed there. When the tests pass, write a summary of the diff,
the decisions you made and any open question to the hand-off file.

The description is what the main conversation uses to decide when to delegate, through its Agent tool, so write it as "use when…" rather than as a job title.

Keep the orchestrator's instructions short

The project's CLAUDE.md describes the pipeline, not every detail: the phases, which subagent owns each one, and the hand-off rule. Claude Code's guidance is to keep each CLAUDE.md under about 200 lines (memory documentation).

Give each subagent the smallest set of tools

A reviewer needs Read, Grep and Glob, not Edit: it can report a problem without fixing it in the middle of a review. A planner that writes tests does not need access to deployment commands.

How do agents hand off work?

A hand-off is a contract with two sides. The orchestrator gives a scope, an explicit list of files and the acceptance criteria. The subagent returns what changed, the decisions it made and its open questions. Whatever is left out of that contract is rediscovered later, usually as a bug.

Write hand-offs to files, not only to the conversation. A subagent's context disappears when it returns, and the main conversation itself will be compacted. A decisions log and per-task notes next to CLAUDE.md let a fresh session pick up the reasoning.

When work moves between Claude Code, Codex and Cursor, or between machines, the hand-off needs a place every tool can read. Fileaify is one: the project's decisions and state live in a hosted workspace that each agent reads over the MCP connector or REST, and keys stay in a vault instead of being passed between prompts. The rule holds either way: a decision that exists in only one agent's context does not exist.

How do you structure CLAUDE.md for several agents?

  • Root CLAUDE.md: the architecture map, service boundaries and the rules no agent may break, such as "never edit generated files".
  • Folder CLAUDE.md files: local conventions, loaded when Claude works in that folder, so a front-end task does not carry back-end rules.
  • A decisions log: dated, one line per decision, referenced from the root file instead of copied into it.

Leave out daily task lists and session state; they belong in a tracker or a shared project record.

How do you combine subagents with test-driven development?

Tests give every subagent a clear finish line.

  1. Red: a planner receives the spec and the conventions, and writes failing tests plus a short note naming the files under test. It writes no implementation, so it cannot make its own tests pass.
  2. Green: the coder receives the tests and one instruction: make them pass with the smallest diff.
  3. Refactor: a reviewer reads the diff and the test results and reports dead code, missed cases and drift from the conventions.

Record each cycle's decisions where the next session will read them.

Design hand-offs

The same rule applies to a design: export tokens, spacing and component structure into a versioned file in the repository, and have the subagent build until the component matches that file. A file can be checked; a screenshot cannot.

What are the common mistakes?

Mistake What happens Fix
Two agents edit the same file The conflict appears at the merge One writer per path, named in the hand-off
No shared record Each agent rediscovers dead ends Decisions written to a file or shared record at every hand-off
Scope too broad The subagent wanders and fills its context One job, named files, a defined output
Context kept in one tool Switching tools means explaining again Conventions in AGENTS.md, decisions in a record every tool reads

When is a single agent better?

When diffs are small, changes are tightly coupled, or the work is exploratory, an orchestrator only adds hand-offs and merge risk. Measure first: for a week, count how often you restate the architecture, the test commands or a settled decision. If that happens every session, the problem is persistence, not the number of agents, and a well-kept CLAUDE.md plus a decisions log fixes most of it. Orchestrate when the work really splits into independent parts.

Sources

Try it

The demo runs on a prepared project, with no account. To give several agents one project record, create a free workspace and give your agent https://fileaify.com/agent.

Common questions

Do Claude Code subagents share context with each other?

No. Each subagent runs in its own context window and returns a summary to the main conversation. Anything the next agent needs must be written to a file or a shared project record.

Where are Claude Code subagents defined?

In Markdown files with frontmatter, in .claude/agents/ for a project or ~/.claude/agents/ for all your projects. Only name and description are required; tools and model are optional.

How many subagents should run at once?

As many as the task has independent parts, often two or three. Work that touches the same files or depends on another step's result should run one after the other.

Does this work with Codex or Cursor?

The pattern does, the files do not: .claude/agents and the Agent tool are Claude Code features. What transfers is keeping conventions in AGENTS.md and decisions in a record every tool can read.

Written with AI assistance, reviewed by Stéphane Mermet and checked against the product. Fileaify publishes this guide and sells the service it describes.