Exercise 1: The Agentic Loop & Plan Mode¶
The quiz-night API has 5 intentional bugs. You will fix them three different ways to see how Claude's execution model works.
Lab: Lab 01 overview
Theory: The Agentic Loop
What it is. Claude Code is an agentic coding assistant. When you give it a task, it does not produce a single answer; it enters a loop: read the prompt, decide which tool to use (read a file, run a command, edit code), observe the result, then decide the next step. This loop repeats until the task is complete or Claude decides it needs your input.
Why it matters. Understanding this loop is essential because it determines how Claude spends your context window. A vague task may cause Claude to read dozens of files; a precise task lets it go straight to work.
How it works. When you press Enter, Claude Code:
- Analyzes your request and the current context
- Chooses a tool (Read, Write/Edit, Bash, Grep/Glob, etc.)
- Executes the tool and reads the observation
- Decides the next step: another tool call, or a response to you
Key actions:
- Esc: interrupt Claude mid-step
- Esc Esc or /rewind: undo the last step
- Shift+Tab: cycle through permission modes
Further reading: Quickstart docs
Theory: Plan Mode
What it is. A permission mode where Claude reads your code and writes a plan, but makes no edits and runs no side-effecting commands. You review, ask for changes, then approve.
Why it matters. The worst failure mode is not "it did nothing," it is "it did the wrong thing for 20 minutes before you noticed." Plan Mode is your preflight check.
How to enter:
You can also set it as default:
Gotcha. Plan Mode does not prevent Claude from reading sensitive files, only from modifying them.
Further reading: Permission modes docs
Hands-on¶
Part 1: Default Mode (watch the loop)¶
- Start Claude Code:
- Give Claude the task:
- Watch Claude work. Notice each tool call, it reads files, runs
pytest, edits code, and re-runspytest. - When pytest passes, note how many tool calls it took.
Part 2: Plan Mode (think before doing)¶
- Reset files and clear context:
Then run
/clearinside Claude (or/exitand relaunch) to start with a clean session. - Enter Plan Mode via
Shift+Tabor: - Same task:
This API has bugs. Fix them so pytest passes. - Read the plan.
- Modify it, e.g., "Start with the route handler bug instead."
- Switch back to default mode (
Shift+Tab) and tell Claude to execute.
Part 3: Interrupt & Rewind (your safety net)¶
- Reset files and clear context:
Then
/clear(or/exitand relaunch). - Default mode, same task.
- After 1–2 tool calls, press
Escto interrupt. - Add: "Also add a comment explaining the purpose of every function you touch."
- Let Claude continue. Try
/rewindto undo the last step. - Let Claude finish.
Checkpoint
- [x]
pytestpasses (all 6 tests green) - [x] You cycled through permission modes with
Shift+Tab - [x] You modified a plan in Plan Mode
- [x] You interrupted with
Escand used/rewind