Build This Now
Build This Now
キーボードショートカットステータスラインガイド
CLAUDE.md, Skills, Subagents, Hooks: When to Use WhichClaude Code Subagents: The 3 to 5 Agent Sweet SpotCLAUDE.md Best Practices: The File That Makes Claude Code ReliableHow to Fix Claude Code Running Out of Context
speedy_devvkoen_salo
Blog/Toolkit/How to Fix Claude Code Running Out of Context

How to Fix Claude Code Running Out of Context

Claude Code running out of context is a session design problem. Fix it with /compact, lean CLAUDE.md, skills, and subagents, not a bigger window.

設定をやめて、構築を始めよう。

AIオーケストレーション付きSaaSビルダーテンプレート。

Published Jun 22, 20268 min readToolkit hub

Claude Code runs out of context because every file it reads, every command it runs, and every tool result it sees piles into one shared memory buffer for the session, and that buffer fills whether you notice or not. The durable fix is not a bigger window. It is designing the session so that buildup never spirals: run /compact early, keep your CLAUDE.md short, load knowledge through skills, and push file-heavy work into subagents that have their own separate memory.


設定をやめて、構築を始めよう。

AIオーケストレーション付きSaaSビルダーテンプレート。


Why this matters to you

If Claude Code keeps forgetting what you told it ten minutes ago, you lose time re-explaining and you get worse code. The cause is mechanical, not mysterious. Once you understand what eats the window, you can stop the bleeding with a few habits that cost almost nothing.

What actually fills the context window

The context window is the total amount of text Claude can hold in mind at once, measured in tokens (a token is roughly three-quarters of a word). People assume chat messages fill it. They do not, at least not mostly.

What fills it is everything else:

  • File reads. Open a 600-line file and all 600 lines sit in the window.
  • Tool outputs. A test run, a build log, a long grep result: all of it stays.
  • Command results. Every ls, every diff, every stack trace adds up.

There is no selective memory. Claude Code keeps one flat buffer per session. It cannot quietly drop the file it no longer needs and keep the function you care about. The window just fills, silently, with every tool call. That is why a long session feels sharp at the start and foggy by the end.

The auto-compaction mechanic, stated honestly

Claude Code has a built-in cleanup step called auto-compaction. When the session gets near full, it summarizes older content to make room. Reported behavior from the community and Anthropic docs: it triggers at about 83.5% of the window used, and it reserves a fixed 33,000-token buffer for the summary work.

Two practical notes:

  1. Do not wait for auto-compaction. Run the /compact command yourself at around 60% usage, not 95%. Early compaction keeps a cleaner summary because there is less junk to compress.
  2. There is a reported edge case (GitHub issue #25620) where a window that is already completely full can block /compact from running at all. If you let it max out, you may have to start fresh. Another reason to compact early.

Does the 1 million token window fix it?

Claude Code reached general availability of a 1 million token context window on March 13, 2026, with flat per-token pricing and no beta headers required. That is a lot of headroom. It still does not fix the root cause.

Two reasons. First, attention dilution: when you load files Claude does not need, the quality of its answers drops across the whole window, even the parts that matter. More irrelevant text means more noise. Second, modern multi-agent builds can burn through a million tokens fast if you let them run without limits. A bigger bucket fills slower, but an unbounded process still empties it.

In short: window size buys time. Architecture buys reliability.

CLAUDE.md is prime real estate, so keep it lean

CLAUDE.md is the instructions file Claude Code reads at the start of every session. It is loaded into the window every single time, so every line is a budget item.

Keep it under roughly 200 lines. Past a density threshold, rules start getting ignored. The Chroma 2025 context-rot benchmark (reported) found model accuracy falling from about 95% to about 60% as the amount of loaded context grew past a point. A bloated CLAUDE.md does not just waste tokens. It makes Claude follow your rules worse. Cut it to the rules that actually change behavior.

Skills load knowledge only when needed

A skill is a packaged set of instructions for one domain, for example "how we write database migrations." Skills use progressive disclosure: at startup Claude scans only a short summary of each skill (about 100 tokens), and it loads the full body only when the task matches. This is the clean way to give Claude deep domain knowledge without parking all of it in the window from the first message. Knowledge sits on the shelf until it is the right moment.

Subagents have their own separate memory

A subagent is a second instance of Claude that runs in its own isolated context window and reports back only a short summary to the main session. This is the correct fix for "infinite exploration" jobs, like reading a few hundred files to find where something is defined. The subagent does the messy reading in its own window, and your main session receives a clean answer instead of a thousand lines of raw files. Claude Code subagents are how you keep big searches from drowning your main context.

Dynamic Workflows: the design-level ceiling

Dynamic Workflows (released May 28, 2026, announced June 2, 2026) lets a lead agent fan work across up to 1,000 subagents, with about 16 running at once and the rest queued, using building blocks named agent(), parallel(), and pipeline(). Each subagent gets its own clean window. This inverts the problem. Instead of nursing one giant context and hoping it lasts, you design a pipeline where no single agent ever accumulates too much. Context stops being a resource you ration and becomes a decision you make up front.

Context fix methods: when to reach for each

MethodWhat it fixesWhen to use itEffortApprox. token savingsLimitation to know
/compactBloated mid-session bufferAt ~60% usage, not 95%LowHighCan be blocked if window is 100% full
.claudeignoreReads of files you never needRepos with large build or vendor foldersLowMediumOnly stops reads, not other output
CLAUDE.md trimmingPer-session fixed overheadWhen rules get ignoredLowMediumCutting too much loses useful guidance
Skills (progressive disclosure)Domain knowledge bloatRecurring specialized tasksMediumHighNeeds upfront authoring
SubagentsFile-heavy explorationReading hundreds of filesMediumVery highSummary may omit a detail you wanted
Dynamic WorkflowsWhole-build context limitsLarge multi-step buildsHighVery highMore moving parts to design and debug

A simple routine that works

  1. Trim CLAUDE.md to the rules that change behavior. Stay under 200 lines.
  2. Add a .claudeignore for build output, lockfiles, and vendor folders.
  3. Move recurring know-how into skills so it loads only on match.
  4. Send "go read everything" tasks to subagents.
  5. Run /compact at around 60%, before the window is tight.
  6. For large builds, design a Dynamic Workflow instead of one long session.

If you want this wired up for you, the Build This Now Code Kit ($29 one-time) ships a ready-made Claude Code harness: a lean CLAUDE.md, scoped skills, subagents, and a production SaaS skeleton with auth, Stripe payments, and PostgreSQL row-level security on every table. It is built around these context habits so you start clean.

FAQ

Why does Claude Code keep forgetting things mid-task?

Claude Code holds everything (file reads, command outputs, tool results) in one flat context window. When that window fills, earlier content is either compacted into a summary or lost. It is not selective memory. It is a single buffer that drains with every tool call.

How do I stop Claude Code from running out of context?

Run the /compact command at around 60% usage instead of waiting for 95%, keep CLAUDE.md under 200 lines, use skills to load domain knowledge only when needed, and delegate file-heavy subtasks to subagents so their reads never touch your main window.

Does the 1 million token context window fix Claude Code context problems?

The 1 million token window buys more headroom but does not fix the root cause. Loading irrelevant files dilutes attention quality across the whole window, and large multi-agent builds can still exhaust 1 million tokens if sessions run unbounded. Session architecture matters more than window size.

What is Claude Code Dynamic Workflows and does it help with context limits?

Dynamic Workflows (released May 28, 2026) lets a lead agent fan work across up to 1,000 isolated subagents, each with its own clean context window. It inverts the problem: instead of managing one giant context, you design a pipeline where no single agent accumulates too much.

More in Toolkit

  • CLAUDE.md, Skills, Subagents, Hooks: When to Use Which
    Claude Code skills vs subagents vs hooks vs CLAUDE.md: a plain mental model for picking the right primitive, with token costs and examples.
  • Claude Code Subagents: The 3 to 5 Agent Sweet Spot
    Claude code subagents work best at 3-5 concurrent agents. Here is why that ceiling exists, how to set them up, and what to use past it.
  • CLAUDE.md Best Practices: The File That Makes Claude Code Reliable
    CLAUDE.md best practices: keep it under 200 lines, write it by hand, and use hooks when you need real enforcement, not advice.
  • キーボードショートカット
    Claude Codeのkeybindings.jsonを設定する: 17のコンテキスト、キーストローク構文、コードシーケンス、修飾キーの組み合わせ、デフォルトショートカットを即座に無効化する方法。
  • ステータスラインガイド
    Claude Code のステータスラインにモデル名、gitブランチ、セッションコスト、コンテキスト使用量を表示する方法。settings.json の設定、JSON入力、bash、Python、Node.js スクリプトを解説。
  • AIによるSEOとGEO最適化
    Generative Engine Optimizationの解説: Googleで上位表示されるだけでなく、ChatGPT、Claude、Perplexityの回答内でコンテンツが引用されるようにする方法。

設定をやめて、構築を始めよう。

AIオーケストレーション付きSaaSビルダーテンプレート。

CLAUDE.md Best Practices: The File That Makes Claude Code Reliable

CLAUDE.md best practices: keep it under 200 lines, write it by hand, and use hooks when you need real enforcement, not advice.

On this page

Why this matters to you
What actually fills the context window
The auto-compaction mechanic, stated honestly
Does the 1 million token window fix it?
CLAUDE.md is prime real estate, so keep it lean
Skills load knowledge only when needed
Subagents have their own separate memory
Dynamic Workflows: the design-level ceiling
Context fix methods: when to reach for each
A simple routine that works
FAQ
Why does Claude Code keep forgetting things mid-task?
How do I stop Claude Code from running out of context?
Does the 1 million token context window fix Claude Code context problems?
What is Claude Code Dynamic Workflows and does it help with context limits?

設定をやめて、構築を始めよう。

AIオーケストレーション付きSaaSビルダーテンプレート。