Skip to content

Browse catalog

Search catalog

[READY] Type a title, tag, or description.

NOTES // concept

Agentic loop

LAST_MODIFIED
2026.07.29
CATEGORY
concept

The agentic loop is three phases Claude Code cycles on every task: gather context (read, search, understand), take an action (invoke a tool), verify results (check whether the action moved toward the goal). A question might only gather; a refactor loops through all three dozens of times. Each tool result feeds the next decision - that feedback is the loop.

What fills the window

Context starts filling before you type - the startup tax (system prompt, CLAUDE.md, tool names, skill descriptions, auto memory). During the loop, file reads dominate growth: each read stays in history for every subsequent turn. Path-scoped rules and nested CLAUDE.md files load when Claude reads a matching path. PostToolUse hooks can inject additionalContext via JSON.

When context drifts mid-session (~turn 30), a constraint may still be in the transcript but no longer near either edge - the lost in the middle failure. Put anything that must hold for the whole session in a file that gets re-injected (project-root CLAUDE.md, or a SessionStart hook with source: "compact"), not in a chat message.

Levers

  • Compaction / /compact - summarize history; project-root CLAUDE.md re-injects from disk.
  • /clear - hard reset of message history.
  • Subagent context isolation - heavy work in a child window, summary back to the parent.

Require the agent to read before it writes and end the task with a command that fails loudly when the target is missing - invented paths become context for everything after them.

Mechanics playbook: How Claude Code’s agentic loop fills your context window. Discipline: Context engineering.

claude-codeagentic-loopcontext

Related_Notes