A chat assistant answers from what you typed. Claude Code can do more: it reads files, runs commands and edits code, then looks at what happened and decides what to do next. That cycle is the agentic loop, and almost everything later in the course, from permissions to hooks to cost, is a way of shaping it.
By the end you can:
- explain what is in Claude's context, and why its size matters;
- explain how one turn proceeds through tool calls and tool results;
- predict which tools a request will use, and check the prediction in the session's transcript.
Before you start
- Sign in, and what leaves your computer is complete: you are signed in, the practice repository is cloned and trusted, and its tests show the one expected failure.
- Work in a terminal in the practice repository's root folder, with the
course's Python environment active (
source .venv/bin/activate).
Tokens and the context window
Language models do not read characters or whole words. They read tokens: short pieces of text, often a word or part of one. Prices, limits and the amount a model can take in are all counted in tokens.
The context window is the most a model can consider at once, measured in tokens. Everything Claude knows during a request has to fit in it:
- Claude Code's own system prompt, and the definitions of the tools Claude may use;
- instruction files for the project, which you write in a later module;
- the conversation so far, including your new request;
- tool results: every file Claude read and every command output it saw.
Two consequences follow, and both shape how you work:
- Claude only knows what is in its context. It has not seen a file until it reads it, and it does not remember earlier sessions unless you resume them. If a fact matters, Claude has to read it or you have to give it.
- Context is sent on every step, and it grows. Each time Claude decides its next step, the whole context goes to the model again. Reading a 5,000-line log adds thousands of tokens that stay in the context for the rest of the conversation. Claude Code reduces the cost of resending unchanged parts with prompt caching, but a full context is slower, costs more and gives Claude more to sift through.
Here is what that looked like in one of the author's runs of this lesson's
exercise (illustrative, Claude Code 2.1.308, sonnet alias). The question
was about 40 words long. Across the run's three model requests, Claude Code
reported:
| Token count | Value | What it is |
|---|---|---|
| Input tokens read from the prompt cache | 55,345 | Unchanged context resent on each step: mainly the system prompt and tool definitions |
| Input tokens written to the cache | 13,240 | Context added during the run, such as the file contents Claude read |
| New, uncached input tokens | 6 | The small remainder |
| Output tokens | 1,047 | Claude's tool calls and its answer |
Your question was a tiny part of what Claude processed. The next lesson,
Context, compaction and usage, shows how to
see this in your own sessions with /context and /usage.
How one turn works

One turn of the agentic loop.
Follow the arrows from the left:
- Your request joins the context with everything already there.
- The context is sent to Claude, the model, which decides the next step. It either answers, which ends the turn, or asks to use a tool.
- A tool call names a tool and its input, for example the Bash tool
with the command
cat src/tidewell/pricing.py. - Claude Code, the program on your computer, checks the call against your permission settings. If the call needs your approval, it asks you. Then it runs the tool on your computer.
- The result is added to the context: the file's contents, the command's output, or an error. A refused call also comes back as a result, so Claude can try another way, as you saw in Requests Claude can verify when an unapproved test command was refused.
- The loop repeats until Claude answers, or a limit such as a turn or usage limit stops it.
You can press Esc at any step to interrupt Claude and redirect it. The
work done so far is kept.
The important boundary in this picture is between Claude and Claude Code. Claude, the model, only proposes tool calls. Claude Code, on your computer, decides whether they run. That boundary is where permissions, the sandbox and hooks act, in later modules.
Claude's main tools
| Tool | What it does | Asks permission by default? |
|---|---|---|
| Read | Reads a file's contents | No |
| Edit | Makes a targeted change to a file | Yes |
| Write | Creates or overwrites a file | Yes |
| Bash | Runs a shell command | Yes, except a built-in set of read-only commands such as ls, cat, find and grep |
| Glob and Grep | Find files by name, and lines inside files | No; on Windows only by default (see below) |
| WebFetch and WebSearch | Fetch a web page; search the web | Yes |
| Agent | Hands a task to a subagent with its own context | Subagents are covered later |
On macOS, Linux and WSL, Claude Code leaves the separate Glob and Grep tools
out by default. Claude searches with find and grep through the Bash
tool instead, and those read-only commands run without asking. On native
Windows, Glob and Grep are part of the default tool set. So the same question
can produce different tool calls on different platforms.
"Asks permission by default" describes Manual mode, the mode you start with
claude --permission-mode default. Other modes and your own rules change
it; that is the subject of the permissions module.
Trace a turn
Goal: ask a read-only question about the practice repository, then check which tools Claude used and why, against your prediction.
1. Check the starting state
In the practice repository's root folder:
git status --short
It should print nothing.
2. Predict before you ask
The question you will ask is:
Explain how `PYTHONPATH=src python3 -m tidewell quote cargo 2` works out the price it prints: name each file and function involved, in the order they run. Read the code to answer; do not change any files.
Before you send it, write down:
- which files Claude will need to read;
- which tools you expect it to use on your platform;
- whether any step should need your permission.
3. Ask the question
claude --permission-mode default
Paste the question and send it. Watch the tool calls appear as Claude works.
When it has answered, press Ctrl+O to open the transcript viewer,
which shows each tool call and its result in full, with timestamps. Press
Esc or q to close it. Then leave the session with /exit.
If Claude asks permission to run the command itself, for example
python3 -m tidewell quote cargo 2, decline: the question asks it to read
the code, and the command is not in the read-only set.
4. Compare and check
In the author's two runs, on Linux, the trace was the same both times (illustrative, condensed):
Bash find . -path ./.git -prune -o -type f -print && cat src/tidewell/__main__.py
# list the project's files, read the entry point
Bash cat -n bikes.py pricing.py __init__.py (in src/tidewell)
# read the two modules __main__.py imports
Then Claude answered: __main__.py parses the arguments, get_bike_type in
bikes.py looks up the cargo bike, and hire_charge_pence in pricing.py
computes the price. Both runs also spotted that the formula adds the free
hour. Neither needed permission: find and cat are read-only commands.
Now check one detail yourself. One run's answer gave the location of the
pricing function as pricing.py:33. Run:
grep -n "def hire_charge_pence" src/tidewell/pricing.py
Illustrative output:
8:def hire_charge_pence(bike_code: str, hours: int) -> int:
The function is on line 8. Line 33 was its position in the combined output
of cat -n bikes.py pricing.py, the command Claude used to read both files
at once. The answer was right in substance and wrong in a detail, and the
reason is visible in its own tool result. This is why you check details
against the files, not against Claude's summary.
Finally, confirm that nothing changed:
git status --short
It should still print nothing.
What success shows
- Your predicted files and tools match the transcript, or you can explain each difference;
- you can say what each tool call contributed;
git status --shortprints nothing: the question changed no files.
This shows you can read a turn as a sequence of tool calls and results, which is how you will diagnose almost every later problem.
When your result differs
| What you see | What it means | Safe next step |
|---|---|---|
| Claude uses Read, Glob or Grep tools instead of Bash commands | Normal: the tool set depends on platform and version, and Claude chooses its own route | Check that each call still makes sense for the question |
| Claude asks to run the quote command | It wants to observe the output rather than read the code | Decline; the question asks it to read the code |
| Claude asks to edit a file | It treated the bug as a request to fix it | Decline, and repeat "do not change any files" |
| The answer names a file Claude never read | It guessed from names or imports | Ask it to read the file and confirm, or read it yourself |
git status --short shows a change | A change was approved by mistake | git restore <file>, then git status --short again |
Your turn
Before asking, predict the tools for this question, then ask it and compare:
Which files in this repository mention the late fee, and what do they say about it? Do not change any files.
Hint
Where is the late-fee rule written: in the code, the tests or the documentation? Which read-only commands find a word across many files?
Solution
Expect a search across the repository, such as grep -rn -i "late"
through Bash on macOS, Linux and WSL, or the Grep tool on Windows, followed
by reading the matching files. The rule lives in docs/staff-guide.md, and
a TODO(feature) comment in src/tidewell/pricing.py notes the missing
feature. No step should need permission. Claude's route may differ: judge it
by whether each call helps answer the question, and confirm with
git status --short that nothing changed.
Reset and cleanup
Nothing to clean up: the questions changed no files. If git status --short
shows a change you approved by mistake, git restore <file> undoes it.
Check your understanding
- Claude Code answered a 40-word question after processing more than 68,000 input tokens. Where did they come from?
- Who decides whether a tool call runs: Claude or Claude Code?
- On Linux, Claude listed files with
findand read them withcat. Why did it not ask permission? - Why does a refused tool call not end the turn?
Answers
- Mostly from context Claude Code sends with every request: the system prompt, tool definitions and, during the run, the file contents Claude read. Most of it was served from the prompt cache.
- Claude Code. The model proposes a call; Claude Code checks it against your permissions, asks you if needed, and runs it.
- They are in Claude Code's built-in set of read-only commands, which run without a prompt in every mode.
- The refusal is returned to Claude as a tool result, so it can choose another way or explain why it cannot continue.