Direct answer
Keep a debugging evidence log that records a prediction before each command and the raw observation after it. Each entry has a timestamp, the exact command, the input, the output, and a classification: fact or hypothesis. Official Claude Code documentation recommends specific symptoms and visible files as useful context (F029), and the log is the structure that keeps those observations auditable. Git bisect can log the revisions marked good or bad and replay a corrected log after a reset (F028), which is the same discipline applied to history.
The log does not prove a root cause. It records what was observed, what was predicted, and where the prediction was wrong. That record survives a context switch, lets another engineer audit the reasoning, and prevents the most expensive debugging mistake: quietly rewriting a failed prediction after seeing the result.
Why debugging without a log loses the thread
A debugging session that lives in a terminal scrollback disappears the moment the window closes. The next engineer, or the same engineer the next morning, restarts from the symptom with no record of what was already ruled out. The cost is repeated experiments, re-derived context, and the specific failure where a wrong explanation survives because nobody recorded that it was tested and rejected.
Three costs follow. Experiments get repeated because the result was not captured. Wrong hypotheses survive because their disconfirming evidence was never written down. Handoffs stall because the incoming engineer cannot tell which observations are facts and which were guesses that happened to sound plausible.
| Without a log | Symptom later | With a log |
|---|---|---|
| Command run from memory | Same command rerun twice | Exact command recorded with output |
| Prediction stated verbally | Failed guess quietly forgotten | Prediction recorded before the run |
| Result summarized as “still broken” | Signal detail lost | Raw observation preserved |
| Hypothesis abandoned silently | Next reader re-investigates it | Rejection recorded with evidence |
The log is not bureaucracy. It is the difference between a session that can be audited and one that has to be trusted.
A log also changes how an investigation ends. Without one, the session closes when the engineer believes they know the cause, and belief is not a checkable state. With one, the session closes when the recorded observations support an explanation and the disconfirming evidence has been looked for and recorded. The difference shows up at handoff, where an incoming engineer can read the log and challenge the conclusion rather than accepting it on reputation. It also matters after a fix ships, because the rollback guide and the changelog guide both need a recorded explanation of what was wrong.
Start with the symptom statement
Begin the log with one paragraph that a reader can check without your environment. Name the symptom, the file or command where it appears, the environment, and when it started. This is the portion official Claude Code guidance supports directly (F029): specific symptoms and named files are useful debugging context.
A useful symptom statement answers four questions. What did you run or open? What did you expect? What happened instead, with the exact error text? What has changed recently in that area?
| Field | Example |
|---|---|
| Symptom | Import command exits 1 with ValueError on row 4 |
| Location | importer/parse.py, function parse_row |
| Expected | Row-level rejection, remaining rows imported |
| Started after | Change to the discount parsing branch |
| Environment | Runtime and package versions recorded |
The symptom statement is a fact, not an interpretation. Write what was observed before writing why it happened, because an early causal claim biases every later entry. If the symptom is intermittent, say so in the statement and record how often it reproduced during the session. An intermittent symptom that is logged as deterministic will produce a log full of inconclusive entries and no record of why.
Record the exact command and environment
Each experiment gets its command recorded verbatim, including the working directory and any environment variables that could change the result. A command paraphrased as “ran the tests” cannot be reproduced or audited. A command recorded as the full invocation with the directory can be rerun by anyone.
| Timestamp | Command | Input | Raw output | Environment note |
|---|---|---|---|---|
| 10:02 | pytest tests/test_import.py::test_row4 -x |
Fixture row4.json |
1 failed, ValueError: invalid literal |
Python 3.12, clean checkout |
| 10:05 | pytest tests/test_import.py -k row |
Same fixture | 2 passed, 1 failed | Same checkout, one flag added |
| 10:09 | git log --oneline -5 -- importer/parse.py |
None | Five commits listed | Same branch |
Pytest documentation covers how test output and logging are captured (F029 context), and capturing the raw output rather than a summary is what makes the entry useful later. Jest troubleshooting guidance makes the same point for JavaScript test failures.
Record the environment once at the top and note only deviations per entry. A deviation worth recording is a changed flag, a different checkout, a different data set, or a changed runtime version.
Write the hypothesis before running it
Before each experiment, write the prediction in one sentence: if this hypothesis is correct, this command will produce this result. The prediction must be falsifiable. “It might be a caching issue” is not a prediction. “If the response is cached, the second request will return the stale value within the cache window” is.
| Hypothesis | Prediction | Command | Confidence before |
|---|---|---|---|
| Row 4 field is not numeric | Parser raises ValueError on that field |
Run parser on a synthetic row | Medium |
| Failure is order-dependent | Test passes alone, fails in the suite | Run the single test, then the suite | Low |
| Failure began in the last commit | Reverting the commit removes it | Check out the parent revision | Medium |
Writing the prediction before the run is what separates an evidence log from a transcript. It records what you expected, which is the only way to notice later that reality disagreed. The derived practice here is to record the prediction before the command and preserve the raw observation after it (F030).
Capture the raw observation
Paste the output. Do not summarize it into a conclusion. A summary such as “test failed” loses the assertion name, the expected and actual values, and the stack frame, and those details are what the next hypothesis is built from.
| Recorded element | Why the raw form matters |
|---|---|
| Full error message | The specific exception narrows the cause |
| Assertion name | Identifies which expectation failed |
| Expected versus actual | Distinguishes a wrong value from a missing value |
| Stack frame | Points at the file and line to inspect next |
If the output is large, record the relevant section verbatim and note what was omitted. An omitted section that is never named becomes indistinguishable from an omitted section that mattered.
Redact secrets before pasting. Tokens, credentials, customer data, and internal hostnames do not belong in a log that will be shared. Replace them with placeholders and note the redaction so a reader knows what was removed.
Timestamps belong on every entry, and they should come from a single clock. An entry that records only the sequence of experiments but not when they ran cannot be correlated with deploy times, alert windows, or log retention boundaries. The timestamp is what connects the debugging log to the operational record if the investigation ever needs that context.
Classify the result without rewriting history
After the run, classify the outcome against the prediction: confirmed, disconfirmed, or inconclusive. The classification is attached to the prediction you wrote beforehand. Do not edit the prediction after seeing the result, because an edited prediction destroys the only record of what was actually expected.
| Hypothesis | Prediction | Observation | Classification | Next step |
|---|---|---|---|---|
| Row 4 field is not numeric | ValueError on that field |
ValueError: invalid literal at that field |
Confirmed | Fix the field handling |
| Failure is order-dependent | Passes alone, fails in suite | Passes both | Disconfirmed | Drop the hypothesis |
| Failure began in the last commit | Reverting removes it | Still fails after revert | Disconfirmed | Look earlier in history |
An inconclusive result is a valid outcome and should be recorded as such. It means the experiment did not discriminate between hypotheses, and the next experiment needs a sharper prediction.
The rejection table is the part of the log that saves the most time. Each rejected explanation, its disconfirming evidence, and the reason for rejection prevent the same dead end from being explored twice.
| Rejected explanation | Disconfirming evidence | Reason for rejection |
|---|---|---|
| Order-dependent test | Single run and suite run both fail | Order is not the trigger |
| Last commit introduced it | Failure reproduces on the parent revision | Commit is not the origin |
| Missing configuration | Failure reproduces with default config | Config is not required to trigger |
Link each hypothesis to the next experiment
A log is useful when each entry points at the next one. After a classification, write the next experiment and the hypothesis it tests. The chain is what makes the session resumable: a reader can start at the last entry and continue without re-deriving the earlier steps.
| Current result | Next experiment | Hypothesis it tests |
|---|---|---|
| Confirmed: field triggers it | Inspect the field-handling branch | Wrong type coercion path |
| Disconfirmed: not order | Reduce the input | Specific input shape triggers it |
| Inconclusive: both pass | Add a stronger assertion | Assertion was too weak to discriminate |
When a hypothesis survives several experiments, it earns investigation rather than more guessing. That is the point to reproduce the failure in a smaller case, which the minimal repro method covers directly. Where the surviving hypothesis involves timing or ordering, deterministic scheduling for async races is the method that makes the interleaving observable enough to log. Where the hypothesis is state leaking between cases, test fixtures that isolate shared state is the matching fix.
Ask Claude Code to challenge missing evidence
Give Claude Code the log and ask what evidence is missing before a conclusion is drawn. The useful prompt names the current leading hypothesis and asks which observation would disconfirm it. This turns the log into a review artifact rather than a private notebook.
Official Claude Code best practices recommends specific symptoms and visible files as debugging context (F029). Applied to a log, the request is: here is the symptom, here is what I have recorded, and here is the hypothesis I am about to act on. What would disconfirm it, and have I actually observed that?
Treat the answer as a lead rather than a verdict. The agent can name an unobserved disconfirming case, but it cannot run your system or know which observations are missing from the log. The value is that the gap becomes explicit before the conclusion is acted on.
| Leading hypothesis | Evidence that would disconfirm it | Recorded? |
|---|---|---|
| Field type triggers it | A non-numeric field that parses fine | Not yet |
| Only row 4 is affected | Another row with the same shape failing | Not yet |
| Recent change caused it | Failure on a revision before the change | Yes |
A hypothesis with no recorded disconfirming evidence is not yet supported, however plausible it sounds. The log makes that gap visible instead of leaving it as an assumption.
Close with the supported explanation
When the session ends, write the explanation the evidence supports and list the observations that support it. State explicitly what the evidence does not establish. A session transcript is not proof of root cause, and the closing summary should not present it as one (F030).
A closing entry has three parts. The supported explanation, with the observations that back it. The remaining uncertainty, stated plainly. The next verification, usually a test that would fail if the explanation were wrong.
| Closing element | Example |
|---|---|
| Supported explanation | Non-numeric field in row 4 reaches an int conversion without a guard |
| Supporting observations | Synthetic row reproduces; valid rows pass; revert does not fix |
| Remaining uncertainty | Whether other callers pass the same shape |
| Next verification | Regression test asserting row-level rejection |
The mutation testing guide covers whether that regression test would actually catch a reintroduction.
Worked example: an importer failure logged end to end
Suppose the import command fails on a production file. The log opens with the symptom: the command exits 1 with ValueError on row 4, in importer/parse.py, on a branch where the discount parsing changed last week.
Entry one records the hypothesis that the row 4 field is non-numeric, the prediction that a synthetic row with that shape raises the same error, and the command that tests it. The observation confirms the prediction. Classification: confirmed.
Entry two records the hypothesis that the failure is order-dependent. The prediction is that the test passes alone and fails in the suite. The observation is that it passes both ways. Classification: disconfirmed, with the rejection recorded so the hypothesis is not revisited.
Entry three records the hypothesis that last week’s commit caused it. The prediction is that checking out the parent revision removes the failure. The observation is that it still fails. Classification: disconfirmed.
Entry four follows the confirmed path. The prediction is that a three-row synthetic fixture reproduces the failure without the production file. The observation confirms it, which produces a shareable repro rather than a private case.
The closing entry states the supported explanation, the observations that back it, the remaining uncertainty about other callers, and the regression test that would fail if the guard is removed again.
The concrete win is a session that another engineer can audit and resume, with two wrong hypotheses recorded as rejected rather than silently dropped. The concrete loss is that the log took real time to write, and on a short investigation that cost can exceed the benefit. The practical implication is to keep the log for any investigation that will outlast a single sitting or that will be handed off, and to skip it only when the cause is obvious within a few commands.
Connect the method to the rest of the batch
The log is the record that other debugging methods in this batch produce. A minimal repro is usually the first entry worth recording, because a small case makes every later observation cheap. Where the failure is an ordering assumption, deterministic scheduling for async races supplies the interleaving that the log then classifies.
When the symptom is growing memory rather than a wrong value, comparing allocation snapshots provides the repeated measurement the log records. Where the failure is state leaking between cases, test fixtures that isolate shared state is usually the cause and the flaky test triage guide covers the classification before the log starts.
For history-based investigation, git bisect for regression hunts is the structured version of the same discipline. Git bisect records which revisions were marked good or bad and can replay a corrected log after a reset (F028), which is the closest built-in analog to an evidence log for commits.
The log feeds the testing work that follows a fix. Mutation testing for weak assertions checks that the regression test would catch a reintroduction, property tests for edge cases generalize the triggering input, and snapshot review prevents an unexamined approval from closing the investigation. A failure that only appears under time pressure points at deterministic handling of time and randomness as the matching control. A fix that changes what the code promises to callers belongs with contract tests for API expectations.
Surrounding disciplines keep the log honest. Selecting tests for changed code keeps each experiment fast enough to run, auditing the context already loaded keeps the investigation focused, and dead code removal removes paths that cannot be the cause because nothing calls them. Refactoring complexity hotspots addresses the structural cause when the log keeps pointing at the same dense function.
Where the log leads to a fix, atomic commits separate the investigation artifacts from the change, and commit messages that record change intent carry the supported explanation into history. Building a static analysis baseline covers the class of issues where the log is short because a tool already names the cause. When the log shows the symptom depends on a recent change, annotated release tags mark the last known-good revision for comparison.
Data gap and future update
The fact pack contains no measured reduction in debugging time from evidence logs, no benchmark comparing logged and unlogged sessions, and no evidence that Claude Code produces more accurate root-cause findings when a log is kept. No such number is claimed here.
Git bisect’s logging and replay behavior is official (F028). Claude Code documentation supports specific symptoms and visible files as debugging context (F029), not the log format itself. The prediction-before-command format is a derived practice (F030), not a built-in feature. SonarSource’s code quality guide is independent vendor guidance on the broader code-quality context, and the article uses no numerical claim from it.
A future update should add a reproducible case study comparing logged and unlogged investigations of the same defect, with time spent, hypotheses tested, and the accuracy of the final explanation. Documentation 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 the log prove a root cause?
No. A log records observations and predictions. It supports an explanation when the observations back it and disconfirming evidence is absent, but a session transcript is not proof (F030). State the remaining uncertainty in the closing entry.
How much detail belongs in each entry?
Enough to reproduce the experiment and audit the reasoning: the exact command, the input, the raw output, and the prediction made beforehand. Summaries lose the details the next hypothesis depends on.
Should failed predictions be removed?
No. Failed predictions are the most valuable entries in the log, because their disconfirming evidence prevents the same dead end from being explored twice. Rewrite a prediction after seeing the result and the record stops being trustworthy.
Is this a built-in Claude Code feature?
No. Claude Code documentation supports specific symptoms and visible files as debugging context (F029). The prediction-and-observation format is a practice you apply yourself (F030). Git bisect is the closest built-in analog for commit history (F028).
When is a log not worth keeping?
When the cause is obvious within a few commands and the investigation will not outlast the session or be handed off. The log earns its cost on investigations that span sittings, involve several rejected hypotheses, or will be reviewed by someone else.
More Claude Code troubleshooting
- Claude Code Duplication: Choose Reuse or Independence
- 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 Merge Queue: Recover Failed Groups
- Claude Code Branch Protection: Define Merge Checks
- Claude Code SemVer: Decide Major, Minor, or Patch
- Claude Code Hotfix Backports: Cherry-Pick Carefully
- Claude Code Release Checklist: Verify the Candidate
Sources
- Official: Claude Code best practices, supporting specific symptoms and visible files as debugging context (F029).
- Official: Git bisect, supporting logging marked revisions and replaying a corrected log (F028).
- Official: Git log, supporting recording the revision history relevant to an experiment.
- Official: Pytest logging, supporting capture of raw test output.
- Official: Jest troubleshooting, supporting reproduction of test failures with recorded output.
- Independent: SonarSource code quality guide, providing broader code-quality context without a numerical claim here.