Single logo
  • Courses
  • Blog
  • About
Join free on SkoolJoin free on Skool

In this topic

Claude
  • CLAUDE.md, settings.json and Plugins: Which Claude Code File Advises, Which Enforces, Which Packages
  • Authoring a Claude Skill: SKILL.md, Frontmatter, Progressive Disclosure and the Description That Triggers It
  • One Change, Four Environments: Where a Claude Config Edit Lands in Dev, Staging, Prod and CI
  • Claude in the SDLC: Prompts in Git, a Change Gate by Path, a Claude Review That Advises and a Person Who Merges
  • Hooks That Block Destructive Actions: a PreToolUse Gate That Allows, Asks or Denies
  • Choosing a Claude Code Extension: Skill, Hook, Rules File, Subagent, Slash Command or Plugin
  • Rolling Out Claude Code to a Team: Settings Precedence, dontAsk in CI, a Hook for Every-Time Rules and a Plugin for Five Repos
  • A Claude Code Review Bot in CI: Headless -p, JSON Findings, Team Rules in Git and a Person on the Merge
  • Lab: Three Planted Bugs in a Claude Code CI Repo, a Permission Mode, a Plugin Path and an MCP Token Variable
  • Configuring MCP Servers in Claude Code: A Command or a URL, Three Scopes, and Three Moves When One Breaks
  • The Claude Messages API: Your First Call, Field by Field
  • Claude Tool Use: How tool_use and tool_result Work in the Messages API
  • Claude Client SDKs Wrap One REST API: Raw HTTP, Python, TypeScript and Async Calls Compared
  • Anthropic SDK Timeouts, Retries and Error Classes: Configure the Client Once, Then Give 429, 529, 400 and Timeouts Their Own Move
  • Claude Streaming Events: The Event Order, message_stop, Tool Arguments, Stop Reasons and a WebSocket Relay
  • Images, PDFs and Thinking Blocks in the Claude Messages API: Typed Blocks In, Typed Blocks Out
  • Getting Data Into Claude: PDF Documents, the Files API, Search Results and Citations
  • Opus, Sonnet or Haiku: Pick the Claude Model per Job, and Test the Request When a New Release Arrives
  • Adaptive Thinking and Effort in Claude: Two Dials, Set per Workload, and the Thinking Block You Must Pass Back
  • Claude Cost Tracking From usage: Count Before, Cap During, Read After, Then Find the Line That Drives the Bill
  • Claude Cache Breakpoints: Where to Put cache_control, How to Move It With the Chat, and Why the Reads Stay at Zero
  • Claude Message Batches or Real Time: Choose by Who Is Waiting, Match by custom_id, Resend Only the Failures
  • Calling Claude Through Amazon Bedrock, Google Cloud and Microsoft Foundry: Same Call, Different Door
  • The Life Cycle of a Claude App: Six Phases, a Model That Retires, and a Release Gate for Every Change
  • Pinning Claude Model IDs and Upgrading Safely: One Change at a Time, a Golden-Set Replay and a Staged Rollout
  • Content Boundaries and Schema Design for Claude: Fence the Input in a Tag, Let the Output Say I Don't Know
  • The Agentic Loop and stop_reason: Keep Turning on tool_use, Stop on end_turn, Cap the Turns
  • The Claude Agent SDK: query(), ClaudeAgentOptions and @tool, in Python and TypeScript
  • Fix the Agent: Four Broken Claude Agent SDK Configs, From the Symptom to the One Wrong Line
  • Claude Managed Agents: Cloud Sandbox, Self-Hosted Sandbox or Self-Hosted Service
  • Agent SDK Hooks for Deterministic Actions: PreToolUse, PostToolUse, and Four Hooks That Fail Silently
  • Memory and Context-Window Patterns for Claude Agents: Context Editing, Compaction and the Memory Tool
  • Reading an Agent Trace: Five Signatures, Five Missing Patterns, and How Long a Fact Must Live
  • Tool Descriptions for Claude: How Claude Picks a Tool, and How to Stop It Picking the Wrong One
  • Tool Input Schemas and Error Responses for Claude: Required Fields, Enums, is_error and a Retry Flag
  • Tool Response Shaping and a Lean Tool Set: Give Claude a Sticky Note, Not the Filing Cabinet
  • Fix the Tool Schema: Read the Trace, Fix the Card, Re-Run (Four Real Schema Bugs)
  • Client Tools, Server Tools and Approval Gates: Who Runs the Tool, and Who Says Yes First
  • Built-in Tool, Custom Tool, Skill or MCP Server? Pick the Lightest One That Fits
  • System Prompt or User Turn: Where Each Instruction Goes, and Output Limits Your Code Enforces
  • Refine the Prompt One Line at a Time, Then Clean and Fence the Customer's Text
  • Prompt Revision Driven by Evals: Name the Cause, Change One Thing, Rerun the Whole Suite
  • Long-Running Sessions: Compact, Prune, Isolate or Start Fresh, Decided by Naming the Failure
  • Context Isolation Through Subagents: Read the Logs Elsewhere, Keep One Line
  • Defensive Parsing of Claude Replies: Check the Stop Reason, Read the Block or the Text, Then Validate the Values
  • Full Context or Retrieval: Choose by Corpus Size, Cost and Freshness
  • Skepticism Toward Confident Output: Check the Quote, the Record and the Sum Before You Send
  • Debugging a Claude App: Three Error Types, the Recovery Each One Earns, and the First Failing Row
  • Six Ways a 200 Can Still Be Wrong: Hallucination, Refusal, Under-Acting, Context Loss, Format Drift and Inconsistency
  • Fix the Cause, Not the Symptom: Four Recovery Drills for an LLM App, Each Checked on a New Input
  • Integration Layer or Model Output? Three Taps and Three Questions to Find Where a Wrong Answer Lives
  • Which Test Layer Owns the Failure? Unit, Functional, Integration and End-to-End Tests for a Claude App
  • Designing an Overnight Document Pipeline on Claude: Batch Lane, Live Lane, a Cached Prefix and a custom_id Reconcile
  • Proving a Model Upgrade Is Ready: A Frozen Golden Set, a Calibrated Judge, the Right Layer and a Release Gate
  • From Requirement to Design for a Claude App: Eight Requirements, Five Elements and a Trace With No Gaps
  • Build a Claude Refund App: the Messages API, Two Tools, an MCP Server and a Hook in One Loop
  • Ship a Claude App: an Eval Gate, Two Guardrail Layers, a Cost Check From usage and a Pinned Model
  • Lab: a 30-Case Golden Set, a Calibrated Judge and a Per-Slice CI Gate on a Claude Refund App
  • Lab: Cut a Claude App's Bill by 62 Percent With Usage Data, Layered Cache Breakpoints and a Batch Job
  • Lab: Three Planted Bugs in a Claude App, a Vague Prompt, a Mistyped Tool Schema and a Broken Stream Handler
  • Lab: Three Planted Bugs in a Claude Code CI Repo, a Permission Mode, a Plugin Path and an MCP Token Variable
  • Lab: Harden a Claude App, an Uncalibrated Judge, a Retry Loop That Retries Everything and a Hook Matcher With a Gap
  • Lab: Turn a Claude App Into a Reusable Template, One Pinned Model Id, No Key in Code and Evals Built From Data
  • Building an MCP Server: Tools, Resources and Prompts in Python and TypeScript
  • MCP Transports: stdio or Streamable HTTP, and Who Starts the Server
  • Deploying and Authenticating an MCP Server: Environment Keys for stdio, Bearer Tokens and Scopes for HTTP
  1. Blog
  2. /
  3. Claude
  4. /
  5. Building with the Claude API

Context Isolation Through Subagents: Read the Logs Elsewhere, Keep One Line

Three log files hold the cause of a failed checkout. Read inline, the main context holds 6,828 characters; delegated to subagents with a one-line brief, it holds 283, with the same answer.

Chaand Sheikh

·27 November 2026Building with the Claude API

What you will learn

  • Explain why every file read inline stays in the main context for every later step
  • Delegate each file to a subagent call with a brief that asks for one short line
  • Spot a leaky brief that hands the whole file back
  • Name the three costs of isolation and the workflow alternative

Before you start

  • The Claude Messages API: your first call
  • Context engineering: what belongs in the context window

A checkout failed last night, and the main agent has to find out why. Three long log files hold the answer. Read them all in one place and they bury the question. In this article a subagent does the reading in its own context and brings back one line.

Three files, 6,828 characters of context

When the main agent reads everything itself, the question goes in first, a thin sliver. Then checkout.log, about 2,300 characters. Then gateway.log, and it stays there. Then payments.log. The context now holds 6,828 characters, and the one useful line is buried somewhere in it.

The key point: every file you read stays in the main context for every step after it.

A manager who sends an intern

A manager has a question about three filing cabinets. Instead of reading them, the manager sends an intern with the question. The intern reads all three cabinets, 144 lines, in the intern's own room. The manager's desk stays clear. Back comes a one-page note: payments timed out. The reading stays in the intern's room.

Each subagent reads in its own window main context the question + three short replies 283 chars subagent: checkout.log read 2,290, returned 76 subagent: gateway.log read 2,233, returned 67 subagent: payments.log read 2,266, returned 60 brief out, one line back
The long reading happens in each subagent's own context. Only the final reply comes back. Sizes are characters counted by the code, not tokens.

brief.txt: the reply is the product

A subagent starts with nothing. It doesn't see the main chat, so the brief is its whole set of instructions:

You read one log file for a failed checkout.
Reply in one line: how many ERROR lines, and the first one with its line number.
Do not copy any other line of the file.

A role, one job, the exact shape of the reply, and a rule against copying the file back. Asking for the line number matters: it lets the main agent look closer later if it needs to.

desk.py: ask and delegate

The project uses the Anthropic SDK with a scripted stand-in on a mock transport, so no key is needed. The stand-in reads only what's in the one request it receives, which is exactly the isolation we want to show. The parts that matter:

QUESTION = "Why did checkout fail last night?"
MAIN = "You find the cause of a failed checkout from the notes you are given."


def ask(system, content):
    """One call. The model sees only this system prompt and this content."""
    reply = client.messages.create(
        model="claude-sonnet-5-5", max_tokens=1000, system=system,
        messages=[{"role": "user", "content": content}])
    return reply.content[0].text


def inline():
    """The main context reads every file itself."""
    context = "\n\n".join([QUESTION] + [f.read_text() for f in LOGS])
    return ask(MAIN, context), len(context)


def delegate(brief_file):
    """One subagent per file. Only its reply reaches the main context."""
    brief = (HERE / brief_file).read_text()
    notes = [QUESTION]
    for log in LOGS:
        text = log.read_text()
        reply = ask(brief, text)              # its own, fresh context
        print(f"  {log.name:13}read {len(text):,} chars, returned {len(reply):,}")
        print(f"    {reply.splitlines()[0][:78]}")
        notes.append(f"{log.name}: {reply}")
    context = "\n\n".join(notes)
    return ask(MAIN, context), len(context)

A subagent here is simply a separate call with its own system prompt (the brief) and its own content (one file). The whole file goes to the subagent and never into notes. Only the reply is appended.

Same question, two ways

inline: main context 6,828 chars -> Cause: card-vault timeouts in payments.
delegated with brief.txt:
  checkout.log read 2,290 chars, returned 76
    3 ERROR lines, first at line 10: checkout order 4411 payment failed: timeout
  gateway.log  read 2,233 chars, returned 67
    2 ERROR lines, first at line 13: gateway 502 from payments, retry 1
  payments.log read 2,266 chars, returned 60
    5 ERROR lines, first at line 11: payments card-vault timeout
delegated: main context 283 chars -> Cause: card-vault timeouts in payments.

Same answer both times: card-vault timeouts in payments. The main context went from 6,828 characters to 283, about 24 times smaller. But notice: the subagents still read every character. Isolation moves the reading out of the main context. It doesn't make the reading free.

Break it: a subagent that returns everything

Here's the leaky brief:

You read one log file for a failed checkout.
Reply with the whole file you read, so nothing is lost.
delegated with brief_leaky.txt:
  checkout.log read 2,290 chars, returned 2,290
    02:05:00 INFO  checkout cart loaded id=1000
  gateway.log  read 2,233 chars, returned 2,233
    02:05:00 INFO  gateway GET /cart 200 id=1000
  payments.log read 2,266 chars, returned 2,266
    02:05:00 INFO  payments token received id=1000
leaky brief: main context 6,869 chars -> Cause: card-vault timeouts in payments.
main context: 6,828 inline, 283 delegated, 6,869 leaky

Each subagent hands back its whole file, and the main context ends at 6,869 characters, slightly bigger than reading inline. A subagent that returns everything gives the main context nothing back. The brief is what makes isolation work.

Isolation has three costs

  1. A summary can lose detail. Ask for the file and line number, as our brief does, so the main agent can look closer.
  2. The subagent starts with nothing. Put everything it needs in the brief; it inherits no chat history.
  3. Replies still add up. Many subagents with long replies fill the main context again.

A workflow isolates too

There's a second route, with no subagent at all: a multi-step workflow. Step one extracts the error lines from one file. Step two decides the likely cause from step one's output only. Step three writes a note for the on-call team from step two's output. Step three never sees the raw log. Each step's context holds one short piece. Both routes do the same job: something reads elsewhere, and only a short result comes back.

When the question is which fix a long session needs (prune, compact, isolate or start fresh), see long-running sessions.

Recap

SetupMain contextAnswer
Read inline6,828 charscard-vault timeouts
Subagents, one-line brief283 charscard-vault timeouts
Subagents, leaky brief6,869 charscard-vault timeouts

When big tool or file output bloats the context, pick isolation: a subagent or a separate step that returns a short result. A bigger model or a longer window doesn't fix it.

Keep going in Claude · 44 of 66

Previous
Long-Running Sessions: Compact, Prune, Isolate or Start Fresh, Decided by Naming the Failure
Next post
Defensive Parsing of Claude Replies: Check the Stop Reason, Read the Block or the Text, Then Validate the Values
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

Claude Certified Developer - Foundations (CCDV-F) Exam Prep

Build and ship Claude apps: the API, agents, tools and MCP, prompts, evals, security and model choice.View on Udemy ↗: Claude Certified Developer - Foundations (CCDV-F) Exam Prep (paid course, opens in a new tab)

Related posts

The Claude Messages API: Your First Call, Field by Field

One request in, one Message out. The four fields of a Messages API call (model, max_tokens, system, messages), how to read content blocks, stop_reason and usage, and why every turn resends the history.

Claude Tool Use: How tool_use and tool_result Work in the Messages API

Follow one order question through Claude's tool round trip: define a tool, read the tool_use block, run your own function and send a matching tool_result back, including parallel calls and is_error.

Claude Client SDKs Wrap One REST API: Raw HTTP, Python, TypeScript and Async Calls Compared

Every Claude client SDK wraps the same REST request: a POST to /v1/messages with a JSON body. See it built by hand, through the Python and TypeScript SDKs, as typed errors, and as async calls that wait together.

Anthropic SDK Timeouts, Retries and Error Classes: Configure the Client Once, Then Give 429, 529, 400 and Timeouts Their Own Move

Configure the Anthropic SDK client (timeout, max_retries, with_options, async, pagination), see which errors it retries by itself, then repair a retry wrapper so a 429, a 529, a 400 and a timeout each get the move the docs support.

On this page

  • Three files, 6,828 characters of context
  • A manager who sends an intern
  • brief.txt: the reply is the product
  • desk.py: ask and delegate
  • Same question, two ways
  • Break it: a subagent that returns everything
  • Isolation has three costs
  • A workflow isolates too
  • Recap
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

Related course on Udemy

Claude Certified Developer - Foundations (CCDV-F) Exam Prep

Build and ship Claude apps: the API, agents, tools and MCP, prompts, evals, security and model choice.View on Udemy ↗: Claude Certified Developer - Foundations (CCDV-F) Exam Prep (paid course, opens in a new tab)

Single logo

Empowering Education, One Course at a Time

About
About usContact usFAQs
Legal
Terms of ServicePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.