How Claude Code Works: The Agentic Loop, Explained
Claude Code is an agentic coding tool, not a chat window. It runs a loop — gather context, take action, verify the result — repeating until the work is done and verifiable. It manages a context window (compacting it when full), uses tools to take real actions, and gives you permission modes to control how much it does on its own.
We know Claude Code is different from a usual chat application — but how does it actually work? The clearest way to understand it is through the agentic loop, the cycle it runs for every task. Below we break down that loop, the context window, tools, and permission modes, so Claude Code stops feeling like a magic box. There's also a fully interactive version further down the page, with the official video synced clip-by-clip to each concept.
What is the agentic loop in Claude Code?
The agentic loop is how Claude Code works. You enter a prompt; it gathers the context needed to complete that prompt, takes an action, then verifies whether the result met your goal. If it did, it stops and waits for you. If it didn't, it runs the loop again until the result is complete and verifiable.
Concretely, the loop has four repeating stages:
- Prompt. You describe what you want in plain language. That prompt is the goal the whole loop works toward.
- Gather context. Claude Code interacts with the model, which returns text or a tool call it can execute, and uses that to pull in the context the prompt needs.
- Take action. It takes a real action — such as editing a file or running a command — on your actual project.
- Verify. It checks the result against your prompt. If the goal is met it stops; if not, it loops back and runs again until the result is complete and verifiable.
▶ Watch this part of the video0:13–0:52
Can you steer Claude Code while it runs?
Yes. Throughout the loop you stay in control: you can add context at any point, interrupt the run, or steer the model to guide it toward your end goal. You are never locked out while Claude Code is working — if it starts heading the wrong way, you can redirect it before it goes further.
What is the context window, and how does compaction work?
The context window determines how much of your conversation, file contents, command outputs, and more Claude Code can store and look back on. When you reach that limit, Claude Code compacts the conversation — automatically deciding what to remove and what to summarize — to bring the context window back down so work can continue.
In other words, you don't have to manually manage memory. As a session grows long, compaction keeps the most useful context and summarizes the rest, so the conversation keeps going instead of hitting a wall.
▶ Watch this part of the video1:03–1:26
What are tools in Claude Code?
Tools are the backbone of how agents work. Most AI assistants only take text in and put text out, with nothing in between. Tools let Claude Code take real action — such as reading a file, searching the web, or running a command — and it uses semantic search to determine when to call a tool and use its output.
That middle step — deciding to act, then acting — is what separates an agent from a plain assistant. A few common tools:
- read_file — pull in exactly the code it needs to reason about.
- search_web — reach for current information beyond the codebase.
- run_command — execute tests, builds, or git, taking real actions on your project.
▶ Watch this part of the video1:26–1:52
What are Claude Code's permission modes?
Permission modes control how much Claude Code does on its own, and you toggle between them with Shift+Tab. Each mode trades a little safety for a little speed:
- Default. Claude Code asks explicit permission before editing a file or running a shell command. Nothing happens without your yes.
- Auto-accept edits. It edits files without asking so it keeps moving, but still asks before running commands.
- Plan mode. It uses read-only tools to compile a plan of action before starting, so you review the approach with no risk of a premature change.
▶ Watch this part of the video1:52–2:15
Is it safe to skip permissions in Claude Code?
Be cautious when skipping permissions. Giving Claude Code free rein to run commands means a mistake could be harder to catch before it happens, so weigh the speed against the risk for each task. A moment of review is cheap insurance.
What makes Claude Code different from a chat window?
Claude Code combines several agentic concepts — an agentic loop, a managed context window, tools, and configurable permissions — inside your terminal. It can read your codebase, take action, and verify its own work, and that is what makes it fundamentally different from a chat window.
Key takeaways
- Claude Code runs an agentic loop: gather context → take action → verify → repeat until the result meets your prompt.
- You can steer the loop at any time — add context, interrupt it, or redirect it toward your goal.
- The context window stores your conversation, files, and command outputs; when it fills up, Claude Code compacts it automatically.
- Tools let Claude Code take real action (read a file, search the web, run a command), chosen via semantic search.
- Permission modes — toggled with Shift+Tab — control whether Claude asks before editing files or running commands.
Frequently asked questions
When Claude Code hits the context limit, what happens?
It compacts the conversation — automatically summarizing and dropping what it can to free up room — so the conversation can keep going.
How do you make Claude Code plan an approach before it edits anything?
Use plan mode. It uses read-only tools to compile a plan of action before starting, so you can review the approach with no risk of a premature change. Toggle to it with Shift+Tab.
Does Claude Code ask before changing files?
By default, yes. Claude Code asks explicit permission before editing a file or running a shell command. You can change this with permission modes using Shift+Tab.
How does Claude Code decide which tool to use?
It uses semantic search to determine when to call a tool — such as a read-file tool or a search-web tool — and to use the output of that tool.