Direct answer
Before asking Claude Code to fix a bug, shrink the failure to the smallest case that still reproduces it. Write the observed and expected behavior first, freeze the original commands and inputs so the case is comparable later, then remove one irrelevant element at a time and rerun after each removal. A reproduction is not a root-cause diagnosis; it is a stable signal that makes the fix reviewable.
The payoff is a case another engineer can run in seconds and a diff that isolates one behavior. The cost is the reduction time, which is usually shorter than the debugging time it replaces. Official Claude Code best practices recommends naming files and describing symptoms when investigating a bug (F025), and a minimal repro is the strongest form of that description.
Why an unreduced failure wastes the fix
A bug reported as “the importer fails on this 40 MB file” carries the trigger and a large amount of noise in the same package. The engineer or the agent reading it must first find which part of the input matters, and every attempted fix has to be validated against the whole heavy case. That validation is slow, and slow validation means fewer fix candidates get tried.
Reduction changes the shape of the problem. A case that reproduces with three rows, one config flag, and one command can be reasoned about directly, and a fix can be checked in seconds. The reduced case also survives handoff, because the next reader does not need the original production payload to see the failure.
Three failure modes appear without reduction. The fix addresses a symptom that the full case shares with an unrelated cause. The fix cannot be verified quickly, so the team ships it on faith. The case never gets shared outside the original reporter because the payload is too large or too sensitive to attach.
| Unreduced case | Cost during the fix | Reduced equivalent |
|---|---|---|
| 40 MB import file | Every run takes minutes | Three rows that trigger the same parse error |
| Full config with twenty flags | Unclear which flag matters | One flag flipped from the default |
| Whole request log | Sensitive data risk | One request shape without payloads |
| Intermittent failure in a long suite | Slow, ambiguous signal | One test that fails deterministically |
The reduction discipline is the same across those cases: preserve the signal, remove the noise, and record each step.
Write the observed and expected behavior
Start with two sentences. The observed sentence describes what actually happened, with the exact error, exit code, or wrong value. The expected sentence describes what the system should have done instead. Both belong in the repro before any code is written.
An observed sentence that says “it breaks” is not usable. An observed sentence that says “the import exits with code 1 and logs ValueError: invalid literal for int on row 4” gives a reviewer something to check. The expected sentence should be equally concrete: “the import should reject row 4 with a row-level error and continue processing the remaining rows.”
| Component | Weak version | Stronger version |
|---|---|---|
| Observed | Import fails | Import exits 1 with ValueError on row 4 |
| Expected | Should work | Row-level rejection, remaining rows imported |
| Trigger | This file | Three-row fixture with a non-numeric field in row 4 |
| Environment | Our staging | Python 3.12, importer version recorded in the repro |
Claude Code best practices recommends specific symptoms and visible files as useful debugging context (F029). The observed and expected pair is that recommendation applied to a reproducible case, and it does not establish cause on its own.
Freeze the original commands and inputs
Before reducing anything, record the exact commands, inputs, versions, and environment that produced the failure. This frozen case is the baseline. Every reduction is compared against it, and if a later reduction loses the signal you return to the frozen case rather than to a memory of it.
Freezing means recording enough to reproduce without the original artifact. Commit the commands to a file in the repository, capture the relevant configuration, and record the versions of the runtime and the dependencies involved. The frozen case is the reference against which the reduced case is judged equivalent.
| Frozen artifact | What to record | Why it matters later |
|---|---|---|
| Command line | Exact invocation and working directory | Reductions use the same entry point |
| Input data | The file or payload, or a faithful stand-in | Proves the reduction still triggers |
| Versions | Runtime, package, and tool versions | Rules out environment drift |
| Configuration | Relevant flags and environment variables | Prevents a fix that only works without them |
The frozen case also protects against a subtle error: fixing the bug in a way that only works because a needed input was removed during reduction. Comparing against the frozen baseline catches that.
Remove one irrelevant element at a time
Reduction works by removing one thing, rerunning, and keeping the removal only if the failure still reproduces. Remove a second element only after the first is settled. Batching removals hides which one mattered and can lose the signal entirely.
| Original input | Removed element | Reproduction result | Decision |
|---|---|---|---|
| 10,000-row file | Rows after row 10 | Fails | Keep the removal |
| 10-row file | Rows before row 4 | Passes | Restore rows before row 4 |
| 10-row file | Non-numeric field in row 4 | Passes | Field is the trigger, restore it |
| Two config flags flipped | Second flag | Fails | Second flag is irrelevant |
| Custom retry wrapper | Wrapper around the call | Fails | Wrapper is irrelevant |
The sequence produces a chain of decisions rather than a guess. Each row in that table is evidence that the remaining case is equivalent to the frozen baseline for the purpose of reproducing this failure.
Hypothesis and similar property-based tools automate a related search: they shrink a failing generated input toward a smaller one that still fails. The manual method here applies the same idea to a hand-reported case (F027). The property tests guide covers the automated version in detail.
Confirm the failure still reproduces
Rerun the frozen repro after every reduction. A smaller case that no longer fails is not a reduction; it is a different case. The confirmation step is what separates reduction from deletion.
Record the reproduction result for each candidate removal, including the ones you reject. A rejected removal that later looks tempting has already been tested, and the record prevents repeating the same dead end.
| Reduction step | Command | Result | Signal preserved |
|---|---|---|---|
| Baseline (frozen) | Recorded command | Fails as observed | Baseline |
| Remove rows after 10 | Same command, smaller file | Fails | Yes |
| Remove config flag 2 | Same command, one flag | Fails | Yes |
| Remove row 4 field | Same command, valid row | Passes | No, restored |
If a removal produces an intermittent result instead of a clean pass or fail, stop reducing and stabilize the signal first. A reduction on top of a flaky signal produces a repro that cannot be trusted, and the time spent is lost.
Separate setup noise from the trigger
Some of what surrounds a failure is setup, not cause. A repro that requires a full application boot to reach a parser bug carries setup noise that the fix does not need. Separating the trigger from the setup makes the repro cheaper and the failure clearer.
Ask which parts of the setup the failure actually depends on. A parser bug usually needs the parser and its input, not the HTTP server that delivers the input. A permission bug may need the auth layer and a specific role, not the whole middleware chain. Each dependency that can be removed without losing the signal is noise for this investigation.
| Repro component | Purpose | Required dependency | Safe to share |
|---|---|---|---|
| Three-row fixture file | Carries the trigger | Parser only | Yes, synthetic data |
| Direct parser invocation | Reaches the failing code | Runtime and package | Yes |
| Original import command | Historical context | Full application | Document, do not require |
| Config with one flag flipped | Reproduces the setting | Config reader | Yes, no secrets |
Removing setup noise can change the observed error text. When that happens, record both the original error and the reduced error, and state that they correspond to the same underlying failure. A reviewer comparing the repro to the original report needs that mapping.
Package the repro without secrets
A repro is meant to be shared. Package it so another engineer can run it without access to your environment and without exposure to credentials, personal data, or proprietary payloads. Replace real customer data with synthetic values that preserve the shape that triggers the failure.
| Included in the package | Excluded from the package |
|---|---|
| Observed and expected sentences | Credentials and tokens |
| Frozen and reduced commands | Customer records and personal data |
| Synthetic fixture with the trigger shape | Proprietary payloads |
| Versions and relevant configuration | Internal hostnames and endpoints |
| The exact error text | Full logs with sensitive fields |
Review the package before sharing it. A repro that leaks a token or a customer record in the process of reporting a bug replaces one problem with a worse one. When a secret must be referenced, replace it with a placeholder and document the placeholder in the repro.
The packaging step is also where the repro becomes durable. A case stored in the repository next to the code it exercises survives long after the original report is closed.
Ask Claude Code to predict the next reduction
Give Claude Code the frozen case and the current reduced case, and ask which single element it predicts can be removed without losing the failure. Then run that removal and compare the result to the prediction.
The value of the prediction is not that it is always right. The value is that a wrong prediction identifies a dependency the investigation had not named, which is exactly the kind of assumption worth surfacing. Record the prediction and the outcome alongside the reduction table.
Official Claude Code best practices recommends naming files and describing symptoms during investigation (F025). The prediction step applies that advice to the reduction itself: name the file or element, state the predicted outcome before running, and compare against the observed result.
| Element proposed for removal | Prediction | Observed | Interpretation |
|---|---|---|---|
| Config flag 1 | Still fails | Still fails | Correct, element is irrelevant |
| Helper validation call | Still fails | Passes | Wrong, call is on the path |
| Second fixture row | Still fails | Still fails | Correct |
A pattern of wrong predictions on one area suggests that area is part of the trigger and should be investigated directly.
Keep the original case for comparison
Never delete the only failing case before preserving it. The frozen original stays available even after the reduced repro is accepted, because the fix has to be validated against both. A fix that passes the reduced case and fails the frozen case is not a fix.
Keep the original in whatever form avoids the sensitive-data risk: a synthetic stand-in with the same trigger shape, a recorded command against a sanitized fixture, or a description precise enough to reconstruct. Git history helps here. Recording the frozen case in a commit or a branch makes it comparable later, and git show can retrieve the exact recorded state when the fix is reviewed (F026).
The original case also protects against a fix that works for the reduced case and regresses a related shape that only the original covered. Comparing both after the fix is cheap compared to discovering the regression in production.
Worked example: an importer row error
Suppose an import command fails on a production file with a ValueError on row 4, and the file cannot be shared because it contains customer records. The observed sentence is that the command exits 1 with that error on row 4. The expected sentence is that row 4 is rejected with a row-level error and the remaining rows import.
Freeze the original: record the command, the file size, the runtime version, and the two flipped config flags. The original is preserved as a sanitized description because the file itself cannot be shared.
Reduce one element at a time. Remove rows after row 10; the failure reproduces. Remove rows before row 4; the failure disappears, so rows before row 4 are restored as context. Remove the non-numeric field in row 4; the failure disappears, so that field is the trigger. Replace the customer values in the three remaining rows with synthetic equivalents that keep the same shape; the failure reproduces on synthetic data.
Flip back the second config flag; the failure still reproduces, so that flag is irrelevant. Flip back the first flag; the failure disappears, so the first flag is part of the trigger and stays in the repro.
The final repro is three synthetic rows, one flipped flag, and a direct invocation of the parser. It runs in under a second and contains no customer data. After the fix, both the reduced repro and the sanitized original are validated.
The concrete win is a case that another engineer can run in seconds and share without a data-risk review. The concrete loss is that the reduced case needed the frozen baseline to prove equivalence, and a reduction without that baseline could have quietly fixed the wrong variant. The practical implication is to reduce before requesting a fix, keep the frozen case alongside the reduced one, and treat the repro as a stable signal rather than as a diagnosis.
Connect the method to the rest of the batch
A minimal repro is the input to most other debugging work in this batch. Once the case is small, the debug log that separates facts from hypotheses records the prediction and observation for each reduction step. Where the failure involves ordering, deterministic scheduling for async races covers making the interleaving explicit, and test fixtures that isolate shared state covers removing setup leakage from the repro itself.
When the bug is a resource leak rather than a wrong value, comparing allocation snapshots provides the measurement method, and the same reduce-and-compare discipline applies to the workload. When the failure is a wrong value that only appears under concurrency, deterministic scheduling for async races makes the interleaving reproducible before reduction starts.
For finding where the failure entered the codebase, git bisect for regression hunts is the adjacent workflow. It also depends on a known good and bad state and a stable classification check (F026), which is the same need for a stable signal that reduction serves.
The repro often becomes a regression test. Mutation testing for weak assertions checks that the new test would actually fail against a mutant, and snapshot review prevents the new case from being approved without inspection. Where the trigger is a boundary value, property tests for edge cases generalize the case automatically, and deterministic handling of time and randomness applies when the original failure was timing-dependent. For an investigation that touches many files, auditing the context already loaded keeps the reduction focused on the failing path.
Investigation quality depends on the surrounding context. Auditing the context already loaded keeps the reduction focused, selecting tests for changed code keeps the validation fast, and dead code removal removes paths that cannot be part of the trigger because nothing calls them. When a repro depends on an interface promise, contract tests for API expectations turns the expected sentence into an enforced check, and test fixtures that isolate shared state keeps the repro’s setup from leaking.
Fixes should land reviewably. Atomic commits keep the repro and the fix in separate revertible changes, commit messages that record change intent explain why the case was reduced this way, and the release checklist decides whether the repro becomes a permanent regression gate. Where the fix rides a merge queue, failed merge queue groups explains why a repro that fails only under concurrency can block a group.
Where the fix tightens validation at a public boundary, check it against semantic versioning decisions and branch protection and merge checks so the new rejection actually gates future changes.
Data gap and future update
The fact pack contains no measured reduction in debugging time from minimal repros, no benchmark comparing reduction strategies, and no evidence that Claude Code consistently shrinks failures faster than manual reduction. No such number is claimed here.
Claude Code best practices supports naming files and describing symptoms during investigation (F025). Git bisect depends on known good and bad states and a stable classification check (F026), which is the related but separate workflow. The one-element-at-a-time reduction method is a derived debugging practice (F027), not an official Claude Code command, and Hypothesis provides the automated analog rather than a measured comparison.
A future update should add a reproducible case study with reduction step counts, time spent reducing versus time spent debugging the unreduced case, and the resulting regression test. Tool-specific shrinking behavior changes over time; recheck the cited pages before publishing.
One AI API Key option for OpenAI-format agents
Claude Code uses an Anthropic-format route, so the One AI free model IDs are not a Claude Code model source. The packet records Claude IDs as unavailable on 2026-11-27.
For a separate OpenAI-format agent, One AI API Key provides https://api.oneaiapikey.com/v1, one key, and 46 live free IDs. That option concerns a different client and request format, not a workaround for Claude Code authentication or quota. Review the free model list and eligibility details before choosing an agent route.
FAQ
Does a minimal repro count as a diagnosis?
No. A repro establishes that a failure exists under stated conditions. It does not identify the cause. Treating a reproduction as a root-cause explanation is the specific mistake this method is designed to avoid.
How small should a repro be?
Small enough to run in seconds and share without sensitive data, and no smaller. Over-reduction can produce a case that no longer represents the reported failure, which is why the frozen original is kept for comparison.
Why remove only one element at a time?
Removing several elements at once hides which one mattered. If the failure disappears, you do not know which removal fixed it; if it survives, you do not know whether an unrelated trigger remains. One at a time produces a decision record.
Can Claude Code do the reduction automatically?
It can propose the next element to remove and run the reduction with you. The evidence pack contains no measurement that this is faster than manual reduction, so no speed claim is made. The prediction step is useful mainly because a wrong prediction exposes an unnamed dependency.
What if the failure is intermittent?
Stabilize the signal before reducing. A reduction performed on top of a flaky failure produces a case that cannot be trusted to reproduce, and the flaky test triage guide covers that classification first.
More Claude Code troubleshooting
- Claude Code Complexity: Refactor Hotspots, Not Metrics
- Claude Code Duplication: Choose Reuse or Independence
- Claude Code Static Analysis: Baseline the Noise
- Claude Code Git Stash: Recover Work Without Dropping It
- Claude Code Git Rebase: Choose a Branch Policy
- Claude Code Merge Conflicts: Resolve Behavior, Not Lines
- Claude Code Release Tags: Use Annotated Markers
- Claude Code Hotfix Backports: Cherry-Pick Carefully
- Claude Code Rollback: Plan a Revert Before Release
- Claude Code Changelog: Write Consumer-Facing Changes
Sources
- Official: Claude Code best practices, supporting naming files and describing symptoms during investigation (F025).
- Official: Git bisect, supporting the known good and bad states and stable classification check (F026).
- Official: Git show, supporting retrieval of a recorded revision for comparison.
- Official: Jest troubleshooting, supporting reproduction of test failures with reduced cases.
- Official: Pytest logging, supporting capture of the observed failure output.
- Independent: Hypothesis documentation, supporting automated shrinking of failing inputs as the related method.