The loop, one turn at a time
Every time you send a prompt, Claude Code runs a loop that looks like this:
- Gather context. Claude reads your prompt plus everything already in the session: system instructions,
CLAUDE.md, earlier messages and tool results. - Decide. The model picks the next step: answer you, or call a tool.
- Act. If it calls a tool (read a file, run a command, edit code), Claude Code checks permissions and then runs it.
- Observe. The tool's output is added to the conversation.
- Repeat until the task is done or Claude needs you.
- ⋮⋮You send a prompt
- ⋮⋮Claude reads the context it has
- ⋮⋮The model decides on a tool call
- ⋮⋮Permissions are checked
- ⋮⋮The tool runs and its output is added to context
- ⋮⋮Claude decides: another step, or a final answer
The built-in toolbox
Claude doesn't have magic access to your machine. It has tools, and each one does one specific thing. The core set:
| Tool | What it does |
|---|---|
Read | Reads a file (text, images, PDFs, notebooks) |
Glob / Grep | Finds files by pattern and searches their contents |
Edit / Write | Changes part of a file, or writes a whole file |
Bash | Runs shell commands: tests, builds, git, package managers, any CLI |
WebFetch / WebSearch | Reads a web page or searches the web |
Agent | Hands a self-contained task to a subagent with its own context |
Skill | Loads a packaged skill's instructions when they're relevant |
On top of these you can add tools from MCP servers (Unit 6), and code intelligence plugins that give Claude real type errors and "go to definition" after each edit.
Bash is the universal adapter. If there's a CLI for it (gh, aws, psql, docker, your own scripts), Claude can use it. Before reaching for anything fancier, ask: "Is there already a command for this?"
The context window: Claude's working memory
Everything in the session (your messages, Claude's replies, every file it read, every command output) lives in the context window. It's large, but it isn't infinite, and the more it holds, the more expensive and less focused each turn becomes.
What loads automatically at the start of a session:
- Claude Code's own system instructions and tool definitions
- Your
CLAUDE.mdfiles (project, user and organization) - The names and descriptions of skills and MCP tools. Their full content loads only when needed.
What grows as you work: file reads, command output and the conversation itself. When the window gets close to full, Claude Code compacts automatically, summarizing older history to make room. You'll learn to steer that in Lesson 5 and Unit 2.
Permissions: the checkpoint inside the loop
Between "decide" and "act" sits the permission check. Reading files is safe, so it's usually allowed. Editing files or running commands may prompt you, depending on your permission mode and rules:
You can approve once, approve similar actions for the session, or say no and redirect. Press Esc at any time to interrupt Claude mid-turn. The work done so far is kept, and you can steer from there.
What do you type inside Claude Code to see how full the context window is?
Check your understanding
In the agentic loop, what happens right before a tool runs?
Which tool lets Claude use almost any command-line program?
What loads into context automatically at session start?
What happens when the context window gets close to full?
How do you interrupt Claude mid-turn without losing its progress?