MISTAKES.md with Claude Code: Turning Repeat Failures into Project Rules
How to maintain a lightweight MISTAKES.md for Claude Code: recording incidents, isolating secrets, defining recurrence thresholds, and turning failures into automated tests.
When working with Claude Code on complex repositories, the agent will inevitably run into non-obvious environment quirks: outdated TypeScript definitions, hidden runtime dependencies, or bundler-specific behaviors. Fixing the same mistake repeatedly in chat wastes context and time. Conversely, dumping multi-page session transcripts into instructions causes prompt clutter and degraded model attention.
A practical pattern is maintaining a lightweight MISTAKES.md in your repository root. It records only reproducible incidents, verified causes, and prevention actions, which are subsequently promoted into project tests, linter rules, and persistent configuration.
1. MISTAKES.md vs. Session Transcript
Do not confuse an incident log with a raw terminal transcript:
MISTAKES.md must stay concise so that Claude Code can ingest it at the start of a session without consuming excessive context tokens.
2. Anatomy of an Incident Record
Every incident entry contains four required fields:
- Incident: Exactly what broke and under what conditions (error code, command, tool).
- Impact: Downstream effect (build broken, migration corrupted, test suite aborted).
- Root Cause: Confirmed technical source. If unproven, explicitly mark as
[Hypothesis]. - Prevention: Concrete rule or check preventing recurrence.
Example Incident Record
ERR-014: PostgreSQL Migration Failed on DROP COLUMN without CASCADE
- Incident: Claude Code executed
ALTER TABLE orders DROP COLUMN customer_ref;in migration 0042. - Impact: Staging deployment failed due to dependent view
v_active_orders. - Root Cause: Views referencing base tables require explicit cascade recreation or prior view updates.
- Prevention: All DDL column removal migrations must check dependent views via
pg_dependbefore execution.
3. Promotion Threshold: From Log to Test or Rule
Not every one-off typo deserves a permanent rule. Promote entries into automated gates using a clear threshold:
- First occurrence: Add a concise record to
MISTAKES.md. - Second occurrence (Recurrence): If the issue can be caught deterministically, write a test or linter rule. Automated gates outperform textual prompts.
- Non-mechanical checks: Formulate an explicit negative rule in
CLAUDE.md(e.g., "Never run jest without --runInBand in CI"). - Archiving: Once a test or hook is deployed, archive or remove the entry from
MISTAKES.mdto prevent file bloat.
4. Verifying on the Next Task
To confirm the new guardrail works:
- Start a fresh Claude Code session.
- Provide a prompt that previously triggered the failure.
- Inspect whether the agent respects the new rule or is stopped by the pre-commit hook.
- If the agent bypasses text instructions, convert the constraint into a strict command wrapper or automated check.
This feedback loop turns random development failures into a robust, self-improving engineering foundation.