Habr AI→ original

Subagents in Claude Code: how to delegate reviews and tests to separate agents

Claude Code quickly hits context limits — the longer the session, the worse the agent performs. Subagents solve this: reviews, tests, audits, and code investigation are delegated to separate agents with clean context and their own toolset. The main session receives only the summary — without intermediate clutter.

AI-processed from Habr AI; edited by Hamidun News
Subagents in Claude Code: how to delegate reviews and tests to separate agents
Source: Habr AI. Collage: Hamidun News.
◐ Listen to article

Subagents in Claude Code allow delegating resource-intensive tasks — reviews, tests, audits, code research — to separate agents with independent context, tools, and rules, bypassing the tool's main limitation: context window exhaustion.

Why context is Claude Code's main enemy

Most developers who start working with Claude Code notice one pattern: the tool works brilliantly at the start of a session and noticeably worse — by the middle and end. The reason isn't the model's capabilities — Anthropic regularly improves Claude. The reason lies in context management architecture.

Each interaction within a session accumulates in the context window: read files, written plans, edit history, tool output, command results. The longer the session, the more "noise" in the context. The model begins to lose its thread of reasoning, produce contradictions with earlier instructions, sometimes return to already-rejected solutions.

The standard solution is breaking work into short sessions. But this is inconvenient: you have to restore context manually each time, copy intermediate results, and re-explain to the agent what's already been done.

Subagents offer a systemic answer to this problem.

What are subagents and how do they work

Subagents are separate agent instances that the main Claude Code session launches for specific sub-tasks. The key difference from manual "start a new chat": delegation happens programmatically, and the result returns to the main session in structured form.

Each subagent operates in an isolated environment:

  • Its own context window — independent from the parent session, starts clean
  • A tool set for the task — only file reading for audits, or test execution for QA
  • Separate rules and instructions — role is configured via system prompt or CLAUDE.md file
  • Isolated working directory — when needed, subagent works in a separate git-worktree

The interaction scheme is simple: the main agent sets a task, passes needed files and context, launches the subagent. It works in an isolated session and returns only the result — a review report, list of issues, ready tests — without intermediate reasoning.

Parallelism is an additional bonus. Several subagents can run simultaneously: while one does review, another writes tests for the same module. The main session coordinates the work without performing it.

What tasks are best to delegate

Not every task makes sense to offload to a subagent — delegation carries overhead for initialization and context transfer. But for a number of scenarios the payoff is obvious.

Code review — analyzing a PR or specific file requires deep diving but yields compact results: a list of remarks with priorities. Subagent reads code, outputs a report, and doesn't pollute the main context with thousands of lines.

Writing tests — subagent gets a function description or source file, writes tests, runs them, and reports results. The main session meanwhile continues working on other project parts.

Security audit — checking vulnerabilities with OWASP checklist and isolated security rules returns a short list of findings with priorities, not cluttering the main context.

Codebase research — finding all pattern occurrences or exploring unfamiliar project sections: subagent returns a structured dependency map without taking up space in the main window.

What it means

Subagents change the approach to working with an AI assistant in development: instead of one large session that degrades with growing context, the developer gets orchestration of specialized agents — each works with a clean context window in its zone of responsibility.

One reviews, another tests, a third hunts for vulnerabilities. This is closer to managing a small team than talking to a single helper — and this approach exactly allows Claude Code to stably handle large, multi-day tasks without losing quality.

ZK
Hamidun News
AI news without noise. Daily editorial selection from 50+ sources. A product by Zhemal Khamidun, Head of AI at Alpina Digital.

Want to stop reading about AI and start using it?

AI News is a curated feed of AI/tech news. Hamidun Academy teaches you to use AI systematically in your work.

What do you think?
Loading comments…