Contents
- 01Know What You Are Operating
- 02Orient to an Existing Project
- 03Turn Intent Into a Build Specification
- 04Make Project Context Durable
- 05Bound Permissions and the Sandbox
- 06Make Changes With Git and Worktrees
- 07Debug and Verify the Result
- 08Extend With MCP, Skills, and Hooks
- 09Delegate and Run Work in Parallel
- 10Operate in CI and Ship the Capstone
Debug and Verify the Result
Use Claude Code to reproduce failures, test hypotheses, and close the loop with evidence instead of accepting a plausible patch.
By the end
A repeatable debugging workflow that records the symptom, environment, reproduction, root cause, change, regression check, and observed proof layer.
Begin with the observed failure
A bug report should describe what was observed, where it happened, the input or action that triggered it, the expected behavior, and the evidence available. `Login is broken` invites guesses. An error message, timestamp, browser state, account condition, request identifier, and minimal reproduction let Claude search the right path.
Name the environment precisely. A failing production request with live data may not reproduce against local fixtures. A test failure on one operating system may depend on path or shell behavior. Before editing, ask Claude to restate the symptom and reproduce it in the safest environment that still preserves the relevant condition.
Build a hypothesis chain
Debugging is a sequence of falsifiable questions, not a search for code that looks suspicious. Trace the failing path, identify the boundary where expected state becomes incorrect, and rank hypotheses by evidence. Then choose the smallest observation that distinguishes them: a targeted log, a single test, a request capture, a state query, or a diff against the last known-good version.
Ask Claude to report what each check would mean before running it. This prevents a large command dump from replacing reasoning. When a hypothesis fails, update the model rather than modifying another nearby file. Keep the investigation record concise so the final explanation shows why the fix addresses the root cause.
Write the failure before the fix
When practical, encode the bug as a test that fails for the right reason before implementation. This proves the test can see the problem and creates a durable guard against regression. A test that was written after the fix and only ever passed may accidentally confirm the implementation rather than the requirement.
Choose the lowest test layer that captures the broken contract without mocking away the cause. Unit tests are fast for pure logic. Integration tests verify boundaries such as a database or API contract. End-to-end tests and browser observation cover user paths but are slower and more sensitive to environment. Use a small number of complementary checks rather than making one giant test responsible for everything.
Verify across the required layers
A targeted test proves one expectation. Typechecking proves selected structural consistency. Linting checks configured rules. A build proves the project can produce an artifact in that environment. A browser screenshot or interaction proves visible behavior. A deployment receipt proves a version was released. A public observation proves the named user-facing route serves that behavior.
Match the proof stack to the claim. If the request is a local refactor, source review and tests may be enough. If the request says `fix the live site`, the loop also needs versioned deployment and independent production verification. Report failed or skipped checks honestly; do not substitute one green layer for another required layer.
- Source: the intended change exists in the reviewed diff.
- Test: representative behavior passes and the regression case is protected.
- Build: the artifact compiles or packages in the named environment.
- Runtime: a process built from that artifact behaves correctly.
- Shared or live: the exact deployed version is independently observable.
Debug the agent environment separately
Sometimes the application is not the failing system. CLAUDE.md may not have loaded, a permission rule may match the wrong path, an MCP server may be disconnected, a hook may reject a command, or the installation may be unhealthy. Use the layer-specific diagnostics instead of changing application code to work around an agent configuration problem.
Anthropic's configuration debugging guide centers `/context`, `/doctor`, `/hooks`, and `/mcp`. Capture the exact warning, effective source, and session location. Reproduce from a clean session when context or reload behavior may be involved. Treat configuration changes with the same diff, test, and rollback discipline as application changes.
Working reference
Commands and patterns
Create a bounded debugging request
claude --permission-mode plan "Reproduce the failure described in BUG.md. Trace the failing path, rank hypotheses, and propose the smallest check that distinguishes them. Do not edit source yet."
Separates evidence gathering from implementation and requires a hypothesis-driven plan.
Run targeted checks before broad checks
npm test -- path/to/relevant.test.ts npm run typecheck npm run build
Illustrative progression only. Use the commands documented by the actual repository, keep exact output, and do not invent missing scripts.
Diagnose Claude Code configuration
/context /doctor /hooks /mcp
Use the relevant interactive diagnostics to separate loaded context, installation health, hook behavior, and MCP connectivity.
When the happy path breaks
Failure modes
Symptom
The immediate error disappears but the same class of failure returns elsewhere.
Likely cause
The patch suppressed a symptom without identifying the invalid state, missing boundary, or broken contract that created it.
Recovery
Restore the reproduction, trace where expected and actual state diverge, and add a regression test at the responsible boundary before revising the fix.
Symptom
All new tests pass even when the fix is temporarily removed.
Likely cause
The test does not execute the broken path, mocks away the cause, or asserts an implementation detail unrelated to the user-visible contract.
Recovery
Prove the regression test fails against the pre-fix behavior for the expected reason, then keep the narrowest test that captures the contract.
Symptom
Claude deletes, skips, or weakens a failing check to make the suite green.
Likely cause
The task rewarded a green command without preserving the test's intended requirement.
Recovery
Require explanation and approval for test changes, compare against the acceptance criteria, and reject changes that remove coverage rather than repair behavior.
Symptom
A local build passes and the bug is reported fixed for production users.
Likely cause
Verification stopped below the requested proof layer.
Recovery
Deploy an identified version through the approved path, then verify the public behavior independently with the original reproduction.
Hands-on lab
Repair one bug from failing proof to regression receipt
Choose a safe, reproducible defect and use Claude Code to establish the failure, locate the root cause, implement the smallest correction, and verify the complete claim.
- 01Write `BUG.md` with environment, exact reproduction, expected behavior, actual behavior, evidence, and impact.
- 02Ask Claude in plan mode to trace the path and rank at least two plausible hypotheses with distinguishing checks.
- 03Reproduce the failure and save the relevant command output, log excerpt, request, or screenshot.
- 04Add or identify a check that fails for the expected reason before the source fix when practical.
- 05Implement the smallest root-cause change and inspect the diff for unrelated cleanup.
- 06Run the regression check, the nearest related suite, structural checks, and the build required by the repository.
- 07Observe the behavior at the proof layer named in BUG.md and have a fresh review try to falsify the result.
Deliverable: A debugging receipt containing the original failure, hypothesis chain, root cause, reviewed diff, before/after check, broader verification, and remaining uncertainty.
Reusable artifact
Debugging and verification ledger
A compact evidence trail that prevents investigation, implementation, and proof from collapsing into one confident narrative.
Observed symptom: [exact behavior] Environment and version: [local/preview/live + identifiers] Reproduction: [numbered steps + input] Expected behavior: [observable contract] Initial evidence: [error, log, screenshot, request, test] Hypothesis 1: [claim + distinguishing check + result] Hypothesis 2: [claim + distinguishing check + result] Root cause: [responsible boundary + evidence] Regression check before fix: [command + failing result] Change: [files + why each changed] Regression check after fix: [command + passing result] Broader checks: [commands + results] Observed proof layer: [source/test/build/runtime/shared/live] Adversarial review: [what tried to falsify the claim] Remaining risk: [unverified condition]
Before you move on
Receipt checklist
- The original failure is reproducible or the inability to reproduce is explicitly documented.
- The root-cause explanation is supported by at least one distinguishing observation.
- A regression check fails against the broken behavior and passes after the correction when practical.
- The diff contains no unrelated cleanup or unexplained weakening of tests and safeguards.
- The observed proof layer matches the claim reported to the user.
Primary sources
