◉CLAUDE LABJP
●CODE 2.1.319 — Claude Code now moves MCP tasks to the background automatically, and a denyInsteadOfPrompting setting denies calls that would wait on a prompt●CONSOLE — Console IP allowlist is in beta (11/5): requests from addresses not on the list are refused●SONNET 4.5 — Retires on the Claude API on 11/30, 23 days left. Migrate to Sonnet 5.5●WINDOWS — Reports say hooks break silently only on Japanese-locale Windows; check the character encoding first●FAST — Opus 4.8 fast mode is deprecated and will be removed on 11/30. Migrate to Opus 5.5●NEW — I Put a Ten-Line Promise File at the To…●CODE 2.1.319 — Claude Code now moves MCP tasks to the background automatically, and a denyInsteadOfPrompting setting denies calls that would wait on a prompt●CONSOLE — Console IP allowlist is in beta (11/5): requests from addresses not on the list are refused●SONNET 4.5 — Retires on the Claude API on 11/30, 23 days left. Migrate to Sonnet 5.5●WINDOWS — Reports say hooks break silently only on Japanese-locale Windows; check the character encoding first●FAST — Opus 4.8 fast mode is deprecated and will be removed on 11/30. Migrate to Opus 5.5●NEW — I Put a Ten-Line Promise File at the To…
Articles/Claude Code
⟐ Claude Code/2026-06-16Advanced

Keeping Large Claude Code Refactors Revertible One Commit at a Time — Field Notes on Checkpoints and Rollback Detection

Hand a big refactor to Claude Code and the speed hides a real cost: review-proof, oversized diffs. Here are the field notes I actually run — declaring checkpoints in a manifest, enforcing commit granularity with a pre-push hook, and tying rollback calls to observability.

Claude Code283Refactoring3Git5RollbackObservability5

✦ Premium Article

You ask Claude Code to "rewrite this whole directory into a different structure," and forty seconds later a 2,000-line diff lands and your hands stop moving. I have lived that moment several times, on personal apps and on client work alike. Generation is fast, but the focused attention review needs grows roughly exponentially with the size of the diff.

For a while I powered through reviews on willpower. Once I started running several projects in parallel as an indie developer, that approach plainly broke down. Now I invert the order. Before I let Claude Code generate anything, I design where I can safely roll back to, and I make Claude Code honor that granularity. These are the field notes for the manifest, hook, and rollback detection I actually use — written so you can copy them.

Estimate the layer that breaks even when tests are green

Claude Code is smart, so most refactors come back as working code. The trouble is that the gap between "it runs" and "it runs correctly" widens with the size of the diff.

The failures I have actually hit lived in a layer unit tests cannot reach. A database connection's initialization order was off by one line, and connections only exhausted during idle periods after deploy. On another project, existing code quietly relied on "swallow the exception and return a default," and a clean rewrite that simply threw instead took down an entire nightly batch. In both cases a new diff broke a contract the old code held implicitly — and because the tests never expressed that contract, they stayed green.

The takeaway is singular: refactor size and reviewability have to be designed as separate things. Rewriting big is fine. The problem is being handed it all at once and forced to verify it all at once.

Declare checkpoints as a manifest, up front

When I start a refactor, the first thing I do is not generate code — it is mark the points I can return to. Rather than leaving that in comments or my head, I put it in a YAML manifest committed to the repo, so the later hooks and reviews can read it.

# refactor.checkpoints.yml — fixed before the refactor begins
target: Move OrderService toward a structure with clearer boundaries
rollback_signals:
  p95_latency_ms: 450      # exceed this -> revert to the previous CP
  error_rate_pct: 1.0
checkpoints:
  - id: CP1
    intent: Add interfaces/ and usecases/. Do not change a single line of OrderService
    invariant: No calls from existing code occur (pure addition only)
  - id: CP2
    intent: Add an adapter so the new UseCase calls the existing OrderService
    invariant: The entry Controller supports both paths via a flag defaulting to the old route
  - id: CP3
    intent: Port tests to the UseCase side. Keep old tests. Flag defaults to false
    invariant: Behavior with the flag false exactly matches CP2
  - id: CP4
    intent: Flip the flag to true for part of production traffic; if clean, invert the default
    invariant: The flag can be returned to false instantly at any time
  - id: CP5
    intent: Delete the old OrderService and the flag branch
    invariant: Predicated on CP4 being stable in production

The part that earns its keep is invariant — the condition that must hold once each checkpoint is done. Writing down not just "what to do" but "what is provably still intact when it finishes" naturally shifts the request to Claude Code from "rewrite the whole thing" to "produce only the diff that satisfies CP1's invariant." The reason a giant diff comes back is not Claude Code; it is that I never defined the granularity. Realizing that was the start of this whole practice.

✦

Thank you for reading this far.

Continue Reading

What follows includes implementation code, benchmarks, and practical content we hope you'll find useful. This site runs without ads — server and development costs are supported entirely by members like you. If it's been helpful, we'd be truly grateful for your support.

WHAT YOU'LL LEARN
✦A workflow for declaring checkpoints in a YAML manifest before you start, mapping each commit to a single revertible point
✦A pre-push hook that mechanically rejects commits over 300 lines, missing a checkpoint ID, or failing to build — stopping oversized diffs at the door
✦A Python snippet that compares metric series before and after to automate the rollback decision, plus how to set the thresholds
Secure payment via Stripe · Cancel anytime
✦

Unlock This Article

Get full access to the rest of this article. Buy once, read anytime. This site is ad-free — your support goes directly toward keeping it running.

or
Unlock all articles with Membership →
Share

Thank You for Reading

Claude Lab is ad-free, supported entirely by members like you. We publish practical guides daily with implementation code, benchmarks, and production-ready patterns. If you've found it useful, we'd love to have you on board.

  • ✦Copy-paste ready implementation code
  • ✦New advanced guides published daily
  • ✦$5/mo or $10 for lifetime access
View Membership →

Related Articles

⟐ Claude Code2026-04-02
Running Claude Code Per Worktree: Notes From Actual Use
Implementation notes on splitting branches into Git worktrees and launching Claude Code per directory. What is shared and what is isolated, measured on a real repository, plus the untracked files nobody warns you about.
⟐ Claude Code2026-11-08
Before a Nightly Job Hangs on a Prompt: Designing Around denyInsteadOfPrompting
Claude Code 2.1.319 adds permissions.denyInsteadOfPrompting. Here is how it compares with other ways to answer permission prompts unattended, and how to catch what a denial quietly drops.
⟐ Claude Code2026-11-06
When claude doctor Listed Four Warnings, I Sorted Them by Cause Before Fixing Anything
claude doctor ended with "4 warnings found", but I didn't need four fixes. Using the real output, here is how to spot duplicated warnings and sign-in-only info lines, group the rest by cause, and decide the order of repair.