CLAUDE.md Repository Instructions for Bug Fixes
Use CLAUDE.md repository instructions to keep bug fixes scoped, define approval boundaries, and give reviewers a clear account of changes.
- claude-md
- claude-code
- repository-instructions
- code-review
A stock-reservation bug fix shouldn't quietly rewrite a database migration that's already shipped. In the illustrative repository below, that distinction is the difference between an acceptable patch and a change that needs a separate design decision. Your CLAUDE.md repository instructions should make that boundary explicit before Claude starts editing.
The useful question is what decisions the file should settle: which behavior must survive, which changes need approval, and what evidence you expect with the patch. Start with those decisions, then write the commands and conventions that support them.
Define the Decisions Before You Write#
CLAUDE.md contains persistent instructions for Claude Code. Anthropic's project memory documentation describes how these files supply project instructions across sessions.
For a bug-fix workflow, use this table as your first drafting pass. The examples describe a fictional stock service; replace its paths and rules with yours.
| Decision | Useful repository instruction | What the reviewer can check |
|---|---|---|
| Where behavior belongs | Keep reservation validation in src/stock/reserve.ts; route handlers translate requests and responses. | The patch preserves the existing responsibility split. |
| What must remain true | A rejected reservation must leave stock unchanged. | The regression test checks both the rejection and remaining stock. |
| What needs approval | Ask before changing schema, public response fields, or dependency versions. | Any expansion has explicit approval. |
| What to do when blocked | Report missing test prerequisites; don't replace database-backed tests with mocks to claim success. | The final report distinguishes executed checks from blocked checks. |
| What to report | Name changed behavior, checks run, and unresolved risks. | The report matches the diff and command results. |
You don't need a complete description of the repository to answer these questions. You need enough policy to distinguish a valid fix from an adjacent change nobody requested.
Turn Review Corrections Into Usable Rules#
Start with corrections you've actually made in review. A recurring comment such as “this bypasses the transaction helper” is a stronger candidate than a general preference such as “keep the code clean.” The former identifies a decision Claude needs to make.
1. Name the decision that went wrong.
Suppose a patch updates stock directly from src/http/reservations.ts. The problem isn't simply that Claude edited the wrong file. The route now owns behavior that your repository expects the stock service to control.
Write the rule around that boundary: reservation checks and stock updates belong in src/stock/reserve.ts; HTTP handlers should call that service. This gives Claude a destination as well as a restriction.
2. Add the condition that activates the rule.
“Use transactions” is underspecified. In this example, write: “When a reservation reads availability and changes stock, perform both operations through withStockTransaction.” Point to the actual helper, such as src/db/stock-transaction.ts.
The condition matters. You probably don't want every read-only endpoint wrapped in a new transaction merely because the instruction used an absolute verb.
3. State the reason briefly.
Add one sentence: “The availability check and stock update must succeed or fail together.” Keep the longer explanation in the relevant design document.
That reason gives the reviewer something to evaluate if a future implementation replaces the helper. The desired property survives even when the current function name doesn't.
4. Specify what happens when the rule blocks progress.
Write: “If the fix appears to require changing this transaction boundary, explain the proposed change and ask before editing it.” Without an exception path, you're leaving the next decision unresolved.
Keep each rule focused. A paragraph that mixes transaction boundaries, formatting preferences, release instructions, and test output is hard to apply to a specific edit. Split it by decision, then remove anything your formatter or type checker already handles adequately.
Start With a Bug-Fix Instruction File#
Use the following as an illustrative policy for the stock service. It assumes the named files exist and that scripts/check-stock.sh is your repository's verified, non-interactive stock check. Don't copy the command into a real repository until you've confirmed that contract.
# Repository instructions
## Scope of bug fixes
- Implement the requested behavior change and its regression coverage.
- Keep unrelated refactors, dependency upgrades, and formatting sweeps
out of the patch. Report useful follow-up work separately.
- Before editing, inspect the working tree. Leave unrelated user changes
untouched and report overlaps with the requested work.
## Stock reservation boundaries
- Reservation validation and stock updates belong in
src/stock/reserve.ts. HTTP handlers call this service.
- When reading availability and changing stock, use withStockTransaction
from src/db/stock-transaction.ts for both operations.
- A rejected reservation must leave stock unchanged.
- Read tests/stock/reserve.test.ts before changing reservation behavior.
## Changes that require approval
- Ask before changing database schema, public response fields,
dependency versions, or transaction boundaries.
- Do not edit previously released files under db/migrations/.
- If a requested fix conflicts with these instructions, identify the
conflict and ask for clarification before crossing the boundary.
## Verification
- Run ./scripts/check-stock.sh from the repository root.
- Add regression coverage for the reported defect.
- Keep existing assertions unless the requested behavior change
explicitly makes them obsolete; explain any changed expectation.
- If a prerequisite is missing, report the blocked check and its cause.
Do not describe a blocked check as passed.
## Documentation and completion
- Review docs/stock-reservations.md if caller-visible behavior changes.
- Do not edit these instructions merely to permit the current fix.
- Report changed behavior, checks executed and their results,
checks not executed, and unresolved risks.
- Leave committing, pushing, and merging to the human unless explicitly
requested for this task.
The section names are your organization choice. The important content is the relationship between a trigger, an action, and a boundary.
Notice what this example leaves out: a directory-by-directory tour, the history of the stock system, and a restatement of the language's style guide. Those details don't help decide whether the patch is within scope.
Human-facing documentation can explain why reservation failures leave stock unchanged. The instruction file tells Claude to preserve that property and where to work. For the broader distinction between instructions and reference material, see the context engineering guide.
Also distinguish a command from permission to execute it. Listing a check establishes the expected verification step; it doesn't grant unrestricted access to a database or authorize changes to the execution environment.
Give Exceptions a Clear Approval Path#
A useful approval rule names the change that requires a decision. “Ask when unsure” puts the entire burden on Claude's interpretation of uncertainty. Prefer boundaries you can recognize in a diff: a schema edit, a new dependency, a public response change, or a transaction boundary change.
For the stock example, a suitable request would look like this:
The requested fix appears to require a new database constraint.
That crosses the repository's schema-change approval boundary.
Proposed expansion:
- Add a new migration; leave released migrations unchanged.
- Add coverage for invalid reservation quantities.
Can I expand the task to include this schema change?
You can approve that expansion, reject it, or ask for an application-only alternative. Keep the approval attached to the specific proposal. “Go ahead” shouldn't become permission for unrelated dependency or deployment changes later in the session.
There is an important limit here: Anthropic describes CLAUDE.md as context rather than enforced configuration. A sentence in the file isn't a technical access control.
Use Claude Code's permission controls to control tool access, and keep repository instructions focused on the engineering reasons for those boundaries. Permission rules and instruction prose have different jobs.
For example, your instruction can require approval before a schema change while your execution environment withholds production credentials entirely. Don't make the prose carry both responsibilities.
Catch the Failure Hidden Behind Passing Tests#
Consider a less obvious failure: the patch follows “run the stock checks” by making the checks easier to pass.
In the illustrative service, an existing test checks that rejecting an oversized reservation leaves stock unchanged. Claude changes the implementation, encounters a failure, and removes the stock assertion. The test still verifies an error response. The command exits successfully. The property you cared about has disappeared from the evidence.
“Always make tests pass” leaves this decision underspecified. Add a rule that preserves existing assertions unless an approved behavior change makes them obsolete. Require an explanation when an expectation changes.
Avoid the opposite absolute rule, “never change existing tests.” A legitimate bug fix may require correcting a test that captured the defect. The question is whether the changed expectation follows from the requested behavior.
For a negative-quantity bug, your intended result might be:
Requested behavior:
Reject a reservation quantity below one.
Required evidence:
The request is rejected, and available stock is unchanged.
Unrelated behavior to preserve:
Valid reservations still reduce stock by the requested quantity.
That gives you a concrete basis for reviewing both implementation and test edits. It also prevents a vague instruction such as “add coverage” from standing in for a decision about what the coverage must establish.
Apply the same reasoning to the final report. Ask for commands and outcomes rather than a blanket statement that everything passed. If the database-backed check couldn't run, you need that fact before deciding what else must happen before merge.
Try One Fix Before You Merge the Instructions#
Your practical next step is a bounded trial of the instructions. Pick a small defect with a clear expected result. Keep the task description focused on the defect so you can see whether the repository policy supplies the working boundaries.
1. Write the task without repeating the policy.
For this example:
Fix stock reservations so quantities below one are rejected.
Add regression coverage. Preserve valid reservation behavior.
Explain the completed change and verification results.
Don't also remind Claude about every migration, transaction, and reporting rule in the file. You want to evaluate whether those instructions help with an ordinary request.
2. Inspect the resulting patch before accepting the explanation.
For an illustrative trial branch whose changes are committed, compare it with its base branch. Here, the base is origin/main:
git diff --name-only origin/main...HEAD
git diff origin/main...HEAD -- src/stock tests/stock db/migrations CLAUDE.md
Git documents this three-dot comparison as changes on the branch since its common ancestor with the other commit. The first command lists changed paths; the second limits the patch display to the relevant paths. Inspect any uncommitted work separately.
Look for the decisions your policy was meant to settle. Did validation stay in the stock service? Did an old migration change? Did the patch preserve the assertions that establish unchanged stock after rejection?
3. Correct the ambiguous instruction.
If Claude changed a public error field because “reject invalid quantities” didn't specify compatibility, add the missing boundary. If Claude stopped unnecessarily because “never change database code” was too broad, narrow that prohibition.
Don't respond to every disappointing result with another paragraph. Replace weak wording where possible. Ask the human reviewer to check that the revised rule reflects an actual team decision before merging the instruction change.
A successful trial gives you a useful starting point. It doesn't establish that every later task will follow the policy.
Keep Supporting Detail Out of the Policy#
When drafting a rule, you may need a fuller explanation of the implementation before deciding what Claude should preserve. Keep that investigation separate from the policy decision itself.
Moxie Docs generates documentation from GitHub repositories, updates it as code changes, and provides repository context over MCP. Generated documentation, updates on merge, and MCP context are available on every plan. Weekly automation is available on Pro and Team.
An illustrative workflow is to use the free plan to inspect repository explanations while you draft the stock transaction rule. Compare the explanation with the implementation, then have the responsible engineer approve the instruction. Documentation can describe the existing transaction path; your team must decide whether changes to that path require approval.
Keep that distinction explicit when documentation changes are proposed, too. Cleanup PRs are proposed changes for human review. A human decides whether to merge them.
For this instruction file, the useful output is a short behavioral rule and a route to supporting detail. Don't paste an entire generated explanation into CLAUDE.md merely because it is available.
The short version#
Pick one correction you repeatedly make in bug-fix reviews and turn it into a conditional instruction: when this situation occurs, take this action, preserve this property, and ask before crossing this boundary. Try it on a small fix, inspect the patch, and have the responsible engineer approve the wording. Leave rules without a clear decision to govern out of the file.
FAQ#
What should Claude do when a bug fix needs a schema change?#
Require Claude to stop at the approval boundary, explain why the schema change appears necessary, and name the proposed expansion. In the stock example, that means proposing a new migration while leaving released migrations untouched. A human must approve the expanded scope before the work proceeds.
Can Claude change an existing test during a bug fix?#
Yes, when the requested behavior makes the existing expectation obsolete. Require an explanation of that change and inspect the assertion itself. For the negative-quantity fix, correcting an expectation that allowed invalid quantities may be appropriate; removing the unchanged-stock assertion would discard evidence the fix still needs.
What should the completion report say if a required check couldn't run?#
Name the check, the missing prerequisite, and what remains unverified. Report any narrower checks separately. If ./scripts/check-stock.sh requires an unavailable database, a passing unit test doesn't establish that the database-backed check passed. The reviewer decides what verification is still required before merge.
Should a bug fix also update CLAUDE.md?#
Only when the task exposes an instruction that is wrong or ambiguous and a human approves the correction. Don't let the patch rewrite a boundary merely to make its own changes permissible. Explain the instruction change separately so the reviewer can distinguish a policy decision from the implementation fix.
Republish or cite this article
You're welcome to republish this piece in full or in part. We just ask that you credit the original with a link back. See our republishing guidelines.
Attribution snippet
<p>This article was originally published on <a href="https://moxiedocs.com/blog/claude-md-repository-instructions">Moxie Docs</a>.</p>Cite this article
The Moxie Docs team. "CLAUDE.md Repository Instructions for Bug Fixes." Moxie Docs, December 3, 2026, https://moxiedocs.com/blog/claude-md-repository-instructions.
Read next
How to Write the Perfect CLAUDE.md File for Claude Code
Claude Code relies on a CLAUDE.md file for instructions on build, test, and style conventions. Learn how to write, structure, and maintain a perfect CLAUDE.md that keeps your AI agent on track.
CLAUDE.md Docs: A Drift-Detection Checklist
Keep CLAUDE.md instructions accurate with source checks, documentation drift detection, and a reviewable GitHub workflow.