The Claude Bible
Home / Claude Code recipes
Level: Intermediate · 12 lessons

Claude Code recipes

Concrete end-to-end recipes for everyday coding tasks.

Open the interactive course212 lessons, quizzes, exercises, 3 languages, free.

Recipe: debug a failing test

A failing test is a reproducible signal: it tells you exactly what the code promised and what it actually did. Claude Code turns that signal into a fix by following a four-step loop: Reproduce, Isolate, Fix, Confirm.

Reproduce means running the test command so Claude sees the exact error output in context. Isolate means narrowing the cause to one function, one assertion, or one bad assumption. Fix means changing only the code that caused the failure. Confirm means running the test again and reading a green result before closing the task.

The key discipline is: do not ask Claude to fix anything before it has read the error. Paste the full test output (the stack trace, which is the chain of function calls that led to the crash) into your prompt. Without it, Claude guesses.

  1. Run your test suite and copy the failure output.
  2. Open Claude Code and paste the output with a clear goal.
  3. Let Claude read the relevant source files and propose a fix.
  4. Apply the fix, re-run the tests, and confirm green before moving on.
Key points
  • Paste the full stack trace, not just the error message
  • Fix only the code that caused the failure
  • Confirm green before closing the task
  • One failing test at a time keeps the loop short

Recipe: refactor safely

Refactoring means changing the internal structure of code without changing what it does from the outside. The danger is silent breakage: you move things around, and a feature quietly stops working. The antidote is a test lock, a suite of automated tests that proves behavior before you touch a single line of logic.

The recipe has three steps in strict order:

  1. Write or generate tests first. Ask Claude Code to read your file and produce tests that cover the current behavior. Commit those tests. They are your safety net.
  2. Run the tests in watch mode. Use /terminal inside Claude Code or your own shell to keep the test runner alive. Every time Claude changes a file, the runner re-executes and turns red the moment something breaks.
  3. Ask Claude Code to refactor, one concern at a time. Small, focused changes make failures easy to trace. If a test goes red, Claude Code can read the failure output and fix it before moving on.

Claude Code reads test output automatically when you paste or pipe it into the conversation. That feedback loop, write test, refactor, read failure, fix, is what makes AI-assisted refactoring reliable rather than reckless.

Key points
  • Write tests before restructuring, not after
  • Keep the test runner live so failures appear instantly
  • Refactor one concern at a time to isolate breakage
  • Paste test output into Claude Code so it can self-correct

Recipe: build a feature test first

Test-Driven Development (TDD) is a workflow where you write a failing test before you write the code that makes it pass. The cycle has three steps: red (test fails), green (code passes the test), refactor (clean up without breaking the test). Claude Code is a natural fit because you can describe intent in plain language and let it generate both the test and the implementation in the right order.

To start, give Claude Code a clear feature description and tell it explicitly to write the test first. The key phrase is: "write a failing test, then make it pass." Without that instruction Claude will often jump straight to the implementation.

Once Claude produces the test file, run it immediately. Confirm it is red (failing) before asking Claude to write the implementation. This one checkpoint prevents the most common TDD mistake: writing a test that was never actually testing anything.

Key points
  • Write the test before the implementation
  • Confirm red before asking for green
  • Refactor only when tests are passing
  • One behaviour per test cycle

Recipe: review a pull request

A pull request (PR) is a proposal to merge a set of code changes into a project. The changes are presented as a diff (short for difference), a file-by-file view showing lines removed in red and lines added in green. Reading a diff carefully is how bugs and unclear logic get caught before they reach production.

Claude Code can read a diff and act as a second reviewer. You point it at a branch or a PR URL, and it flags issues across several dimensions:

The /code-review skill inside Claude Code orchestrates this automatically. It reads staged changes or a named branch diff, runs analysis, and returns structured findings. You control depth with an effort flag: --effort low for a quick pass, --effort high for broader coverage including uncertain findings. Add --comment to post findings directly as inline PR comments on GitHub, or --fix to apply safe fixes to the working tree.

Key points
  • A diff shows added and removed lines across files in a PR
  • /code-review runs structured analysis on the current diff
  • --effort controls how deep and broad the review goes
  • --comment posts findings as inline GitHub PR comments

Recipe: build a feature end to end

A feature build is the full arc from a plain-English request to a working, tested change committed in your repo. Claude Code handles every step, but you get better results when you structure that arc deliberately.

The recipe has four phases:

  1. Scope. Open Claude Code in your project root and describe what you want in one clear sentence. Ask it to list the files it will touch before writing anything: /plan or just say "list the files you will change and why, then wait for my go-ahead."
  2. Implement. Approve the plan, then let Claude Code write the code. Watch the tool calls in the terminal. If a call looks wrong, type /stop to interrupt without losing context.
  3. Verify. Ask Claude Code to run the relevant tests or linter: run the tests for this module and show me the output. For a UI change, use the /run skill or ask it to start the dev server and describe what to check.
  4. Commit. Once tests pass, ask Claude Code to stage only the changed files and write a commit message. Review the diff it shows before confirming.

Two habits that prevent rework: always read the plan before you approve it, and always run tests inside Claude Code rather than trusting a visual inspection alone.

Key points
  • Scope the feature in one sentence before coding starts
  • Use /stop to interrupt without losing context
  • Verify with real test runs, not visual checks
  • Review the diff before every commit

Recipe: fix a bug systematically

Jumping straight to a fix without understanding the root cause is the fastest way to create two bugs instead of one. The systematic approach forces diagnosis first, patch second. Claude Code supports this discipline through a set of commands that read, trace, and test before touching any code.

The workflow has four phases. Reproduce: confirm the bug is real and isolated. Trace: find the exact line and reason it fails. Hypothesize: state one specific cause before writing any fix. Verify: run the tests again after the patch to confirm the symptom is gone and nothing new broke (this is called a regression check).

Claude Code's /systematic-debugging skill enforces this order. You can also drive it manually with plain prompts. Either way, the key rule is: do not accept a patch that Claude proposes unless it also explains why the bug happened.

Key points
  • Diagnose root cause before writing a fix
  • Reproduce the bug in isolation first
  • Demand a 'why' explanation, not just a code change
  • Run a regression check after every patch

Recipe: migrate or upgrade a dependency

A dependency is an external library your project relies on (for example, a date formatter or an HTTP client). Upgrading one means changing a version number, fixing every breakage, and confirming the app still works. Claude Code turns that multi-step chore into a guided conversation.

The recipe has four stages:

  1. Plan: ask Claude Code to read the current version, check the changelog, and list breaking changes that affect your code.
  2. Change: let it edit package.json (or the relevant manifest) and run the install command.
  3. Run: execute your build and test suite so errors surface immediately.
  4. Verify: review the diff, confirm tests pass, and do a quick smoke test of the affected feature.

Because Claude Code can read files, run shell commands, and iterate in one session, it catches cascading errors (where fixing one import breaks another) without you switching between terminal tabs. Always commit your code before starting so you have a clean rollback point.

Key points
  • Commit before you upgrade, so rollback is one command away.
  • Ask for breaking changes first, before touching any file.
  • Run tests automatically after the install, not as an afterthought.
  • Review the final diff yourself before merging.

Recipe: onboard an unknown codebase

When you open a codebase you have never seen before, jumping straight into editing is the fastest way to break things. The professional move is to map the territory first: understand what exists, where the entry points are, and only then act. Claude Code can do most of this work for you in one session.

Start with a broad reconnaissance pass. Ask Claude Code to describe the project structure, list the main directories, and identify entry points (the files where execution begins, such as index.js, main.py, or app.ts). Then ask it to find the key configuration files: package managers (package.json, pyproject.toml), environment templates (.env.example), and CI definitions (.github/workflows/).

Once you have a mental map, the most valuable thing you can do is write a CLAUDE.md file at the root of the project. This plain-text file is automatically read by Claude Code at the start of every session. It acts as a persistent briefing: it tells Claude Code how to build the project, which commands to avoid, which directories matter, and any team conventions. Without it, every new session starts from zero.

A good CLAUDE.md covers four things:

Key points
  • Map structure and entry points before editing anything
  • CLAUDE.md is auto-loaded every session as a project briefing
  • Cover build, test, architecture, and off-limits rules in CLAUDE.md
  • Use /init to generate a starter CLAUDE.md automatically

Recipe: generate and maintain docs

Documentation that diverges from the code is worse than no documentation: it misleads. The solution is to treat docs as a build artifact, generated and updated by Claude Code whenever the code changes. The core idea is docs-as-code: your README, API reference, and changelogs live in the repo and are regenerated on demand.

Claude Code can read your entire codebase in one pass and produce accurate, structured documentation. The key flags are --print (non-interactive, pipes output to a file) and --allowedTools "Read,Write" (restricts Claude to only reading source and writing docs, nothing else). Always scope the prompt tightly: name the files to read and the file to write.

For ongoing sync, two patterns work well:

The model id for everyday doc tasks is claude-sonnet-4-6: fast and accurate enough for structured output. Reserve claude-opus-4-8 for architecture-level documentation that requires deep reasoning about design decisions.

Key points
  • docs-as-code: treat documentation like source, keep it in the repo
  • --print flag runs Claude Code non-interactively and pipes output
  • git hooks and CI steps enforce sync automatically
  • scope prompts to specific files to keep cost and latency low

Recipe: automate a repetitive chore

A repetitive chore is any task you run more than two or three times with the same shape: rename a batch of files, convert a report to a different format, pull data from an API and format it, clean up logs. These are prime candidates for automation with Claude Code.

The first step is to spot the pattern. Ask yourself: what inputs change each time, and what stays fixed? The fixed part becomes the script; the changing part becomes a parameter (a variable input you pass in). Claude Code can write, run, and refine that script in one conversation.

The second step is to capture the recipe so you never type it from scratch again. Claude Code gives you two options:

Once the recipe exists, running the chore costs you nothing but a single command. Claude Code reads the script, confirms the parameters, and executes, giving you a log you can review before any files change.

Key points
  • spot the repeating pattern before writing anything
  • separate fixed logic from variable inputs (parameters)
  • save the result as a script or a ~/.claude/skills/ slash-command
  • review the execution log before confirming destructive steps

Recipe: write and run a one-off script

Sometimes you need a throwaway script: a small program that does one job right now and is never needed again. Examples include renaming 200 files, parsing a CSV, or hitting an API to fetch data. Writing it by hand is slow. Claude Code can write and run it for you in one go.

The recipe has three steps. You describe the job in plain language, Claude Code generates the script (usually a short Node.js or Python file), and then it runs the script immediately. You get the output without ever opening a text editor.

Key things to include in your request so Claude Code gets it right the first time:

Claude Code writes the file to a temp path, executes it, streams the output back to you, and can delete the file automatically. No leftover clutter, no manual cleanup.

Key points
  • Describe input, output, and runtime clearly
  • Claude Code writes, runs, and can delete the script
  • No editor or terminal knowledge required
  • Ask for a dry-run first on large or destructive jobs

Recipe: explain confusing code

When you open an unfamiliar file and the logic is opaque, Claude Code can walk you through it line by line. The key is giving enough context: the file, the specific section, and what you already know (even if that is "nothing").

The fastest path is the at-mention syntax. In the Claude Code chat panel, type @filename to attach a file directly to your message. Claude then explains it with full visibility into the actual source, not a paste you might have trimmed.

For a targeted explanation, narrow the request to a function, a class, or even a single expression. Broad requests ("explain this whole repo") produce broad answers. Focused requests produce actionable answers.

Key points
  • Use @filename to attach context without copy-pasting
  • Narrow the request to the specific function or block that confuses you
  • Ask for a glossary of jargon inside the same prompt
  • Request a real-world analogy for abstract or recursive logic
Work with me

Master Claude, Claude Code and LLMs, from your first prompt to multi-agent orchestration.

Like this course? I built it end to end. Need a web app, mobile app, AI automation or SEO/GEO? Let us talk.

Contact me on LinkedInSee a site I built