CLAUDE LABJP
FORK — Claude Code 2.1.212 changes what /fork does: it copies your conversation into a new background session with its own row in claude agents, so you can keep working. The old in-session subagent is now /subtaskLIMITS — WebSearch calls are now capped at 200 per session by default, and subagent spawns get the same 200 ceiling, so a runaway search or delegation loop stops on its ownMCPBG — MCP tool calls running past two minutes now move to the background automatically, keeping the session usable. Tune the threshold with CLAUDE_CODE_MCP_AUTO_BACKGROUND_MSPLANFIX — Fixed plan mode auto-running file-modifying Bash commands such as touch and rm without a permission prompt or an SDK canUseTool callbackSONNET5 — Claude Sonnet 5 is running on introductory pricing of $2 per million input tokens and $10 per million output. After August 31 it moves to $3 and $15IPO — Bankers are reportedly lining up investor meetings for Anthropic ahead of a possible public listing as soon as OctoberFORK — Claude Code 2.1.212 changes what /fork does: it copies your conversation into a new background session with its own row in claude agents, so you can keep working. The old in-session subagent is now /subtaskLIMITS — WebSearch calls are now capped at 200 per session by default, and subagent spawns get the same 200 ceiling, so a runaway search or delegation loop stops on its ownMCPBG — MCP tool calls running past two minutes now move to the background automatically, keeping the session usable. Tune the threshold with CLAUDE_CODE_MCP_AUTO_BACKGROUND_MSPLANFIX — Fixed plan mode auto-running file-modifying Bash commands such as touch and rm without a permission prompt or an SDK canUseTool callbackSONNET5 — Claude Sonnet 5 is running on introductory pricing of $2 per million input tokens and $10 per million output. After August 31 it moves to $3 and $15IPO — Bankers are reportedly lining up investor meetings for Anthropic ahead of a possible public listing as soon as October
Articles/Claude Code
Claude Code/2026-05-25Advanced

Three State-Passing Patterns for Claude Code Subagents — Lessons from 4 Months of Automated Blog Pipelines

JSON files, environment variables, and context bundles — three ways to hand state between Claude Code subagents, compared with four months of production data and clear guidance on when to pick each.

claude-code129subagent4pipelinestatearchitecture10

Premium Article

When you start running Claude Code subagents in earnest, almost everyone hits the same wall: how do you hand state from a parent agent to a child agent? The Agent tool is stateless. The child only sees the prompt you give it. If the parent's hard-won context never crosses that boundary, the child re-discovers everything from scratch.

I'm an indie developer — I've been shipping iPhone and Android apps since 2014 (cumulative installs are now north of 50 million), and over the past few years I've been running multiple Claude-powered Lab sites in parallel. After four months of operating an automated blog generation pipeline across four sites, the question of state passing came back to bite me more times than I'd like to admit. This article distills the three patterns I kept, plus when to choose each.

Why subagent state is awkward

Claude Code's subagent model resembles a Unix subshell more than a true fork. The parent doesn't share memory with the child; it composes a prompt string and spawns a fresh session. The child has its own context window and only returns a final message when it's done.

That isolation is wonderful for safety and context hygiene. The cost is a hard ceiling on how much the parent can hand down. In my pipeline, a single-site article generation run needs to pass:

  • Slugs from the last 14 days so the child doesn't duplicate a topic
  • Recent GSC data (clicks, impressions, CTR) per article
  • Per-category article counts to keep the mix balanced
  • Ongoing real-world threads — AdMob fill rate, Crashlytics top crashes, Xcode build issues — the child can pull from
  • Cross-site exclusion lists so four sites don't all suddenly publish on the same topic

If you inline all of that into the prompt, the child wakes up with most of its context window already eaten. I measured a stretch where 12,000 of the available 30,000 tokens were spent on state alone, leaving little room for the child to write a substantive premium article.

Pattern 1: JSON file handoff (best for ~100 runs/day)

The first pattern I landed on writes state to a JSON file. The parent persists it, the child reads it back with the Read tool.

Implementation

import { writeFileSync, readFileSync, renameSync } from 'fs';
import { join } from 'path';
 
type PipelineState = {
  pipelineId: string;
  timestamp: number;
  recentSlugs: string[];
  gscData: Record<string, { clicks: number; impressions: number }>;
  excludedSlugs: string[];
  categoryBalance: Record<string, number>;
};
 
const STATE_DIR = '/tmp/claude-pipeline-state';
 
function writeState(state: PipelineState): string {
  const path = join(STATE_DIR, `${state.pipelineId}.json`);
  // Atomic write: stage to a tmp file, then rename
  const tmpPath = `${path}.tmp.${process.pid}`;
  writeFileSync(tmpPath, JSON.stringify(state, null, 2), 'utf-8');
  renameSync(tmpPath, path);
  return path;
}
 
function readState(pipelineId: string): PipelineState {
  return JSON.parse(readFileSync(join(STATE_DIR, `${pipelineId}.json`), 'utf-8'));
}
 
// Hand the child only the path, not the payload
const childPrompt = `
Before you start, Read the state from this path to avoid duplicate topics:
  ${writeState(currentState)}
 
Then choose a topic, generate the article, and write your result back to the same file.
`;

What four months told me

The end-to-end overhead per handoff was 12ms in our Linux sandbox. Token consumption for the state itself dropped from roughly 12k tokens to 4k. At Sonnet 4.6 input prices, that's about $30 in savings per month per pipeline.

Two months in I hit a sharper edge. Cowork scheduled tasks for multiple sites overlapped at one timing, and concurrent writes to the same JSON file caused one update to silently lose to the other — three times in a single week.

The fix is the rename-based atomic write shown above. On the same filesystem, Linux's rename(2) is atomic, which is enough to dissolve the race.

When to choose this

This is what I use today for the four sites generating four articles per day each. For state below 100KB and parallelism up to about four, the JSON file pattern is the lowest-friction default and what I recommend trying first.

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
Three patterns compared with working code (overhead: 12ms / 0.3ms / 380ms) so you can pick by latency budget
Real numbers from running 4 sites and 630 generated articles per month — which pattern scales to which volume
Three production failures (32KB env var limit, JSON write race, context bundle token blowup) and the fixes that stuck
Secure payment via Stripe · Cancel anytime

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • Copy-paste ready implementation code
  • New advanced guides published daily
  • $5/mo or $10 for lifetime access
View Membership →

Related Articles

Claude Code2026-05-02
Claude Code Stops Mid-Execution: Complete Diagnostic Guide
Diagnose why Claude Code freezes or stops mid-task. Covers context budget exhaustion, unresponsive subagents, infinite loops, and tool timeouts with actionable fixes for each scenario.
Claude Code2026-04-24
Diagnosing Claude Code Subagents That Stall or Never Return
Diagnostic flow for Claude Code subagents that freeze, return silently, or produce the wrong output shape — classified by symptom with runnable examples.
Claude Code2026-04-12
Claude Code Sub-agent Patterns — Designing Autonomous Task Decomposition and Parallel Execution
Dissect Claude Code's internal Sub-agent architecture and learn concrete design patterns for task decomposition, parallel execution, and result merging in your own projects.
📚RECOMMENDED BOOKS
Build a Large Language Model (From Scratch)
Sebastian Raschka
LLM Dev
Prompt Engineering for LLMs
Berryman & Ziegler
Prompting
AI Engineering
Chip Huyen
AI Eng
* Contains affiliate links
See all →