← Back to all entries
2026-06-27 💡 Tips 'n' Tricks

Prompts That Survive Compaction & Self-Verifying Refactors

Prompts That Survive Compaction & Self-Verifying Refactors — visual for 2026-06-27

💡 Writing Instructions That Still Hold After Context Compaction

Long Claude Code sessions eventually trigger context compaction — older conversation turns get summarised to make room for new work. Most of the time this is invisible, but instructions given casually early in a session ("also, never touch the migrations folder") can get lost or diluted in the summary if they weren't stated as a durable rule. The fix isn't to avoid long sessions — it's to put anything genuinely load-bearing somewhere compaction can't quietly drop it.

A simple test

Before a long unattended run, ask: "if this session's context got compacted right now, would the rule I care about survive?" If the honest answer is "maybe," it belongs in CLAUDE.md instead of a passing comment.

⭐⭐⭐ code.claude.com
context compaction CLAUDE.md long sessions durable constraints Claude Code

💡 Structuring Multi-File Refactors So Claude Checks Itself as It Goes

Large refactors that touch dozens of files are where agentic coding tools are most valuable — and where silent drift is easiest to miss if verification only happens at the very end. A more reliable pattern: break the refactor into checkpoints where Claude runs the test suite (or a narrower relevant subset) after each meaningful chunk, not just once at the finish line.

Why end-of-run verification isn't enough

If a 40-file refactor only gets tested after all 40 files are touched, a mistake introduced in file 3 is indistinguishable from one introduced in file 38 by the time you're debugging the failure — you've lost the information about where things went wrong. Checkpointed verification (test after every 5-10 files, or after every logically complete unit) keeps failures small and localised, which is dramatically faster to fix than untangling a single large failure at the end.

⭐⭐⭐ code.claude.com
refactoring Claude Code test-driven verification checkpoints workflow design
Source trust ratings ⭐⭐⭐ Official Anthropic  ·  ⭐⭐ Established press  ·  Community / research