●CC 2.1.325 — No new release over the weekend; 2.1.325 (11/13) is still the latest●BILLING — 2.1.325 fixes background sessions on a claude.ai login being billed to an API key from the shell●SONNET 4.5 — Retires on the Claude API on 11/30, 14 days left. Check saved model settings too●403 — Users report a Cloudflare 403 page mid-session that still burns tokens●MANAGED — Since 11/12 you can request self-hosted Claude Managed Agents that run entirely on your own infrastructure●NEW — When Browser Extension Is Not Connected Won't Go Away●CC 2.1.325 — No new release over the weekend; 2.1.325 (11/13) is still the latest●BILLING — 2.1.325 fixes background sessions on a claude.ai login being billed to an API key from the shell●SONNET 4.5 — Retires on the Claude API on 11/30, 14 days left. Check saved model settings too●403 — Users report a Cloudflare 403 page mid-session that still burns tokens●MANAGED — Since 11/12 you can request self-hosted Claude Managed Agents that run entirely on your own infrastructure●NEW — When Browser Extension Is Not Connected Won't Go Away
Running Claude Code Without Breakage — A Failure-First Production Workflow with Plan Mode, Hooks, Rewind, and Subagents
If Claude Code has ever left broken commits on your branch, this guide chains Plan Mode, task tracking, hooks, subagents, and Rewind into one failure-first routine — including what each layer does not protect, a guard hook that fails open without jq, and the Bash changes checkpoints cannot undo, all with real output.
I opened the diff and stopped scrolling. Three commits stacked on top of a red test suite, and one config file I did not recognize had been rewritten. All of it had happened in the forty minutes I had left Claude Code alone with the repository.
For a long while after that, I kept Claude Code fenced inside a subdirectory and never let it near main. Unwinding broken commits one at a time is tedious work, and the worst part was that I often could not say where things had first gone wrong.
But "too risky, so don't use it" was quietly costing me most of the upside. What I needed was not a yes-or-no decision. I needed to assume failure and build the way back before I needed it.
The first thing I want to say is that none of the five mechanisms here — Plan Mode, task tracking, hooks, subagents, and Rewind — is airtight on its own. So before the step-by-step routine, I lay out what each one protects and, more importantly, what it does not. Then I order them so each covers another's blind spot, with real terminal output along the way. Everything below was checked against Claude Code and its official documentation as of November 2026.
Why "Success-First" Workflows Break
AI-assisted coding tends to fail in three predictable places.
The first is drift of intent. The prompt was fuzzy, Claude started on something plausible, and halfway through the session both sides are working from slightly different assumptions. People catch this by asking "is this what you meant?" Agents, the more autonomous they get, tend to skip that question.
The second is side effects you cannot see. A commit landed on top of failing tests. A migration ran in a way that cannot be reversed. A dependency moved a minor version without anyone noticing. None of these show up by reading generated code alone.
The third is compounding failure. One mistake is easy to spot and fix. Several small drifts, each built on the last, reach a point where nobody can say what "before" looked like. The more commits an agent makes on its own, the more expensive the walk back becomes.
What all three share is a quiet assumption that things will go right, with intervention only after something visibly breaks. Flip the order — lay down the safety net expecting breakage — and autonomous runs stop leaving damage in the repository.
Clearing Up a Misconception: What Each Mechanism Does and Does Not Protect
My own first mistake was treating each feature as a complete safety guarantee. In practice, each one has a narrow, well-defined scope.
Mechanism
What it protects
What it does not protect
Note as of November 2026
Plan Mode
Intent drift before implementation; forces read-then-approve
What actually runs after approval; plans nobody read
Do not relax other defenses because "it's read-only"
Task tracking (Task tools)
Visibility into progress and where things broke
The safety of any individual operation
In interactive Claude Code, TodoWrite has been replaced by TaskCreate, TaskUpdate and friends
Hooks (PreToolUse)
Stopping dangerous Bash calls before they run
What happens when the hook itself fails; tools the matcher doesn't match
Any non-zero exit other than 2 is treated as non-blocking
Subagents
Keeping the main conversation's context clean
The filesystem — in the same working tree, changes persist
Use worktree isolation when you want the files separated too
Rewind (checkpoints)
Files Claude changed through its editing tools, plus the conversation
Changes made by Bash commands such as rm, mv, cp; changes outside the session
The docs state plainly that checkpoints are not a replacement for version control
The two right-hand columns are the real subject of this article. For a long time I believed that anything a subagent tried would leave no trace in my main repository. It isn't true. If the subagent runs npm update through Bash, package-lock.json changes in the very same working tree — and because the change came through Bash, a checkpoint won't bring the old file back either.
Never trust a mechanism alone; line them up so each one closes another's gap. Everything that follows is built backward from that sentence.
✦
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
✦Developers who have had Claude Code leave broken commits, green-washed tests, or unexpected file rewrites in their repo will walk away with a repeatable routine that eliminates those incidents.
✦You will see, in one table, what each of the five mechanisms protects and what it leaves open, then get a fail-closed PreToolUse hook and a worktree-isolated subagent definition with real test output.
✦You'll be able to use Claude Code confidently on a real main branch, shipping faster without sacrificing reversibility, reviewability, or the trust of anyone else reading the git log.
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.
The routine I run on my own projects chains the five mechanisms in a fixed order.
Plan Mode settles what will happen, how far, and why. The plan is broken into tasks so progress is visible. Hooks physically block destructive operations. Wide-blast-radius work goes to a subagent. Edits are rolled back with Rewind, while Bash-made changes and commits are handled by git.
The point is not to use these "when needed." It is to use them every time, in this order. A fixed order means nothing gets skipped on a tired evening.
Step 1: Plan Mode Locks Down Intent
Plan Mode makes Claude produce a plan before it changes anything. Toggle it with Shift+Tab, or enter it with /plan. What you are protecting is the sequence: read first, approve second.
Asking for a plan first surfaces drift early. Claude will start on something plausible even from a vague prompt; a plan puts its understanding into words. If it is off, you fix it before a single line moves.
Before approving, I check for three things:
Affected files listed by path ("related files in the auth module" is not enough)
Changes ordered into reversible steps (migration, then code, then tests)
An explicit test strategy (what existing tests confirm the change, what new ones get added)
If any of these is missing, I send it back. This is the exact reply I use:
I'm not approving this plan yet. Please rewrite it with:1. Every file you'll touch, by path (separate new files from edits)2. Steps ordered so each one can be verified on its own3. How each step is verified (the exact test command and expected result)Leave commits out of the plan. I'll make the commits myself.
One caution. Plan Mode is a promise not to write yet; it is not a substitute for hooks. The CHANGELOG records a fix for an earlier bug where file-modifying Bash commands could run in plan mode without going through the permission prompt. After reading that, I keep hooks and deny rules active even while planning.
Step 2: Break the Work into Tasks and Leave an Exit
Once the plan is settled, it gets broken into tasks. Older versions of Claude Code used a tool called TodoWrite for this. Since early 2026, interactive Claude Code uses the Task tools instead (TaskCreate, TaskUpdate, TaskList and others), though parts of the Agent SDK documentation still describe TodoWrite. The name matters less than the granularity rules.
Task tracking matters in a failure-first workflow because it keeps the session resumable. When tasks are evenly sized, it is obvious which one broke, and you only need to undo that one.
I hold to three rules when splitting work:
Each task should take five to fifteen minutes (bigger tasks do more damage when they fail)
Every implementation task is followed by a verification task (a test run or a diff review)
The final task is always "a human reviews the diff, then commits"
The third is the one that matters most. Leave a human look at the diff as the last step of anything you delegate. Skip it, and the path for broken commits to reach your branch opens right back up.
Step 3: Hooks Stop Dangerous Operations Before They Run
Hooks let Claude Code run your script when specific events occur. A PreToolUse hook runs just before a tool call, which means you can stop a dangerous operation before it happens.
The hook receives JSON on stdin, including tool_name and tool_input. Per the official hooks reference, exit code 2 blocks the call and feeds your stderr back to Claude. Any other non-zero exit is treated as a non-blocking error, and the tool call goes ahead. That distinction is where I got burned.
Why my old hook let things through
The hook I used to publish here began with set -euo pipefail and parsed the JSON with jq. Here is what happens when you feed it the same input on a machine without jq (Ubuntu 22.04, bash 5.1):
$ printf '%s' '{"tool_name":"Bash","tool_input":{"command":"rm -rf /"}}' | env PATH="$PWD/nojq" bash ./old.sh./old.sh: line 4: jq: command not foundexit=127
Exit 127 is not 2. Claude Code sees a hook that failed, not a hook that said no, and lets rm -rf / proceed. The safety net I believed in fell open the moment one tool was missing. Looking back, I had never once tested what happens when the hook itself fails. That's exactly the kind of gap that appears on a fresh machine, inside a CI container, or under a different user account.
This is what now lives at ~/.claude/hooks/pre-tool-use-guard.sh. I dropped set -e, and whenever the hook cannot make a judgment — no jq, unreadable input — it exits 2 explicitly.
#!/usr/bin/env bash# ~/.claude/hooks/pre-tool-use-guard.sh# PreToolUse hook: block dangerous Bash calls before they runset -uo pipefail# If jq is missing we cannot inspect the call, so fail closed rather than openif ! command -v jq >/dev/null 2>&1; then echo "BLOCKED by pre-tool-use-guard: jq not found, cannot inspect the call" >&2 exit 2fipayload=$(cat)tool_name=$(printf '%s' "$payload" | jq -r '.tool_name // ""' 2>/dev/null) || { echo "BLOCKED by pre-tool-use-guard: unreadable hook input" >&2 exit 2}# Only inspect Bash (Edit/Write can be rolled back with checkpoints)[ "$tool_name" = "Bash" ] || exit 0command=$(printf '%s' "$payload" | jq -r '.tool_input.command // ""')forbidden_patterns=( 'rm[[:space:]]+-[a-zA-Z]*r[a-zA-Z]*f?[[:space:]]+(/|~|\$HOME)' # recursive delete at root or home 'git[[:space:]]+push[[:space:]].*(--force|-f([[:space:]]|$))' # force push (incl. --force-with-lease) 'git[[:space:]]+reset[[:space:]]+--hard[[:space:]]+(HEAD~|HEAD\^|origin/)' 'git[[:space:]]+(filter-branch|filter-repo)' 'git[[:space:]]+checkout[[:space:]]+(--[[:space:]]+)?\.([[:space:]]|$)' 'git[[:space:]]+clean[[:space:]]+-[a-zA-Z]*f' 'git[[:space:]]+commit' # humans make the commits 'chmod[[:space:]]+-R[[:space:]]+777')for pattern in "${forbidden_patterns[@]}"; do if printf '%s' "$command" | grep -Eq -- "$pattern"; then printf 'BLOCKED by pre-tool-use-guard: %s\nCommand was: %s\n' "$pattern" "$command" >&2 exit 2 fidoneexit 0
I'd rather not test a guard hook by asking Claude Code to do something destructive. If the hook isn't working, the destructive thing simply happens. Instead, pipe JSON straight into the hook and read the exit code. This is real output from my machine:
$ t(){ printf '%s' "$1" | ./pre-tool-use-guard.sh; echo "exit=$?"; }$ t '{"tool_name":"Bash","tool_input":{"command":"rm -rf ~/projects/app"}}'BLOCKED by pre-tool-use-guard: rm[[:space:]]+-[a-zA-Z]*r[a-zA-Z]*f?[[:space:]]+(/|~|\$HOME)Command was: rm -rf ~/projects/appexit=2$ t '{"tool_name":"Bash","tool_input":{"command":"git push --force-with-lease origin main"}}'BLOCKED by pre-tool-use-guard: git[[:space:]]+push[[:space:]].*(--force|-f([[:space:]]|$))Command was: git push --force-with-lease origin mainexit=2$ t '{"tool_name":"Bash","tool_input":{"command":"git commit -m \"wip\""}}'BLOCKED by pre-tool-use-guard: git[[:space:]]+commitCommand was: git commit -m "wip"exit=2$ t '{"tool_name":"Bash","tool_input":{"command":"git status --short"}}'exit=0$ t '{"tool_name":"Bash","tool_input":{"command":"rm -rf ./dist"}}'exit=0$ t 'not json'BLOCKED by pre-tool-use-guard: unreadable hook inputexit=2$ printf '%s' '{"tool_name":"Bash","tool_input":{"command":"rm -rf /"}}' | env PATH="$PWD/nojq" bash ./pre-tool-use-guard.shBLOCKED by pre-tool-use-guard: jq not found, cannot inspect the callexit=2
rm -rf ./dist passing is intentional. Block build-artifact cleanup and development grinds to a halt. The hook only stops things that cannot be undone; everything undoable is left to Rewind and git.
The patterns are regular expressions because Claude phrases the same operation slightly differently depending on context. An allowlist is a valid alternative, but for day-to-day flexibility I settled on blocking only the clearly dangerous shapes. For how this fits with the other hook events, see Claude Code Hooks: A Field Guide to the 8 Core Hooks — and the 33-Event Catalog They Now Live In.
Step 4: Delegate to Subagents, but Separate Context from Files
A subagent is a separate agent launched from your main session, working in its own context. Only its final report comes back to the main conversation, so trial and error doesn't clutter it. That makes subagents a good fit for work you can only evaluate by trying it — dependency upgrades are the classic case.
But as the table above says, what gets separated is the context, not the files. A subagent running in the same working tree changes the same files your main session sees. I learned this by carrying a half-updated package-lock.json from a failed subagent run straight into my next task. I only noticed the next day, when the build printed a version warning I didn't recognize.
Here is the definition I use now, at ~/.claude/agents/dependency-upgrader.md:
---name: dependency-upgraderdescription: Try minor/patch npm updates, then report type-check and test results. Never commits.tools: Bash, Read, Grep, Globisolation: worktree---You are an agent dedicated to dependency updates.# GoalUpdate packages in package.json to their latest minor/patch versions without crossing a major version.# Procedure1. Run `npm outdated --json` to get the list of outdated packages2. Exclude anything that would cross a major version3. Run `npm update`4. Run `npm run typecheck` and keep the output5. Run `npm test -- --run` and keep the output6. Roll back any package whose update caused a failure# Forbidden- Editing package.json by hand (npm commands only)- git commit / git push- Proposing major-version upgrades# Output format (return nothing else)## Changed files- <path> (paste the output of git status --short verbatim)## Succeeded- <package>: <old> → <new>## Reverted- <package>: <reason> (failing command and the first line of its error)## Next Steps- Diffs a human should check
Three things changed from the previous version: Edit is gone from tools, isolation: worktree moves the work into its own working tree, and the report must open with the raw git status --short output.
isolation: worktree is a frontmatter field that runs the subagent in a dedicated git worktree. There was a stretch when the documentation hadn't caught up with it, and an issue reported that the field was ignored for agents bundled inside plugins. Before relying on it, I check once with git worktree list that a separate tree really appears. Cleaning up leftover trees is its own topic, which I covered in Taking Inventory of Worktrees That Were Supposed to Be Gone.
Watch your hook matchers too. An issue reports that in v2.1.63 the tool that launches subagents was renamed from Task to Agent. A hook watching subagent launches with "matcher": "Task" silently stops firing after the update. I write "matcher": "Agent|Task" to cover both during the transition.
Step 5: What Rewind Restores, and What Belongs to git
Rewind is Claude Code's checkpointing feature. Press Esc twice or type /rewind to open the history, then restore code and conversation, conversation only, or code only, to any point you pick.
The official docs are explicit about its limits. Checkpoints track changes Claude makes through its editing tools. File changes made by Bash commands — rm, mv, cp and the like — are not tracked, and neither are changes made outside the session. The docs also state that checkpoints are not a replacement for version control.
So the results of the subagent's npm update, or files Claude rewrote in bulk through Bash, won't come back with Rewind. I split responsibilities like this:
What you want back
Tool
Concrete action
A conversation drifting from the plan, plus edits made with editing tools
Rewind
/rewind to just after plan approval, restore code and conversation
File changes made through Bash (generated, moved, deleted)
git
Return to a pre-task git stash push -u -m before-task or a WIP commit on the work branch
Wide-impact experiments such as dependency updates
worktree
Throw the whole tree away (git worktree remove)
A commit that already landed
git
A human runs git revert (no history rewriting)
I rewind deliberately at three moments: when the session starts drifting from the plan, right after tests turn red, and when a subagent's report turns out to be wrong after I've applied it. The earlier you rewind, the smaller the damage and the shorter the do-over.
The Integrated Routine
Here are the five steps as the single routine I run every time — new feature, bug fix, or refactor — whenever Claude Code touches a real repository.
[0] Freeze the starting state - git status shows no changes (otherwise git stash push -u) - create a work branch (never start on main) ↓[1] Get a plan in Plan Mode (Shift+Tab or /plan) - send it back unless it has paths, order, and verification ↓[2] Have the plan split into tasks - 5-15 minutes each, a verification task after each implementation task - last task: "human reviews the diff" ↓[3] Implement (the PreToolUse hook watches from here on) - wide-impact work goes to a worktree-isolated subagent ↓[4] Review the diff at every verification task - edit drift: /rewind; Bash changes: git ↓[5] A human reads git diff and makes the commit
The most important part is step 5: the commit is never Claude's. Implementation, tests, and docs can all be delegated, but every commit passes one human look first — and the hook's git commit block backs that rule up from the machine side.
A Real Session: Where Each Layer Earned Its Place
Here is a condensed log of one change: adding per-article purchases to my own Next.js site, so readers can unlock a single article without a full membership.
The plan came back about two minutes after the prompt. Seven files, with a test strategy that extended the existing Stripe webhook mock. On my second read, I noticed the part that records purchased articles in a cookie was written as an overwrite — buying a second article would silently erase the first. I sent it back at the plan stage, asked for accumulation instead, and only then approved.
During implementation the hook fired twice. Once when Claude tried to rm -rf a generated cache using an absolute path from the home directory, and once when it reached for git reset --hard HEAD~1 right after a test failure. Both times Claude read the block reason and switched course: a relative-path delete, and a message asking me whether to roll back.
At the final diff review I caught an environment variable missing its last character — STRIPE_ARTICLE_PRICE_I instead of STRIPE_ARTICLE_PRICE_ID. The tests passed because they used mock values, so this was the kind of bug that only shows up in production. I fixed it by hand and made the commit myself. Zero rollbacks, zero incidents.
Troubleshooting Table
Even with the routine in place, some days go sideways. These are the symptoms I've actually hit, in the order I check them.
Symptom
Likely cause
How to confirm
Fix
A dangerous command slipped past the hook
The hook exited non-zero but not 2 (e.g. 127), which is non-blocking
Pipe the same JSON into the hook and check echo $?
Check dependencies first; exit 2 whenever the hook can't decide
The hook never fires
Not executable, or the matcher doesn't match the tool name
ls -l ~/.claude/hooks/; review registrations with /hooks
chmod +x; match real tool names (Bash, Agent|Task)
A deleted file didn't come back after /rewind
Deletions via Bash rm aren't checkpointed
Check in the transcript whether the change came from Edit/Write or Bash
Restore from the pre-task git stash or WIP commit
The lockfile changed after a failed subagent run
The subagent ran in the same working tree
git status --short, git worktree list
Add isolation: worktree; require a changed-files list in the report
A commit appeared despite "don't commit"
The instruction was dropped late in a long session
git log --oneline -5, check author and time
Block git commit in PreToolUse — enforce with machinery, not wording
A hook watching subagent launches stopped after an update
The tool was renamed from Task to Agent
Log tool_name from the hook
Use "matcher": "Agent|Task"
Where Each Defense Belongs: Hooks, Deny Rules, and Human Gates
Hooks are not the only way to stop things. You can also write deny rules under permissions in settings.json. Here is how I divide the work:
Method
Good at
Weak at
Where I use it
Permission deny rules
Declaratively forbidding commands with a fixed shape; easy to read
Commands whose argument order varies; conditional logic
Operations that almost always look the same, such as git push
PreToolUse hook
Flexible matching with regex and conditions; explains the reason to Claude
A buggy hook can fail open
Deletions, history rewrites, and commits, whose shape varies
Human gates (plan approval, final review)
Catching mistakes in intent and meaning
Tired days when you wave things through
Plan approval and right before the commit
In one sentence: fixed shapes go to deny rules, variable shapes go to hooks, and correctness of meaning goes to a person. I layer all three so that if one lapses, the other two still stop the problem.
Common Pitfalls
Approving a plan without reading it
This is the most common way incidents start. A plan only has value if a human reads it. On busy days the temptation is to wave it through, and the five minutes you saved come back as an hour of rollback.
When a plan arrives, I start a five-minute timer and don't approve until it rings. Opening one of the files the plan mentions during those minutes makes it much easier to tell whether the plan is concrete enough.
Hook patterns so strict that nothing moves
Over-tightened hooks block legitimate work too. I once banned git reset --hard outright and then couldn't run the reset I needed to re-sync the working tree after a Rewind.
Keep the blocklist to destruction at root or home, history rewriting, and commits. The hook above blocks only resets with HEAD~, HEAD^, or origin/, while git reset --hard HEAD passes. I note every legitimate command that got blocked and revisit the patterns once a month.
Taking a subagent's report at face value
Without a fixed format, reports come back vague about what was actually done. If the main session believes them, it starts building on changes that never happened.
Two countermeasures: make the report open with raw git status --short output, and have the main session check once that the files listed in the report actually exist.
A stale CLAUDE.md that everyone trusts
Three weeks after I rebuilt the auth module, CLAUDE.md still described the old function names, and plans kept referencing them. Now, any task that renames an API or moves a file ends with a single grep -n "oldFunctionName" CLAUDE.md.
The Next Wall: When You Step Away for Longer
Once the routine feels natural, you'll want to run it overnight or call it from CI. The first wall you hit is that nobody is there to answer permission prompts.
Unattended runs lose both human gates — plan approval and final review. To make up for it, I widen the hook's blocklist a notch, allow pushes only to work branches, and merge into main myself the next morning. For deciding how hooks should behave when they fail in that setting, the onFailure and missing-jq write-up mentioned earlier is the place to start.
Where to Begin
You don't need all five layers at once. Add them in the order they pay off.
Plan Mode needs no configuration and works today. Next, install the hook above and test it from outside Claude Code by piping in JSON and reading the exit code. Those two alone stopped most of the incidents I used to hit, right at the entrance. Subagent isolation and the Rewind-versus-git split can wait until the first two feel natural.
If you do one thing after reading this, pipe a single JSON payload into your own guard hook with jq removed from PATH, and see whether you get exit=2. That one line is how I found out my own safety net had been open.
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.