[KongchangAI]
· 2 min read· 1,189 words

Building Multi-Agent Systems with Claude Code: Sub-Agent Context and Task Decomposition in Practice

Building Multi-Agent Systems with Claude Code: Sub-Agent Context and Task Decomposition in Practice

From tool selection and installation fixes to sub-agent context and human review—Claude Code multi-agent essentials.

Based on Bilibili creator "码士集团"'s share, this article covers Claude Code multi-agent implementation: prioritizing Claude Code/Codex for code tasks, switching to NPM when official install commands fail, using independent sub-agent context windows to avoid pollution, allocating models by task difficulty, and keeping human review checkpoints so AI autonomy stays controlled.

Claude Code's multi-agent architecture is becoming a focal point for developers. In a recent share, Bilibili creator "码士集团" (Mashi Group) laid out a practical, actionable approach covering tool selection, installation pitfalls, sub-agent configuration, and task decomposition. This article organizes that video content alongside general engineering principles for multi-agent collaboration.

Tool Selection: Why Claude Code or Codex

The creator opened with a blunt assessment: if your company has no specific requirements, prioritize Claude Code or Codex rather than tools like Trea (often misspelled as "Tree") or Cursor.

Happy to elaborate if you enjoy it

His reasoning comes from hands-on experience—in code generation and project development scenarios, Claude Code and Codex perform "possibly better" than Trea or Cursor. He also stressed this isn't self-promotion ("王婆卖瓜"), but respect for good tools.

This view deserves a balanced reading. Tool effectiveness is highly task-dependent: Cursor offers a mature in-IDE completion and quick-edit experience, while Claude Code's strengths lie more in long-context understanding, multi-file changes, and agentic task execution. If your workflow centers on "letting AI independently complete a module," Claude Code's architecture is indeed a better fit.

Claude Code is Anthropic's command-line AI programming tool, designed around agentic task execution—it can autonomously read and write files in a project directory, run commands, and iteratively modify code. Codex originally referred to OpenAI's series of code generation models (such as code-davinci, which powered GitHub Copilot), and later extended to OpenAI's agent product form for software engineering. Cursor is an AI-first IDE built on a VS Code fork, focused on inline completion, multi-line editing, and codebase-indexed Q&A. Trea (commonly misspelled as Tree) is an AI IDE product from ByteDance, also integrating conversational development and agent capabilities. Understanding the differences among these four helps clarify the creator's recommendation logic: Cursor and Trea are closer to "editor enhancement," while Claude Code and Codex lean toward "task delegation"—their positions in the workflow do not fully overlap.

Installation: Why the Official Commands Often Fail

The video devoted considerable time to installation issues, since this is almost every beginner's first hurdle.

I've also opened this up for everyone in advance

Most people, after opening the Claude Code official site, will directly copy the installation commands from the docs: a shell command for Mac/Linux, or execution in PowerShell or CMD for Windows.

Might use this in PowerShell

But the creator points out that anyone who has actually run these commands will find they "most likely fail to install"—network issues, proxy problems, or other environmental factors can all cause failure.

It threw a bunch of messy exceptions and errors

Once a flood of abnormal errors appears, his advice is not to keep hammering at it: you might fiddle for ages and still not solve it. A more reliable path is installing via NPM—this isn't his own invention, but a method explicitly documented in the official docs; just search for the relevant keywords there. For developers in China, NPM with a mirror source offers greater controllability and a clearer troubleshooting path.

NPM (Node Package Manager) is the package management and distribution tool for the Node.js ecosystem; npm install -g installs command-line tools globally. Claude Code's official curl script installation requires access to overseas domains, which easily breaks in network environments with unstable proxies or DNS pollution. In contrast, NPM installation can work with domestic mirror sources (such as npmmirror), making the download path more controllable and errors traceable layer by layer via commands like npm config get registry and npm ls -g. This is why "switching to another installation path" is often more efficient than repeatedly debugging the original script—the problem isn't the command itself, but the network path it depends on.

The Core Value of Sub-Agents: Independent Context

The key design of a multi-agent architecture is giving each sub-agent its own independent context window.

This is impossible in single-agent mode: as the main conversation continuously accumulates code, logs, and discussion, the context balloons rapidly, and the model's attention to early information gets diluted. Independent sub-agent context means each task executes in its own "clean room," receiving only explicitly dispatched information and returning results to the main agent.

This isolation brings two direct benefits: first, it avoids context pollution—sub-agents aren't disturbed by irrelevant historical conversation; second, different models can be configured for different tasks, e.g., lightweight models for retrieval and summarization, strong models for core code generation.

Context Window refers to the total number of tokens a model can hold in a single inference, including system prompt, conversation history, read-in file contents, and tool return results. As the window approaches its limit, early content gets truncated or forcibly compressed, and the model's ability to follow key constraints declines—a phenomenon often called "context rot" or "lost in the middle." Sub-agent architecture is essentially a context engineering technique: the main agent keeps only the high-level information needed for task orchestration, delegating context-heavy operations like specific file retrieval, batch edits, and log analysis to sub-agents, which return only conclusion summaries after execution. This keeps the main chain's context lean while sub-agents can fully expand details within their own windows.

Model Configuration and Task Decomposition: Keeping Control in Human Hands

Two other points the creator raised are model configuration and human review after task decomposition.

On model configuration, sub-agent architecture allows allocating model resources by task difficulty—both cost optimization and effectiveness optimization. Simple tasks use fast models, complex reasoning uses strong models, and overall throughput improves markedly.

Task decomposition is the watershed for whether multi-agent systems truly work. Break a large requirement into several clearly bounded subtasks, assign them to sub-agents respectively, then have humans review outputs at key checkpoints—this keeps AI always in a "controlled" state: it handles execution, humans handle direction and acceptance. The creator summarizes this principle as "letting AI work within control," which is also the bottom line of multi-agent engineering: autonomy can be granted, but review authority cannot be relinquished.

Practical Recommendations

Synthesizing the video content, several actionable recommendations emerge: evaluate Claude Code or Codex's performance on your own tasks first when choosing tools; switch decisively to NPM installation when the official method fails; insist on independent sub-agent context architecturally; and retain human review checkpoints in the process. Multi-agent isn't about letting AI run free—it's about using structured division of labor to constrain its capabilities within a controllable range.

One-line Summary

From tool selection and installation troubleshooting to independent sub-agent context and human review—key points for putting Claude Code multi-agent systems into practice.

Paragraph Summary

Based on Bilibili creator "码士集团"'s share, this article organizes practical implementation of Claude Code's multi-agent architecture. On tool selection, it suggests prioritizing Claude Code or Codex for code generation and project development over Trea or Cursor, but with task-type-aware judgment. On installation, it notes official commands often fail due to network and proxy issues, recommending the NPM path also documented officially for greater mirror controllability and clearer troubleshooting. Architecturally, it emphasizes that sub-agents' independent context windows prevent context pollution and support allocating different models by task difficulty to balance cost and effectiveness. Process-wise, it advocates task decomposition plus human review at key checkpoints—AI executes, humans direct and accept—keeping autonomy within controllable bounds.

#Claude Code#multi-agent#sub-agent context#task decomposition#NPM installation#AI coding tools
Share:

Related articles