Playbook: fixing a real bug with a coding agent
A six-step flow from repo context and reproduction through planning, editing and testing to review, with permission settings, a cost formula, failure modes and an acceptance list.
Prepare: fix the scope
This workflow uses stepwise review. Approval granularity and acceptance of changes depend on project authorisation and risk; these are not universal agent defaults.
- Choose a reproducible bug with steps, expected behaviour and actual behaviour.
- Restrict access to the repository rather than the home directory; exclude credentials from readable paths.
- Specify exclusions: unrelated modules, dependency upgrades and CI changes.
- Run baseline tests and retain passing/failing results for comparison.
If work spans modules or becomes difficult to review, split it by cause and impact. File counts can signal scope change but are not a universal stopping threshold.
Reproduce first
- Supply reproduction commands, logs and relevant paths.
- Request a cause hypothesis and a way to test it before editing.
- For multiple hypotheses, start with a low-cost discriminating check.
Failure mode: a plausible patch without reproduction can pass review while missing the root cause.
Plan in three parts
Request three parts:
| Part | Contents | Evidence |
|---|---|---|
| Root cause | File, line and why it fails | Confirmed by reproduction |
| Change | Scope, exclusions and impact | Affected tests listed |
| Rollback | How to revert if needed | Explicit command or patch |
Exclude unrelated refactoring and incidental improvements from the bug-fix scope.
Edit with permissions
- Terminal agent: inspect execution approvals and allow specific commands rather than an unrestricted shell.
- IDE agent: inspect inline diffs and accept the intended changes deliberately.
- Cloud agent: obtain a draft PR and run the necessary checks during handoff.
For this review policy, file deletion, database changes, remote pushes and global package installation require explicit approval.
Three pieces of evidence
- The original failing case now passes.
- Relevant regression tests still pass.
- The original bug-report steps produce the intended behaviour.
Select regression and acceptance checks for the change's risk, and record checks that were not executed.
Review with a second pass
- Review a change summary, risks, uncovered cases and the actual diff.
- Inspect error handling, boundaries, logs/privacy and new dependencies.
- Keep root-cause repair separate from broader cleanup when review scope requires it.
Cost formula
Use rates from the applicable official billing page:
Model cost = sum over calls of
(input tokens × input rate + output tokens × output rate) / 1,000,000
Total cost = model cost + actual tool cost + review and other costs
Input tokens include repository context, logs and conversation history.
Rates are per million tokens; separate cached input at its applicable rate and include retries in actual calls. Provide necessary files/logs while preserving reproduction evidence. A subscription is not an API quota. Record assumptions in the cost calculator.
Dated facts and limits
- Claude Code CLI has a separate CHANGELOG/Atom feed and configurable permissions; source is visible but licensed All rights reserved (repository; October 2026 snapshot).
- Codex CLI is implemented in Rust, with app-server architecture and thread continuation (repository/releases; October 2026 snapshot).
- Gemini CLI supports non-interactive scripting and MCP for CI workflows (repository; October 2026 snapshot).
- Context and task limits vary by tier; use current official documentation rather than treating an interface snapshot as a promise.
Acceptance checklist
- [ ] Reproduction recorded and failing before the change.
- [ ] Root cause stated and confirmed.
- [ ] Only planned files changed.
- [ ] Original case and relevant regressions pass.
- [ ] Original steps checked again.
- [ ] No secrets, unrelated dependencies or CI changes added.
- [ ] A second review pass records risks.
- [ ] Rollback described in the PR.
Failure modes
- Scope creep: fixing A while changing unrelated B increases review work.
- No reproduction: a patch is proposed without demonstrating failure.
- Test substitution: tests are changed to accept the bug rather than repair it.
- Broad permissions: allowing the whole shell expands unintended execution scope.
- Context disclosure: credentials or production logs are pasted into the conversation.
Worked example: an empty list crashes a page
This fictional minimal case illustrates a repair record; it is not a project executed by this site.
Input and failure: a page reads items[0].title; items=[] fails. Expected behavior is an empty state, while populated lists still show the first title.
Reproduce with empty, single-item and multi-item lists. Establish the original failure and baseline behavior.
Scope: handle the empty list before reading its first item. If the interface also permits null or missing fields, document those inputs separately instead of silently widening the contract.
Required evidence: an empty state for no items, unchanged rules for populated lists and absence of the original error. These are acceptance requirements, not reported test results.
If failure remains, inspect the actual input and error location rather than piling on defaults. Deliver reproduction inputs, changes, validation results and uncovered cases.
Sources
| Source | URL |
|---|---|
| Anthropic: Claude Code repository (permissions and CHANGELOG; October 2026 snapshot) | https://github.com/anthropics/claude-code |
| OpenAI: Codex CLI repository (thread continuation and app server; October 2026 snapshot) | https://github.com/openai/codex |
| Google: Gemini CLI repository (non-interactive mode and MCP; October 2026 snapshot) | https://github.com/google-gemini/gemini-cli |
| Anthropic: Claude Code documentation (permissions and workflows; October 2026 snapshot) | https://code.claude.com/docs/en/overview |
Source snapshot: 2026-11-03; item-specific rechecks and their scope are recorded in the text or source notes. Features and terms may change; check the original sources before use.
This page appears in: Write code with AI · Make games with AI · Use AI well