{"slug": "claude-loops-2-context-is-the-hidden-loop", "title": "Claude Loops 2: Context Is the Hidden Loop", "summary": "Anthropic's Claude Code agent loop degrades over time as its context window accumulates stale data, turning conversation history into 'compost' rather than durable project memory. The company recommends moving repeated corrections into CLAUDE.md files as short, specific rules to prevent the loop from reasoning from a cluttered bench.", "body_md": "A clean desk does not make you smarter, but it makes the next decision easier. Claude works the same way. The model may be strong, the tools may be correct, and the prompt may be clear. If the active context is crowded with stale evidence, the loop starts reasoning from a messy bench.\n\nWhy can a Claude Code session feel sharp for one hour and oddly confused in the next?\n\nBecause the loop is not running inside empty space. It is running inside a context window.\n\nAnthropic’s Claude Code docs describe that window as the place where session history, file contents, command outputs, CLAUDE.md, auto memory, loaded skills, and system instructions all live while you work. That is a lot of material. Some of it is precious. Some of it is yesterday’s debris wearing a hard hat.\n\nPart 1 of this series was about the basic agent loop: observe, act, inspect, repeat. Part 2 is about the thing that quietly shapes every turn in that loop.\n\nContext is the loop’s working bench.\n\nClaude does not only need more context; it needs the right context close enough to matter.\n\nWhy does this distinction matter so much?\n\nBecause people use the word memory for everything, and that makes Claude Code harder to operate.\n\nClaude Code has persistent instruction and memory systems. CLAUDE.md files carry project, user, or organization instructions across sessions. Auto memory can store learnings based on your corrections and preferences. The docs are careful about the boundary: Claude treats these as context, not enforced configuration.\n\nThat last phrase matters.\n\nIf you write “always use pnpm” in memory, Claude is more likely to use pnpm. If you need to block a risky action, you need permissions or hooks. Memory nudges behavior. Configuration constrains behavior.\n\nThe practical model is simple:\n\nThe failure mode is using conversation history as if it were durable project memory.\n\nIt is not. It is compost.\n\nWhat actually enters the active context during a session?\n\nMore than the visible chat.\n\nThe context window can include startup instructions, memory, MCP tool names, skill descriptions, file reads, command output, rules that load when matching files are touched, hook results, and Claude’s own prior responses. The longer the session runs, the more the bench accumulates.\n\nThis is useful at first. Claude needs evidence. A failing stack trace belongs in the window. The file that defines the broken parser belongs in the window. The test command and its output belong in the window.\n\nThen the same mechanism starts to work against you.\n\nOld theories stay nearby. Unrelated file reads stay nearby. A side question about deployment can sit next to an auth refactor. Three abandoned attempts at the fix can become part of the next turn’s briefing.\n\nThat is how a good loop starts dragging its own history.\n\nWhen should something move out of chat and into project instructions?\n\nWhen you would hate explaining it again.\n\nThe Claude Code memory docs recommend adding to CLAUDE.md when Claude makes the same mistake twice, when code review catches something Claude should have known, when you repeat the same correction across sessions, or when a teammate would need the same context to be productive.\n\nThat is the right threshold.\n\nCLAUDE.md is not a diary. It is not where you paste every quirk you have ever noticed. It should be short, specific, and boring in the best way.\n\nGood memory entry:\n\n**md**\n\n```\nUse pnpm for package scripts. Do not use npm in this repo.\n```\n\nBetter project rule:\n\n**md**\n\n```\nBefore editing auth code, run pnpm test -- auth.Preserve UTC handling in token expiry tests.\n```\n\nBad project rule:\n\n**md**\n\n```\nBe careful with auth because we had a weird issue last week and the testswere flaky and maybe timezone related but also maybe not.\n```\n\nThe first two help the loop. The last one makes the loop inherit your fog.\n\nWhy is /compact not just an emergency button?\n\nBecause compaction is a handoff between versions of the same session.\n\nClaude Code can compact automatically as context approaches the limit, but the docs also recommend focused compaction when you want more control. A command like /compact focus on the API changes tells Claude what must survive the summary.\n\nThat is the move to use when the task changes shape.\n\nYou explored the bug. Now you are implementing. Compact.\n\nYou implemented. Now you are writing tests. Compact with the modified files and commands preserved.\n\nYou finished the fix. Now you are drafting the PR explanation. Compact around decisions, risk, and verification.\n\nThe trick is not waiting until the window is almost full. The trick is compacting at phase boundaries while the important signal is still obvious.\n\nWhen should you use /clear instead of /compact?\n\nWhen the next task does not need the last task’s history.\n\nThe best-practices docs are direct here: run /clear between unrelated tasks. They also note that a clean session with a better prompt can outperform a long session full of accumulated corrections.\n\nThat is emotionally annoying, because long sessions feel like momentum. You have been working. Claude has seen things. The chat has a story.\n\nBut here’s the thing: the story may be the problem.\n\nIf Claude has spent ninety minutes failing at a migration, the next prompt is not starting from neutral ground. It is starting from a pile of failed attempts, half-read files, and assumptions that may no longer be useful.\n\nClear is not defeat. Clear is hygiene.\n\nWhat should happen to a quick aside that does not belong in the main task?\n\nIt should not become part of the loop’s memory just because you were curious.\n\nClaude Code’s command docs describe /btw as a way to ask a quick aside that should not add to conversation history. That is exactly the right instinct for context hygiene.\n\nUse it for small checks:\n\nIf the answer matters to the task, bring it back deliberately. If it was just a side check, let it stay outside the working bench.\n\nSmall leaks become big clutter.\n\nWhen should you move work out of the main window entirely?\n\nWhen the main session needs the conclusion, not the full search path.\n\nClaude Code’s context-window docs point out that subagents can handle large reads in their own separate context window, returning a summary and metadata instead of dumping every file into the parent conversation. The skills docs describe the same idea with context: fork, where a skill can run in an isolated subagent without your conversation history.\n\nThis is one of the most important patterns for long Claude sessions.\n\nDo not make your main loop read everything when a research loop can read everything and return the useful part.\n\nMain loop:\n\nResearch loop:\n\nThis is not just about token cost. It is about attention.\n\nWhy do people misdiagnose context problems?\n\nBecause context rot feels like intelligence failure from the outside.\n\nClaude repeats an old assumption. It edits the wrong file. It forgets the latest decision. It overweights a log from twenty turns ago. It explains a plan beautifully and then acts on the previous plan.\n\nThe easy reaction is “the model got worse.”\n\nSometimes, sure. But often the model is doing exactly what you asked in the messiest possible room. It is trying to infer the current task from a mixture of live evidence, dead evidence, project rules, old corrections, and nearby conversation.\n\nAnthropic’s context engineering article makes the broader point: agent work is no longer only prompt engineering. The system has to curate and maintain the whole token state the model sees across turns.\n\nThat is why context is the hidden loop.\n\nEvery turn creates more context. Every next turn consumes that context. If you never curate the loop, the loop curates itself badly.\n\nHow should you ask Claude when you want the context managed on purpose?\n\nWrite the context behavior into the request.\n\nWeak request:\n\n**Code**\n\n```\nHelp me finish this feature.\n```\n\nBetter request:\n\n**Code**\n\n```\nFirst run /context mentally by listing what information you need and whatis probably stale. Read only the files needed for the next step. If the taskchanges from exploration to implementation, ask me before compacting.\n```\n\nFor command-line work, you can be even more direct:\n\n**Code**\n\n```\nInspect the current context. If old migration logs are no longer relevant,summarize the current auth bug state, then continue from that summary.\n```\n\nThe point is not to micromanage every token. The point is to make context maintenance part of the job.\n\nThat is the second loop:\n\nPart 3 will move from context to tools: how to decide which tools Claude should see, when to hide tools, and why a messy tool surface can be just as damaging as a messy context window.\n\nUntil then…\n\n— Sage 🍓\n\n*PS: Before your next long Claude Code session, write down one sentence: “What should stay in context when this task changes phases?” That sentence will make your compaction better.*\n\n[Claude Loops 2: Context Is the Hidden Loop](https://pub.towardsai.net/claude-loops-2-context-is-the-hidden-loop-417c6d646807) was originally published in [Towards AI](https://pub.towardsai.net) on Medium, where people are continuing the conversation by highlighting and responding to this story.", "url": "https://wpnews.pro/news/claude-loops-2-context-is-the-hidden-loop", "canonical_source": "https://pub.towardsai.net/claude-loops-2-context-is-the-hidden-loop-417c6d646807?source=rss----98111c9905da---4", "published_at": "2026-07-14 23:01:02+00:00", "updated_at": "2026-07-14 23:22:59.670621+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "large-language-models", "developer-tools"], "entities": ["Anthropic", "Claude Code", "Claude"], "alternates": {"html": "https://wpnews.pro/news/claude-loops-2-context-is-the-hidden-loop", "markdown": "https://wpnews.pro/news/claude-loops-2-context-is-the-hidden-loop.md", "text": "https://wpnews.pro/news/claude-loops-2-context-is-the-hidden-loop.txt", "jsonld": "https://wpnews.pro/news/claude-loops-2-context-is-the-hidden-loop.jsonld"}}