AI EngineeringZero to ProductionHome·About·What’s new·Contact
Claude & Anthropic · Chapter C3

Claude Code & Agentic Development with Claude

You've built the agent loop by hand. Claude Code is that loop, productionized into a coding agent that lives in your terminal, reads and edits your repo, runs commands, and asks before doing anything risky. This chapter is how to drive it well — and what to steal for your own agents.

⏱️ ~50 min🛠️ Hands-on🎯 Beginner→Intermediate
⚙️ To run this for realThe code here is complete and correct as written. To actually execute it you'll need:
  • an Anthropic API key (ANTHROPIC_API_KEY) + pip install anthropic
Reading and learning works without any of this — run when you're ready. IDs/ARNs in examples are placeholders; swap in your own.

Learning objectives

  • Install Claude Code and run it against a real repository.
  • Explain its agent loop and how permissions gate risky actions.
  • Use CLAUDE.md, slash commands, and subagents to steer it.
  • Write effective prompts for an agent that can read, edit, and run code.
  • Map every Claude Code feature back to a pattern in your own agents.

What Claude Code is intermediate

Picture the difference between an assistant that tells you what to type and one you can actually hand the keyboard to. A chatbot can describe the fix — "open server.py, find the handler, add a null check" — but you still do every keystroke, every file open, every test run. That gap between advice and action is exactly what Claude Code closes, and it's why this chapter matters: you're about to see the agent loop you built by hand in C2 turned into a tool that lives in your terminal and does the typing.

The mental model to hold: it's your C2 tool-use loop, but the tools reach into your real project. In C2 you wrote a loop where the model proposes a tool call, your code runs it, and the result goes back. The "tools" there were toys — a calculator, a mock lookup. Claude Code is the identical shape, except the tools are the ones a working developer actually uses: read a file, edit a file, grep the codebase, run a shell command, hit the web, spawn a helper. Same engine, real steering wheel.

A common beginner mistake is to imagine Claude Code as a smarter autocomplete, like the inline suggestions in an editor. It isn't. Autocomplete guesses the next few characters; Claude Code takes a goal ("add a --version flag") and runs a multi-step loop — reading files, making edits, running tests, reacting to failures — until the goal is met or it needs your input. It's an agent, not a suggestion engine, and that changes how you talk to it (a whole section below) and why the safety gate exists at all.

Claude Code is Anthropic's official agentic coding tool. It's the Chapter 4 agent loop, hardened and given a real tool surface: it can read files, edit them, run shell commands, search the codebase, call the web, and spawn subagents — all under a permission system that stops before anything destructive. Under the hood it's the same Messages API and the same tool-use loop you just wrote in C2, running against a frontier model at high effort.

a chatbot describes the fix you type it all advice — you do the work Claude Code takes a goal read · edit · run action — it does the work Advice vs action. A chatbot describes the fix and leaves the keystrokes to you; Claude Code takes the goal and reads, edits, and runs code itself. That gap between telling and doing is the whole point of an agentic coding tool.
🗺️ How to read this diagram

Read it as two columns split by the dividing line — the left is an ordinary chatbot, the right is Claude Code — top box (what it takes in) to bottom box (what it produces).

  • The left column is a plain chatbot: it describes the fix ("open this file, add a check"), but the bottom box is you — every keystroke, file open, and test run is still your job.
  • The right column is Claude Code: you hand it a goal, and the green bottom box shows it doing the work itself — reading files, editing them, running commands.
  • The two captions under each column — "advice" vs "action" — are the payoff: same request, but only one of them actually moves your repo.

In short: A chatbot tells you what to type; Claude Code takes the goal and does the typing. Closing that advice→action gap is what makes it an agent, not autocomplete.

Where it runsClaude Code is available as a terminal CLI, a desktop app (Mac/Windows), a web app at claude.ai/code, and IDE extensions (VS Code, JetBrains). This chapter uses the CLI — the concepts carry across all of them.

The agent loop, productionized intermediate

Here's the moment where "an AI that edits my code" stops being scary and starts being understandable. The word agent sounds like magic — some autonomous thing making its own decisions in your repo. It isn't magic. It's a loop you can draw on a napkin, and once you see the four boxes, the whole tool loses its mystery and you know exactly where you're in control.

Think of it like a contractor renovating your kitchen. The contractor doesn't silently knock down a wall — they say "I'd like to remove this wall," you say yes or no, then they swing the hammer, and they show you the result before proposing the next step. Claude Code runs that exact rhythm: the model proposes an action, a gate checks it (auto-approve the safe stuff, ask you about the risky stuff), the tool runs, and the result feeds back so the model can decide what to do next. Round and round until the job's done.

Why give this its own section when you already wrote a loop like it in C2? Because the stakes changed. In C2 the "tools" couldn't hurt anything — worst case, a wrong number came back. Here the tools touch your real files and run real shell commands, so the loop grows one new organ: the permission gate in the middle. The single most common misconception is that the model just does whatever it wants; in reality nothing state-changing happens without passing that gate first. Read the diagram below as "the C2 loop, plus a checkpoint" — the checkpoint is the whole reason you can trust an agent with your keyboard.

You already know this shape from C2. Claude Code is the same round-trip, with a real file/shell tool surface and a permission gate wrapped around every action.

Claude (model) proposes a tool call permission gate allowed / asks you tool runs (edit/bash/…) resultback to model Same loop, real stakes. The model proposes; the permission gate decides whether it runs automatically or waits for your approval; the tool executes; the result feeds back. This gate is the single most important safety idea you'll carry into your own agents.
🗺️ How to read this diagram

This picture is the whole idea of Claude Code in four boxes: it is the same send-request / get-reply loop you built in C2, but now the model can act on your computer — and a permission gate sits in the middle so nothing dangerous happens without your say-so.

  • Top box — Claude (the model): it looks at your request and proposes a single action, called a tool call (for example "edit this file" or "run this command"). At this point nothing has actually happened yet.
  • Arrow down → permission gate: every proposed action passes through this gate first. The gate decides: run it automatically (safe, read-only things) or pause and ask you (anything that changes files or runs commands).
  • Arrow down → tool runs (edit/bash/…): only after it's allowed does the tool actually execute — editing a file, running a shell command, and so on.
  • The long curved arrow back up (labelled "result back to model") carries the outcome — the new file contents, the command's output — back to Claude, which reads it and decides the next step. Then the whole loop repeats until the job is done.

In short: The one box to remember is the permission gate. It is the difference between an assistant that suggests and one that acts — and the safety idea you'll rebuild in every agent of your own.

Lab C3.1 · Install & first session intermediate

Example code for learning — review, test, and adapt it before running against real or production systems. Commands can create, change, or delete resources. See the Terms & Disclaimer.
Lab C3.1
  1. Install & launch. Follow the current install instructions from Anthropic's docs, then in any project directory run:
    shellclaude

    It starts an interactive session scoped to the current directory.

  2. Ask it to orient itself. A good first prompt is exploratory, not a change:
    promptExplain what this project does and how it's structured.
    Don't change anything yet.

    Watch it read files, search, and summarize — read-only tools run without prompting you.

  3. Ask for a small, concrete change.
    promptAdd a --version flag to the CLI that prints the version from
    pyproject.toml. Show me the diff before applying.

    Now it proposes an edit — a state-changing action — and pauses for your approval.

▶ How this works

This lab is your first real session. You install Claude Code, launch it in a project, and give it two prompts — first a harmless "look around" one, then a small change. The point is to see the permission gate in action: read-only work just happens, but a change waits for you.

  1. Launch: running claude in a project folder starts an interactive session scoped to that directory — it can see and work with the files there, and nowhere else. Think of it as opening a chat that also has hands.
  2. Prompt 1 (orient): "Explain what this project does… Don't change anything yet." asks it only to read and summarise. Reading files and searching are read-only tools, so they run without asking you — you'll watch it explore on its own.
  3. Prompt 2 (change): asking it to Add a --version flag and Show me the diff before applying requests an edit — an action that changes state. Now the gate kicks in: Claude proposes the edit and pauses for your approval before touching anything.
  4. The habit this teaches — explore first, change second — is called read-only-first, and it's the same discipline you'll see again in the FDE method (Chapter 7).

What the output means: Prompt 1 prints a plain-English summary of the repo (no changes). Prompt 2 shows you a diff — the exact lines it wants to add or remove — and then stops and asks "apply this?" instead of silently editing.

Try this: On your very first prompt in any unfamiliar repo, add "don't change anything yet." You build trust in what the agent understands before you let it write a single line.

Start read-only, then escalateYour first prompt in an unfamiliar repo should be "explain / find / don't change anything." You build trust in what the agent understands before you let it write — the exact same discipline the FDE method (Chapter 7) applies to deploying an agent into a company.

Permissions: the trust ladder intermediate

Imagine hiring a brilliant new engineer on day one and handing them production database credentials before lunch. Nobody does that — not because the person isn't capable, but because trust is earned, and the cost of a mistake before it's earned is enormous. Claude Code bakes that same instinct into software. It won't refuse to help, but it won't quietly run rm -rf or push to main either. It classifies every action by how much damage it could do, and stops to ask before the dangerous ones.

The useful analogy is a set of doors with different locks. Some doors are wide open — reading a file, searching the code, listing a directory. These can't hurt anything: worst case, the agent looks at something and moves on, so they run automatically and never interrupt you. Other doors need a key you turn each time — editing or creating a file. And some doors open onto the street — running a shell command, installing a package, pushing to git — where a mistake escapes your machine or is hard to undo. Those always pause and ask, and you decide door by door.

The mistake to avoid is thinking of approval as a one-time switch you flip to "trust this agent." It isn't binary and it isn't blanket — that's why we call it a ladder. You climb it one rung at a time: allow a specific safe command, watch what happens, allow a slightly broader pattern once you've seen it behave. Approving npm test is not the same as approving npm publish, and treating them as the same is exactly how people get burned. This is the productionized version of the human-in-the-loop gate from Chapter 4 — the difference between an agent that suggests and one that acts, made concrete as a policy the tool enforces on your behalf.

Claude Code classifies actions by risk and asks before the risky ones. This is the productionized version of the human-in-the-loop gate from Chapter 4.

risk climbs as you go down · so does the checkpoint read-only read · grep · glob · list → auto-runs writes edit · create file → asks once shell / external run · install · push → always asks approve door by door — never one blanket switch The trust ladder. Actions are graded by how much damage they could do: safe reads run free, file writes pause for a yes, and shell/external commands always ask. You climb one rung at a time rather than flipping a single "trust it" switch.
🗺️ How to read this diagram

Read the three bands top to bottom — as you go down, the action gets riskier and the checkpoint gets stricter.

  • The green top band — read-only (read, grep, glob, list): these can't hurt anything, so they run automatically and never interrupt you.
  • The amber middle band — writes (edit or create a file): reversible-ish, so it asks the first time — you can allow it once you've seen it behave.
  • The red bottom band — shell / external (run a command, install a package, push to git): a mistake here escapes your machine or is hard to undo, so it always pauses and asks.
  • The line underneath is the key discipline: you approve door by door, not with one blanket "trust this agent" switch — approving npm test is not approving npm publish.

In short: Green runs free, amber asks once, red always asks. Trust is earned one rung at a time, not granted all at once.

Action classExamplesDefault behavior
Read-onlyread file, grep, glob, listRuns automatically
Reversible-ish writesedit a file, create a fileAsks (or auto-approves once you allow it)
Shell / externalrun a command, install a package, push to gitAsks — you approve each, or allowlist a pattern
Approval in one context isn't blanket permissionAllowing npm test once doesn't mean npm publish is fine. Approve deliberately. For outward-facing or hard-to-reverse actions (push, deploy, delete), confirm first — this is a habit the tool enforces and one you should build into every agent you write.

Lab C3.2 · Steering with CLAUDE.md & slash commands advanced

Two mechanisms turn Claude Code from generic to your project's agent:

CLAUDE.md loaded every session /review command invoked on demand the agent always when you type it Two ways to steer. CLAUDE.md is standing context loaded into every session automatically; a slash command is a saved prompt you invoke only when you want it. Both feed the same agent so you stop re-typing instructions.
🗺️ How to read this diagram

Read left to right: two sources of instruction on the left both flow into the one agent on the right — but they arrive at different times.

  • The top-left box — CLAUDE.md: a file at your repo root that is loaded into every session automatically. Its arrow is labelled "always" — the agent has this context before you type a word.
  • The bottom-left box — /review command: a saved prompt under .claude/commands/. Its arrow is labelled "when you type it" — it only runs on demand, the moment you invoke it.
  • Both arrows point into the agent box: the difference is timing, not power — standing context vs a reusable prompt you fire when needed.

In short: CLAUDE.md = context the agent always has; a slash command = a prompt you re-run on demand. Both stop you repeating yourself.

Lab C3.2
  1. CLAUDE.md — persistent project context. A file at the repo root that's loaded into every session. Put conventions, build/test commands, and gotchas here.
    CLAUDE.md# Project conventions
    - Run tests with `pytest -q`; lint with `ruff check`.
    - All API code targets the Anthropic Python SDK, model `claude-opus-4-8`.
    - Never edit files under `generated/` by hand — they're built by `make gen`.

    Now every session already knows how to test, what model to use, and what not to touch — you stop repeating yourself.

  2. Slash commands — reusable prompts. Type / to see built-ins (and any you define). They're saved prompts for tasks you do often:
    .claude/commands/review.mdReview the current git diff for correctness bugs and
    security issues. Report findings with severity; don't fix yet.

    Invoke it with /review. This is exactly the "prompts as versioned artifacts" idea from Chapter 2, applied to your workflow.

▶ How this works

This lab shows the two ways you turn a generic agent into your project's agent: a CLAUDE.md file (standing context it always reads) and slash commands (saved prompts you can re-run). Both save you from re-typing the same instructions every session.

  1. CLAUDE.md is a plain text/Markdown file at the top of your repo. Claude Code loads it into every session automatically, so whatever you write here is context it always has — like a sticky note the agent reads before starting.
  2. The example lines state conventions: how to run tests (pytest -q), which model to use, and a hard rule — Never edit files under generated/ by hand. Now you never have to repeat any of this; the agent just knows.
  3. Slash commands are reusable prompts saved as files under .claude/commands/. The filename becomes the command: review.md → you type /review to run it.
  4. The review.md body is just a prompt: "Review the current git diff for correctness bugs and security issues… don't fix yet." Saving it as a file means the whole team gets the same review prompt, and it's version-controlled like any other code.

What the output means: After adding these two files, a fresh session already knows your test command and coding rules without being told, and typing /review runs your saved review prompt in one keystroke.

Try this: Write a CLAUDE.md for a project you know with just four lines: the test command, one build/lint command, one convention, and one "never touch this" rule. That's Exercise C3.1 — the smallest useful version.

This repo already uses itThe bit-bucket-repo this course lives in has nested CLAUDE.md files that tell the agent how each sub-project deploys. Good CLAUDE.md hygiene is the difference between an agent that guesses and one that follows your conventions.

Subagents & parallelism advanced

You've almost certainly done this in real life without naming it. Faced with a big question — "does our codebase use this deprecated library anywhere?" — a smart team lead doesn't grind through every folder alone. They split the repo three ways, hand a slice to each teammate, and stitch the answers together at the end. What took one person a day takes three people a few hours. Claude Code does the exact same thing with subagents, and knowing when to reach for them is what separates fast agent work from slow.

A subagent is a fresh, separate Claude Code instance that the main agent spins up to handle one independent chunk of a task. Each gets its own clean context window and works on its own piece — search subsystem A while another searches subsystem B — then reports its findings back. The main agent collects those reports and synthesizes them into one answer for you. The technical name for the shape is fan out, then converge: spread wide across independent work, then pull the results back to a single point. It's the same concurrency pattern you'd build by hand with threads or async tasks in your own systems, just wrapped up so the agent manages it for you.

The trap — and it's the one worth flagging loudly — is over-delegation. Because modern models spawn subagents readily, it's tempting to think "more agents = faster," but that's backwards for the wrong shape of task. Subagents only help when the work is genuinely wide: many independent things that can happen at once. For a single sequential edit — read one file, change one function — spinning up a subagent just adds startup latency and burns extra tokens for a result the main agent could have produced directly. The rule of thumb: fan out for breadth, not for depth. If the subtasks depend on each other's output, they're not parallel, and a helper adds nothing but overhead.

For big tasks, Claude Code can spawn subagents — separate agent instances that work in parallel on independent pieces, then report back. This is the same "fan out, then synthesize" pattern you'd build with concurrency in your own systems.

main agent explore A explore B explore C results synthesized back into one answer Fan out, then converge. Independent subtasks (search three subsystems, review five files) run concurrently as subagents; the main agent merges their findings. Delegate when work is parallel and independent — not for a single-file read.
🗺️ How to read this diagram

This diagram shows how Claude Code handles a big task by splitting it into pieces that run at the same time. It's the "fan out, then converge" pattern: hand independent chunks of work to helpers, then combine what they find.

  • Top box — main agent: the session you're talking to. When a task naturally breaks into independent parts, it doesn't do them one-by-one — it delegates.
  • Three arrows fanning out → explore A / B / C: each is a subagent, a separate agent instance working on its own piece in parallel (e.g. searching three different subsystems, or reviewing five files at once).
  • The line at the bottom — "results synthesized back into one answer": each subagent reports what it found, and the main agent merges those findings into a single coherent result for you.
  • When to use it: only when the work truly fans out into independent items. For a single sequential edit, spinning up subagents just adds delay and cost — the main agent should just do it.

In short: Fan out for breadth (many independent things at once), converge for the answer. Reach for subagents when a task is wide, not when it's a single step.

Use subagents for breadth, not everythingModern models spawn subagents readily. Reach for them when work fans out across independent items; for a single sequential edit, let the main agent just do it. Over-delegation adds latency and token cost.

Prompting a coding agent well advanced

The single biggest reason people are disappointed by coding agents is that they prompt them like a chatbot. "Fix the bug" works fine when a human reads it — the human asks a clarifying question, uses judgement, fills the gaps. An agent that can act won't pause to ask; it will confidently interpret your vague request and go do something, and if your words left room for a wrong reading, you'll get a wrong-but-plausible diff. Sharper input isn't politeness here — it's the difference between a task that closes and an afternoon of undoing damage.

The mental shift is from chatting to briefing. Think of how you'd hand a task to a capable contractor you can't interrupt for a week: you wouldn't say "make the kitchen nicer." You'd say what "done" looks like, what's off-limits, and how they'll know it worked. A good agent prompt has the same three parts — a fully specified goal, explicit bounds ("don't touch X"), and a verification step ("run the tests and fix failures"). Modern Claude does its best work when the whole task is stated once, up front, rather than dripped out over ten back-and-forth turns.

Two failure modes trip up newcomers, and they pull in opposite directions. The first is vagueness: "clean up the code" gives the agent no target, so it guesses at scope and often refactors things you never wanted touched. The fix is to bound the work — say what not to do as clearly as what to do. The second is shouting: because Claude follows instructions literally, ALL-CAPS demands and piled-on emphasis don't make it try harder, they over-trigger and distort its behaviour. The winning register is calm, literal, and specific. "Fix the login bug" is weak; "the /login endpoint 500s on empty passwords — reproduce it with a failing test, then fix it so an empty password returns a 400" is a task an agent can actually finish, because there's nothing left to guess.

An agent that can act needs sharper prompts than a chatbot. The habits that work:

chatting "fix the bug" wrong-but-plausible it guesses the scope briefing goal (symptom + done) bounds (don't touch X) verify (run the tests) task that closes nothing left to guess Chatting vs briefing. A vague prompt leaves room for a wrong reading, so an agent that acts returns a wrong-but-plausible diff. State goal, bounds, and a verification step and there is nothing left to misinterpret.
🗺️ How to read this diagram

Read the two columns split by the line: the left is prompting like a chatbot, the right is briefing an agent — each flows top (the prompt) to bottom (the result).

  • The left column starts with "fix the bug" and lands in a red box — because the agent can't ask a clarifying question, it guesses the scope and confidently produces a wrong-but-plausible diff.
  • The right column stacks the three parts of a good brief — a specified goal, explicit bounds ("don't touch X"), and a verification step ("run the tests") — which feed into a green box: a task the agent can actually close.
  • The payoff line under each column — "it guesses the scope" vs "nothing left to guess" — is the whole difference: sharper input, not politeness, is what makes the task finish.

In short: Vague in → wrong-but-plausible out; goal + bounds + verification in → a task that closes. Brief the agent, don't chat with it.

HabitWhy
Give the goal up front, fully specifiedModern Claude does best with the whole task stated once, not dripped over many turns. State intent, constraints, and "done" criteria.
Say what NOT to do"Don't refactor unrelated code. Don't add error handling for cases that can't happen." Bounds prevent scope creep.
Ask to plan before big changes"Show me a plan and the files you'll touch before editing." Cheaper to redirect a plan than a diff.
Point at verification"Run the tests after each change and fix failures before moving on." An agent that checks its own work is far more reliable.
Calm, literal, specificBecause Claude follows instructions literally, vague prompts get literal-but-wrong results and shouting over-triggers. "Fix the bug" is weak; "The /login endpoint 500s on empty passwords — reproduce it with a test, then fix it" is a task an agent can actually close.

What to steal for your own agents expert

Here's the reframe that makes this whole chapter pay off twice. It's easy to treat Claude Code as a finished product you consume — a clever black box from Anthropic. But you just spent C2 and Chapter 4 building the pieces it's made of, which means you can flip the relationship: instead of only using it, you can read it as a worked example of how a production agent is assembled. Every feature you've met in this chapter is a design decision you'll face in your own agents, already answered well.

The analogy is learning to cook by eating at a great restaurant with an open kitchen. You don't just enjoy the meal — you watch how they plate it, and you steal the techniques. Claude Code's permission gate is a technique. Its CLAUDE.md context loading is a technique. Its subagent fan-out, its read-only-first default, its slash commands — each is a concrete answer to a question every agent-builder must answer: how do I stop it doing damage? how do I give it standing context? how do I parallelize? how do I make prompts reusable?

The mistake worth naming is believing these features are proprietary magic you couldn't reproduce. They aren't — that's the entire point of the mapping table below. The permission gate is your human-in-the-loop approval plus risk classification from Chapter 4. CLAUDE.md is your system prompt plus retrieved conventions from Chapters 2 and 3. Slash commands are your versioned, reusable prompts. Subagents are your fan-out-and-synthesize pattern. Read each row as a promise: "you already know how to build this." If you can name the course chapter behind every feature, you've stopped seeing Claude Code as magic and started seeing it as engineering you can do too.

Claude Code is a reference implementation of everything this course teaches. Map its features to the patterns you build:

Claude Code feature you already know how to build permission gate human-in-the-loop CLAUDE.md context system prompt + RAG slash commands versioned prompts subagents fan-out + synthesize read-only-first the autonomy ladder Every feature is a pattern you already own. Read each arrow as a promise: Claude Code's permission gate, context file, slash commands, subagents, and read-only default each map to something this course taught you to build. It's engineering, not proprietary magic.
🗺️ How to read this diagram

Read it row by row, following each arrow from a Claude Code feature on the left to the pattern you build yourself on the right.

  • The left column lists Claude Code features you met in this chapter: the permission gate, CLAUDE.md context, slash commands, subagents, and the read-only-first default.
  • The right column is the equivalent you assemble in your own agents: human-in-the-loop approval, a system prompt plus retrieved conventions (RAG), versioned reusable prompts, fan-out-then-synthesize, and the autonomy ladder.
  • Each arrow is the mapping — and the point: none of these are proprietary. If you can name the pattern on the right, you can rebuild the feature on the left.

In short: Left = what Claude Code ships; right = what you already know how to build. The arrows prove it's engineering you can do, not magic.

Claude Code featureYour agent's equivalent
Permission gate on risky toolsHuman-in-the-loop approval + risk classification (Ch 4, capstone safety gate)
CLAUDE.md project contextSystem prompt + retrieved conventions (Ch 2, Ch 3 RAG)
Slash commandsVersioned, reusable prompts (Ch 2)
SubagentsParallel fan-out with a synthesis step (Ch 4)
Read-only-first workflowThe autonomy ladder — earn trust before acting (Ch 7 FDE)

Common pitfalls expert

Almost every bad experience with a coding agent traces back to one of a handful of avoidable habits — not to the tool being weak. That's good news: it means the fixes are cheap and mostly about discipline, not cleverness. The reason a pitfall table earns its place here is that these mistakes are seductive precisely because each one feels efficient in the moment — skip the read-only pass, blanket-approve to stop the interruptions, dash off a one-line prompt — and the cost only shows up later, when a diff is wrong or a command did something you didn't want.

Notice the through-line as you read the table: every pitfall is a shortcut around one of the safety ideas this chapter taught, and every fix is simply not taking that shortcut. Skipping read-only-first trades a minute of orientation for a bad edit. Blanket-approving trades the permission gate — your one real safety net — for slightly less clicking. Re-typing conventions instead of writing a CLAUDE.md trades five minutes once for friction every session. The pattern is always the same: a small convenience now, a larger correction later. Reading this list before you start is how you skip learning each one the expensive way.

shortcut small convenience now larger correction later discipline tiny cost now no correction every fix is simply not taking the shortcut The shortcut trap. Every pitfall — skipping read-only-first, blanket-approving, re-typing conventions — feels efficient now and bills you later. The fix is the same each time: pay a tiny discipline cost up front instead.
🗺️ How to read this diagram

Read the two columns split by the line, each flowing top (what you choose) to bottom (what it costs).

  • The left column — the shortcut: a small convenience now (skip the orientation pass, blanket-approve to stop the prompts) drops into a red box — a larger correction later, when a diff is wrong or a command did something unwanted.
  • The right column — the discipline: paying a tiny cost up front (read-only-first, deliberate approval, a CLAUDE.md) lands in a green box — no correction to pay for.
  • The line at the bottom is the whole lesson: every fix in the table below is just not taking the shortcut in the left column.

In short: A shortcut buys convenience now and bills you later; a small discipline now costs almost nothing and saves the correction. Every pitfall fix is the same move.

PitfallFix
Letting it edit before you trust its understandingStart with read-only "explain/find" prompts
Blanket-approving shell commandsApprove deliberately; allowlist narrow patterns only
Repeating conventions every sessionPut them in CLAUDE.md once
Vague prompts ("make it better")State goal, constraints, and done-criteria explicitly
No verification stepTell it to run tests/lint and fix failures before finishing

Exercises expert

Exercise C3.1 — Write a CLAUDE.md

Context: The fastest way to feel the value of standing context is to write one for a project you know and watch the agent honour it unprompted.

Your task: For a project you know, write a CLAUDE.md with how to run tests, the one build/lint command, two conventions, and one "never touch this" rule, then start a session and confirm the agent respects it without being told.

Requirements:

  • Include the test command and one build/lint command
  • Include two real conventions the repo follows
  • Include one hard "never touch this" rule
  • Start a session and confirm the agent follows it without a reminder
  • This is a context file, not executed code

💡 Hint: Pick conventions you'd otherwise have to repeat every session — the win is watching the agent already know them on turn one.

Exercise C3.2 — Plan-first refactor

Context: Running one real refactor under the plan-first protocol is how the difference from a one-shot "just do it" becomes obvious rather than theoretical.

Your task: Give Claude Code a real refactor task, but require: show a plan and the files first, wait for approval, then make one change at a time and run the tests between each — and note how the flow changes the outcome versus one-shot.

Requirements:

  • Require a plan and the file list before any edit
  • Wait for approval, then change one thing at a time with tests between each
  • Observe that assumptions surface before code changes
  • Observe that diffs stay small and reviewable and redirection is cheap
  • This is a workflow, not executed code

💡 Hint: Watch specifically for the moment the plan reveals a wrong assumption — that's the redirect you'd otherwise have paid for in a finished diff.

Show what to watch for

Plan-first surfaces wrong assumptions before any code changes, keeps diffs small and reviewable, and lets you redirect cheaply. It mirrors the capstone's "thin vertical slice" discipline.

Exercise C3.3 — Map the features

Context: The check that you see Claude Code as an example rather than magic is being able to trace each feature back to the course chapter that teaches its underlying pattern.

Your task: Without looking, redraw the "steal for your own agents" table from memory: for each Claude Code feature, name the course chapter that teaches the underlying pattern.

Requirements:

  • Permission gate → the agents chapter / capstone safety gate
  • CLAUDE.md context → prompting and RAG
  • Slash commands → prompting (reusable artifacts)
  • Subagents → the agents chapter (parallelism)
  • Read-only-first → the FDE chapter (autonomy ladder)
  • This is a recall/design exercise, not executed code

💡 Hint: If you can name the chapter behind each feature, you've internalised that Claude Code is assembled from patterns you already know.

🪜 Practice ladder beginner → industry

Six graded exercises, easy to real-world. Try each before opening its solution.

Exercise 1 · A read-only-first first sessionBeginner

Context: Claude Code is the manual tool-use loop, hardened into a coding agent with a permission gate. Your first move in an unfamiliar repo is to let it orient without changing anything.

Your task: Launch Claude Code in a project and write your first prompt so it only orients itself without changing anything, then explain why read-only tools run without prompting you.

Requirements:

  • Start a session scoped to the project directory
  • First prompt asks it to explain the project and structure and to change nothing yet
  • Explain that read-only tools (read/grep/glob) run automatically because the permission gate classifies them as safe
  • Frame this as read-only-first discipline — build trust before letting it write
  • This is a workflow, not executed code

💡 Hint: The permission gate's whole design is that safe reads don't interrupt you while writes do — leaning into that is how you stay in control cheaply.

Show solution
shell:
  claude

prompt:
  Explain what this project does and how it's structured.
  Don't change anything yet.

Running claude starts an interactive session scoped to the current directory — it can see and work with files there and nowhere else. Reading files, grep, and glob are read-only tools, so the permission gate lets them run automatically without asking you. Adding "don't change anything yet" on the first prompt in an unfamiliar repo is the read-only-first discipline: you build trust in what the agent understands before you let it write a single line. This solution is a workflow, not executed code.

Exercise 2 · Write a minimal CLAUDE.md (Exercise C3.1)Intermediate

Context: CLAUDE.md is standing context loaded into every session, so the agent stops needing the same reminders. The minimal useful version is just four lines.

Your task: Write a CLAUDE.md at the repo root with the four smallest useful things: the test command, one build/lint command, one convention, and one "never touch this" rule.

Requirements:

  • Plain Markdown at the repo root, loaded into every session automatically
  • The test command (e.g. pytest -q)
  • One build or lint command (e.g. ruff check)
  • One convention the agent should follow
  • One hard "never touch this" rule (e.g. never hand-edit generated files)
  • This is configuration/context, not executed code

💡 Hint: Put in the things you'd otherwise retype every session — the test command and the one rule you never want violated earn their place first.

Show solution
# Project conventions
- Run tests with `pytest -q`; lint with `ruff check`.
- All API code targets the Anthropic Python SDK, model `claude-opus-4-8`.
- Never edit files under `generated/` by hand — they're built by `make gen`.

CLAUDE.md is a plain Markdown file at the repo root that Claude Code loads into every session automatically, so it is standing context the agent always has — like a sticky note it reads before starting. Stating the test command, the model to use, and a hard "never touch this" rule means you stop repeating yourself each session; a fresh session already knows how to test and what not to break. This file is configuration/context, not executed code.

Exercise 3 · Author a reusable slash commandAdvanced

Context: A slash command is a saved, version-controlled prompt the whole team shares — "prompts as versioned artifacts" made concrete. A /review command standardises code review.

Your task: Create a /review slash command as a saved prompt under .claude/commands/ that reviews the current git diff for correctness bugs and security issues but does not fix them yet.

Requirements:

  • Save it as .claude/commands/review.md — the filename becomes the command
  • The body is prompt text asking for a diff review of correctness and security
  • It reports findings with severity but does not fix anything yet
  • It's reusable and identical for everyone on the team
  • It's version-controlled like code; this is a workflow artifact, not executed code

💡 Hint: The filename is the command name, and the body is just the prompt you'd otherwise paste every time — committing it makes the whole team review the same way.

Show solution
.claude/commands/review.md:

Review the current git diff for correctness bugs and
security issues. Report findings with severity; don't fix yet.

Slash commands are reusable prompts saved as files under .claude/commands/; the filename becomes the command, so review.md is invoked by typing /review. The body is just a prompt. Saving it as a file means the whole team gets the identical review prompt and it is version-controlled like any other code — this is the "prompts as versioned artifacts" idea from Chapter 2 applied to your workflow. Not executed code; it is a workflow artifact.

Exercise 4 · Prompt a coding agent well: goal, bounds, verificationExpert

Context: "Fix the bug" is a weak prompt. The lesson's four habits — specified goal, explicit non-goals, plan-first, and a verification step — turn it into one a coding agent can execute reliably.

Your task: Rewrite the weak prompt "Fix the bug" into a strong, actionable one using the four habits: a fully specified goal, what NOT to do, plan-first, and a verification step.

Requirements:

  • State the goal precisely (the symptom, the expected behaviour, a reproducing test)
  • Say what NOT to do (no unrelated refactors, no handling impossible cases)
  • Require a short plan and the files it will touch before editing, and wait for approval
  • Require verification: one change at a time, run the tests after each
  • This is workflow design, not executed code

💡 Hint: Bounding the work ("don't do X") and demanding a plan first are what keep the agent from confidently solving the wrong, larger problem.

Show solution
prompt:

The /login endpoint 500s on empty passwords.

Goal: reproduce it with a failing test, then fix it so an empty
password returns a 400 with a clear error.

Do NOT: refactor unrelated code, or add error handling for cases
that can't happen.

First: show me a short plan and the files you'll touch — wait for
my OK before editing.

Then: make one change at a time and run `pytest -q` after each
change; fix any failures before moving on.

An agent that can act needs sharper prompts than a chatbot. "Fix the bug" is vague and gets literal-but-wrong results; a strong prompt states intent, constraints, and "done" criteria up front (modern Claude does best with the whole task stated once). Saying what not to do bounds scope creep; asking for a plan first is cheaper to redirect than a diff; and pointing at verification ("run the tests after each change") makes the agent check its own work. This is a workflow, not executed code.

Exercise 5 · Plan-first refactor with per-step verification (Exercise C3.2)Professional

Context: On a real refactor, a strict plan-first, one-change-at-a-time protocol surfaces wrong assumptions before code changes and keeps diffs small — the same discipline as a thin vertical slice.

Your task: Give Claude Code a real refactor task under a strict plan-first, one-change-at-a-time protocol, and describe what the plan-first flow buys you versus a one-shot "just do it".

Requirements:

  • State the refactor, then require a plan plus the exact files before any edit
  • Wait for approval; then make one change at a time and run the tests between each
  • Stop and report if any test fails; don't proceed
  • Bound scope (e.g. don't change public signatures or unrelated modules)
  • Explain the payoff: assumptions surfaced early, small reviewable diffs, cheap redirection
  • This is workflow design, not executed code

💡 Hint: Plan-first is cheaper to redirect than a finished diff — you catch the wrong approach at the plan, not after the code is written.

Show solution
prompt:

Refactor payments/charge.py to extract the retry logic into a
reusable helper.

1. Show a plan and the exact files you'll touch first.
2. Wait for my OK.
3. Then make ONE change at a time and run `pytest -q` between each.
4. Stop and report if any test fails; do not proceed.

Don't change public function signatures or unrelated modules.

Plan-first surfaces wrong assumptions before any code changes, keeps diffs small and reviewable, and lets you redirect cheaply — it mirrors the capstone's "thin vertical slice" discipline. The per-step verification ("run tests between each") means an agent that checks its own work, which is far more reliable, and the explicit bounds prevent scope creep. This maps directly to the human-in-the-loop and read-only-first patterns the FDE method (Chapter 7) uses. Workflow design, not executed code.

Exercise 6 · Map Claude Code features to your own agent's patterns (Exercise C3.3)Industry scenario

Context: Claude Code is a reference implementation, not magic. Mapping each of its features to the pattern you'd build yourself proves you can steal the ideas for your own agents.

Your task: Reproduce the "steal for your own agents" table: for each Claude Code feature, name the equivalent pattern you build into your own agents.

Requirements:

  • Permission gate on risky tools → human-in-the-loop + risk classification
  • CLAUDE.md project context → system prompt + retrieved conventions (RAG)
  • Slash commands → versioned, reusable prompts
  • Subagents → parallel fan-out with a synthesis step (only when work is genuinely wide)
  • Read-only-first workflow → the autonomy ladder, earning trust before acting
  • This is a knowledge/design exercise, not executed code

💡 Hint: The permission gate is the single most important idea to carry across — classify by risk so safe reads run free and writes ask.

Show solution
Claude Code feature            -> Your agent's equivalent
-----------------------------------------------------------------
Permission gate on risky tools -> Human-in-the-loop approval +
                                 risk classification (Ch 4 /
                                 capstone safety gate)
CLAUDE.md project context      -> System prompt + retrieved
                                 conventions (Ch 2, Ch 3 RAG)
Slash commands                 -> Versioned, reusable prompts (Ch 2)
Subagents                      -> Parallel fan-out with a
                                 synthesis step (Ch 4)
Read-only-first workflow       -> The autonomy ladder — earn trust
                                 before acting (Ch 7 FDE)

Claude Code is a hardened, productionized version of the same Messages API and manual tool-use loop from C2, running against a frontier model. Its permission gate is the single most important safety idea to carry into your own agents — it classifies actions by risk (read-only runs automatically; writes and shell/external commands pause and ask). Subagents are the "fan out, then converge" pattern used only when work is genuinely wide, not for a single sequential edit. This is a knowledge/design exercise, not executed code.

✓ Checkpoint — you can move on when you can…

  • Install Claude Code and run a read-only orientation session.
  • Explain its agent loop and how the permission gate classifies actions.
  • Write a CLAUDE.md and a slash command that steer its behavior.
  • Say when to use subagents and when not to.
  • Prompt a coding agent with goal, bounds, and verification.
  • Map each Claude Code feature to the course pattern it implements.
🏗️ Toward the capstoneThe AI DevOps Engineer is essentially "Claude Code for infrastructure": the same loop, but the tools are terraform plan, kubectl, and AWS calls, and the permission gate is a hard safety policy that never touches prod unapproved. Everything you learned here about read-only-first, approval gates, and project context maps straight onto it. See the capstone design →

Knowledge check check yourself

✓ Knowledge check

What is the single most important safety idea in Claude Code's productionized agent loop, and how does it treat read-only vs state-changing actions?

Show answer
The permission gate: read-only actions (read, grep, glob) run automatically, while writes and shell/external commands pause and ask for your approval before executing.
✓ Knowledge check

What does a CLAUDE.md file do, and how does it differ from a slash command?

Show answer
CLAUDE.md is persistent project context loaded into every session (conventions, build/test commands, gotchas); a slash command is a reusable saved prompt under .claude/commands/ that you invoke on demand.
© 2026 studybydoing.in · AI Engineering: Zero to Production · All rights reserved. · About · Privacy Policy · Terms · Contact
Educational content, provided as-is and without warranty. Code samples are examples — review, test, and adapt them before using in production. See the Terms of Use & Disclaimer. Use at your own risk.
© studybydoing.in