All guides

Find and fix one bug with Claude Code

Bring a reproduction command and error into Claude Code, review a plan first in plan mode, apply the fix, then rerun the same command to verify.

AINavWritten / Updated Sources checked
On this page

At a glance

This guide covers one small bug fix in Claude Code: provide the reproduction command and error, let Claude read files and propose a fix, approve before anything changes, and verify with the same command. The example, a null-value problem in user.ts, is fictional and is not a real run result.

Workflow

  1. Describe it

    Give the reproduction command, the error or stack trace, and whether it is consistent.

  2. Review first

    Use plan mode so Claude reads files and proposes a fix; it edits only after approval.

  3. Rerun

    After the fix, rerun the reproduction command and related tests, then inspect the diff.

Each stage cites official sources.

Before you start

  • Claude Code starts in your terminal and the project has a command that reproduces the bug (installation and login were not verified here).
  • You know whether the bug appears every time or intermittently, and the steps that trigger it.
  • The project is in a recoverable state, for example changes are committed or you can inspect differences with version control.

1. Enter the project and start a session

In your terminal run cd /path/to/project, replacing the path with your own project directory. To review before anything is written to disk, start in plan mode with claude --permission-mode plan. Alternatively, start claude normally and press Shift+Tab during the session until the status bar shows ⏸ plan mode on. In plan mode Claude reads files and proposes a plan, and makes no edits until you approve.

2. Provide the command and the symptom

Your input should include the command that triggers the error, the full error or stack trace, the steps to reproduce, and whether it happens every time or only sometimes. For example: "I'm seeing an error when I run npm test", followed by the pasted error text. The documentation's tips are to tell Claude the command that reproduces the issue and provide a stack trace, mention the reproduction steps, and say whether the error is intermittent or consistent. State the expected behavior too. In this synthetic example, missing email must return an explicit validation error, while normal email inputs retain their existing behavior.

3. Ask for several fix options

Before any change is applied, ask for the cause and options, for example: "suggest a few ways to fix the @ts-ignore in user.ts". Use @ with a path, such as @src/utils/user.ts, to reference a specific file. This puts the file's content in the conversation and also adds CLAUDE.md files from that file's directory and its parents to context. Compare how much each option changes and prefer the smallest one that explains the root cause. Content inclusion is the default. In Claude Code v2.1.299+, CLAUDE_CODE_DISABLE_FILE_MENTIONS=1 in the shell or user/managed settings env sends paths only, so Claude must read them with file tools. The variable is ignored in project and local settings.

4. Review the plan, then approve

Read the plan: which files change, which logic, and how it will be verified. If you are unsure, ask follow-ups or request adjustments; nothing on disk has changed yet. Approve only when the plan matches your understanding of the cause, then have Claude apply it, for example: "update user.ts to add the null check you suggested". State the expected behavior too. In this synthetic example, missing email must return an explicit validation error, while normal email inputs retain their existing behavior.

5. Rerun the command and related tests

After the fix, ask Claude to run the same command that first triggered the error, then the related tests. Compare with the symptom from step 2: is the original error gone, and did a new failure appear? If it still fails, paste the new full output back and return to step 3 rather than letting Claude keep editing blindly.

6. Inspect the changes and decide how to finish

Use version control to view the actual diff and confirm only the planned files changed. If you want a pull request, you can ask Claude to create one; the documentation advises reviewing the generated PR before submitting and asking Claude to highlight risks. If the task spans several sittings, run claude --continue in the same directory to resume the most recent session. To stop, do not approve the plan, or quit the session and revert uncommitted changes.

Original example

The following is a fictional scenario that only illustrates how to phrase inputs; it is not real output. Scenario: when npm test runs in a project, a function in user.ts may throw a null-value error for a user object that lacks an email field; it happens on every test run. Step 2 input: I'm seeing an error when I run npm test. It fails every time, not intermittently. Steps: run npm test in the project root. Error text: <paste your real error here> Step 3 input: suggest a few ways to fix the null handling in @src/user.ts After approving the plan: update user.ts to add the null check you suggested, then run npm test again and show me the result Expected check result: the same npm test no longer shows the original error, and the version-control diff touches only the files named in the plan. State the expected behavior too. In this synthetic example, missing email must return an explicit validation error, while normal email inputs retain their existing behavior.

Completion checks

  • The reproduction command really showed the error before the fix, and rerunning the same command afterward no longer shows it.
  • In plan mode the status bar shows ⏸ plan mode on, and no file on disk changed before you approved.
  • The proposed fix explains the root cause instead of only suppressing the error, for example not just adding @ts-ignore.
  • The version-control diff contains only the files listed in the plan, and the related tests were run.
  • State the expected behavior too. In this synthetic example, missing email must return an explicit validation error, while normal email inputs retain their existing behavior. Check the real output of the relevant tests.

Limits

  • Plan mode only controls "no edits before approval"; it does not judge whether the plan is right, so you still review the root cause yourself.
  • If the error cannot be reproduced reliably, or needs an external service or private data to trigger, add those conditions first rather than letting Claude edit code on a guess.
  • An @ reference is not included when the file exceeds the Read tool's token limit (25,000 by default) or a text file is over 256KB; for large files let Claude read the relevant parts itself.
  • This guide covers one small bug fix only, not parallel worktrees, subagents, scheduled tasks or non-interactive use in CI.

Verification scope

This guide is based on reading the official documentation. Login, installation, product command or API execution, file upload and generated output were not tested; the scenario and inputs in the example are original illustrations with no real run results.

Article sources

Original editorial content; official descriptions and checking suggestions are distinguished.

  1. Claude Code · Official sources
    View details