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-04-27Advanced

Claude Code Context Window Mastery — 7 Production Patterns to Stop Sessions From Stalling

Most slowdowns and silent quality drops in Claude Code on large repos come from context window management, not from model limits. This guide walks through seven patterns I rely on in production, with measurement scripts and runtime rules.

claude-code129context-window6token-budget3production111performance4

Premium Article

After three weeks of running Claude Code on a monorepo north of 100k lines, the thing that ate my time wasn't bugs or scope changes. It was the slow-burn problem of sessions becoming heavy. The first one or two tasks would fly. Then I'd start a cross-cutting refactor, the responses would drift slower, and at some point a /compact warning would arrive and crush the prior reasoning context. After compaction, Claude Code would burn through Glob and Read calls relearning where files lived, doubling both latency and bill.

The official documentation says "you have 200K tokens." In practice, behavior shifts somewhere around 80-100K. By 150K, the agent feels noticeably less precise, even when the model itself is unchanged. This article is the field guide I wish I had had — seven patterns I have validated across multiple projects, prioritizing tomorrow-morning rules and scripts over theory. Each pattern is small enough to adopt in isolation, and together they keep long workflows stable for weeks at a time.

Why "use the whole window" is the wrong mental model

Claude Sonnet 4.6 ships with a 200K context window, and the Opus tier offers a 500K extended variant. On paper there is plenty of headroom for any reasonable task. In production, three forces collide and the headroom evaporates quickly.

First, attention cost. Larger inputs mean heavier internal processing per turn. My rough measurements show that going from 60K to 150K input tokens roughly multiplies response time by 1.7x and cost by 2.5x — the curve is not linear in your favor. If you are paying per million input tokens, the bill grows faster than the output you receive, which makes large-window strategies economically painful even when they technically fit.

Second, cache boundary fragility. Claude's prompt caching, available in 5-minute and 1-hour tiers, hinges on prefix stability. The moment a re-read forces you to drift away from the cached prefix — for example, after a /compact reshuffles the conversation history — hit rate collapses, and your cost efficiency goes with it. I have watched cache hit rates fall from 80% to under 20% in the span of one compaction cycle, simply because the new prefix no longer matched the cached one byte-for-byte.

Third, reasoning dilution. This one is hard to put on a graph but real: when irrelevant context piles up, generated patches tend to overreach. You ask for a surgical fix and get a sprawling diff that touches files you specifically did not want touched. Most of us have lived this. The model is not "wrong" — it is just trying to be helpful given the surface area you handed it. The fix is to hand it less surface area.

So context management is not about filling the window. It is about loading exactly what this turn needs and nothing else. The seven patterns below all serve that goal, and they are listed roughly in order of impact-to-effort ratio.

Pattern 1: Declare task scope at session start

The single most effective thing you can do is to bound the session in your opening message. Claude Code does not read minds, and when you give it freedom it tends to use that freedom to broaden its exploration. I keep a four-line template handy and paste it as the first message of any non-trivial session.

Scope for this session:
- Target directory: src/payments/ only
- Off-limits: src/auth/, tests/legacy/
- Done condition: stripe webhook idempotency tests are green
- Expected duration: under 30 minutes

Once the scope is articulated, Claude Code's autonomous exploration shifts to honor "expected duration" and "done condition." Glob and Grep invocations drop noticeably — by my count, around 30 percent fewer file-system probes — which prevents the early context bloat that compounds later.

The piece doing the heavy lifting here is the off-limits list. Without it, dependency analysis tends to wander into adjacent files because they look "relevant." Maybe an interface lives in src/auth/ that the payments code consumes; the agent will happily open the entire auth tree to understand the type. That helpfulness is exactly what destroys your context budget over a long session. By naming the directories you do not want explored, you let the agent infer that you have already decided their internals are not in play.

A subtle benefit: when an unanticipated need comes up — for example, the auth module turns out to genuinely need a tweak — the agent will pause and ask, rather than silently expanding scope. That single pause is worth thousands of tokens.

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
A measurement script that surfaces, in real time, the three root causes of slow, expensive, forgetful sessions
Seven production patterns — sub-agent isolation, MCP pruning, sliced reads — that keep long sessions fast
The runtime rules and weekly audit that cut average session length from 73 to 38 minutes and tokens from 145K to 71K
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-04
5 Practical Ways to Work Around Claude Code's Context Window Limit
When Claude Code warns you that the context limit is approaching on large codebases or long sessions, here are five practical approaches — from /clear and /compact to CLAUDE.md and scope splitting.
Claude Code2026-07-09
Is the Draft That Passed the Gate the Same One You Published?
In unattended pipelines, the file your quality gate inspected and the file you actually publish can quietly diverge. Here is a digest-bound gate receipt design, with working code and measured results from 180 days of running it.
Claude Code2026-07-03
Five Minutes of Silence, and Something Retries on Your Behalf — Rethinking Retry Ownership After the Streaming Idle Watchdog Became a Default
Claude Code's streaming idle watchdog is now on by default, quietly adding another retrying layer to your stack. This article inventories the four layers (SDK, wrapper, watchdog, scheduler), computes worst-case attempt amplification, and shows how to collapse retry ownership into a single layer.
📚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 →