Urgent.News

What's breaking now, across hundreds of outlets.

AI

Claude Code Context Deep Dive (6): What Subagents Keep Out of Your Context

Editor's note: This is an AI-assisted English adaptation of a research note on Claude Code v2.1.220. It distinguishes observations from that build from the current documented behavior of subagents, forks, and workflows. Say you ask Claude Code to find React components in a monorepo that use useMemo with the wrong dependencies. The main agent can search for every candidate, read each file, and…

When instructing Claude Code v2.1.220 to locate React components in a monorepo using useMemo with incorrect dependencies, the primary agent can conduct a comprehensive search and examination of every file, carefully evaluating the results. However, the challenge lies not in the agent's ability to perform this task, but rather in the subsequent burden it carries: it must retain all search results and file excerpts, which are likely unrelated to the next task at hand.

In response, a subagent can independently undertake the investigation within its own conversation and subsequently provide a concise report. This enables the main agent to obtain a narrowed-down list of candidates that require rectification, rather than sifting through every potential outcome the search initially produced. This concept is further discussed in the broader pattern outlined in Anthropic's context engineering article, as well as in the companion Agent Loop article focusing on sidechains. The key inquiry here pertains to the specific contents each model call has access to.

A subagent, unlike a non-forked subagent, initiates a brand-new conversation instead of merely replicating the parent conversation and tool results. The delegation process supplies the subagent with a task prompt, while the subagent's system prompt, tool access, and permission settings are defined within the subagent guide. The tool is now referred to as Agent, previously known as Task.

The Agent tool deep dive provides historical context on the tool interface. Notably, the old note found that subagents did not receive CLAUDE.md. This rule no longer holds true for current versions. While many subagents load pertinent instruction files at startup, the Explore and Plan subagents skip that initial bundle. However, a custom definition may utilize omitClaudeMd on supported versions, subject to the documented rules for managed instructions.

Additionally, directory-specific instructions can be loaded during the agent's work with relevant files. Importantly, the parent’s auto memory is not automatically incorporated into a fresh subagent. Part 5 elucidates the distinction between standing instructions and auto memory.

Upon receiving the subagent's report, the transcript remains separate from the main message history. The conventional return path delivers the subagent's result to the parent without incorporating the entire investigation into the main message history. The older note explained a particular final-text extraction and usage envelope.

For the purpose of this discussion, the exact format of these implementation details is considered implementation-specific. The critical boundary is that the parent can act upon the findings without having to read every step that led to them. The transcript is not necessarily discarded. Current documentation outlines separate JSONL transcripts that can persist even after the parent conversation has undergone compaction.

If further investigation is required, the subagent can be resumed. If a specific claim needs verification, the parent can request the relevant evidence or inspect the cited lines. Neither option necessitates importing all tool results into the parent conversation.

Parts 1 and 2 discuss the mechanisms by which tool results become integrated into the conversation that is subsequently returned to the model. There is also an associated cache consequence. The parent appends the delegation and its resulting outcome after the existing history. The child's intermediate reads do not overwrite this prefix. While a normal subagent caches its own results, this approach maintains a lean parent without guaranteeing fewer overall tokens consumed.

Forking presents an alternative approach, trading a fresh start for inherited context. A fresh subagent should be employed when the evidence is readily available within the repository and the task can be articulated independently. In contrast, a fork is advisable when the task necessitates the inherited context from the parent's previous learning, such as a sequence of unsuccessful fixes and the reasoning behind them.

The prompt-caching guide indicates that a fork inherits the parent's prompt, tool set, and conversation. It can also reuse a matching warm prefix. However, the old note inaccurately stated that a fork strips all inherited tool results. This is both a misrepresentation of the documented behavior and an oversimplification that obscures a valuable feature of forks: they can begin with the evidence already present in the conversation. Nevertheless, a shared prefix still necessitates an existing cache entry within its lifetime.

Context isolation and worktree isolation are distinct concepts. Even with a subagent possessing its own conversation, working within the same checkout can lead to conflicts if two agents attempt to modify the same files. For independent alterations, supported agents can leverage isolation by operating in another checkout using worktree.

It is crucial to review the base revision and assess what has changed before integrating the changes. It is essential to note that the worktree is not automatically destroyed when the agent concludes or that it serves as a general-purpose sandbox. While the old note utilized Node.js AsyncLocalStorage to illustrate how an in-process implementation might scope a working-directory value to each asynchronous execution chain, the underlying design principle remains consistent regardless of the specific mechanism employed.

Changing a process-global directory is fundamentally different from granting a single tool call a scoped working directory. The precise storage mechanism remains undisclosed. Additionally, context boundaries do not equate to permission boundaries. Instead, one should review the subagent’s tool and permission configuration to determine its actual permissions, rather than presuming it inherits every runtime approval or starts with no permissions at all.

The Agent Loop article on approvals provides the complementary perspective. It is important to remember that independent context does not inherently imply a separate account, quota, or guaranteed cancellation behavior.

Rewritten by urgent.news; may contain errors — check the original.

Source: dev.to

Read the original at dev.to →

Report a problem with this story

More in AI

Stop Asking Claude to Remember Everything: Build a Knowledge Assistant with RAG

Introduction Large Language Models (LLMs) have changed the way we interact with information. Tools such as Claude can explain technical concepts, generate code, analyse documents, and assist with…

  • Retrieval-Augmented Generation (RAG) combines information retrieval with AI-generated responses.
  • RAG retrieves relevant information from an external knowledge base before generating an answer.

LLM API Context Window Cost Surcharge: The Hidden Multiplier That Breaks Every Price Comparison

Everyone knows GPT-5.6 Luna costs $0.20 per million input tokens and Claude Sonnet 5 costs $2. But push a 400K-token retrieval request through Luna, and the LLM API context window cost surcharge kicks…

  • Hidden context window cost surcharge doubles input cost beyond ~272K tokens.
  • OpenAI GPT-5.6 Luna's surcharge: $0.40 input rate, $1.80 output rate.
  • Claude Sonnet 5 maintains flat $2 input rate regardless of context size.

More from Tuesday, 1 December 2026 →