Last week, while drafting a new post in my blog repo, Claude Code took it upon itself to edit the tags on three other articles—because it decided they were “inconsistent.” When I ran git diff, changes were scattered across four files, while the one file I actually wanted updated had a single-line edit.

That wasn’t a capability issue—it was a constraint issue. Since then, I’ve codified a standard operating procedure (SOP) that ties together the prompting techniques, trust calibration, and lessons learned from earlier posts into a single routine. Following it has cut my rollback rate by more than half.


Starting a New Task: 3 Steps

Every time I open Claude Code for a new task, I run through three quick checks. They take less than a minute and save hours of debugging later.

1. Confirm Your Working Directory

Juggling multiple projects is an easy way to shoot yourself in the foot—you think you’re editing a backend API, when you’re actually inside your blog theme repo.

1
2
3
# Make this your very first command every time
pwd
# /home/user/workspace/projects/l4_cloud/backend

If you’re in the wrong directory, cd to the right repo or open a fresh terminal window. Never start a session in the wrong workspace—Claude will faithfully modify the wrong project.

2. State the Goal in One Sentence

The gap between a vague prompt and a crisp one is night and day:

1
2
3
4
5
# Bad: vague, multi-goal
claude "Improve the user experience"

# Good: specific, single-focus, bounded
claude "Add a search box to the user list page supporting fuzzy search by name and email, following the existing pagination component"

The rule of thumb: what to do + how far to take it + what to reference. When all three are present, Claude stops improvising.

3. Have Claude Read the Code Before Editing

Skipping this step is the mistake that has burned me the most. When Claude jumps straight into writing code without reading the existing implementation, it either reinvents the wheel or edits code it shouldn’t touch.

1
2
# When modifying existing code, always start with this
claude "Inspect the current user list implementation (src/pages/UserList.tsx) and tell me how you plan to change it. Do not edit any code yet."

The plan it returns becomes your review checkpoint. If something looks off, steer it before a single line is written; if the plan looks solid, reply “go ahead with this plan.” Thirty seconds up front saves thirty minutes of rework.


During Execution: Checkpoint Mode

I don’t let Claude run through an entire multi-step task uninterrupted. Instead, I work in a checkpoint loop: Claude takes 3–5 steps, I review the diff, and only then do we move to the next round.

Loop Stage Your Action Acceptance Criteria
Claude executes Watch the output for scope drift No unauthorized file edits
Review the diff Run git --no-pager diff Right files touched; no unintended deletions
Confirm or steer Say “continue” if clean, or give concrete corrections Each round can be reverted cleanly on its own

When to Interrupt

You don’t have to wait for Claude to pause at a checkpoint. Interrupt immediately when you spot any of these signals:

  • More than 5 files modified—a single feature rarely needs that blast radius; it has likely drifted
  • Edits to files you never mentioned—Claude is doing “drive-by improvements” that need your sign-off
  • Three consecutive search-and-edit loops—it’s spinning in circles and needs a new direction
  • Repeated “Let me rethink this” in the output—context is muddled; consider running /clear

Interrupting is simple: just send a message right away without waiting for the current turn to finish.

How to Review

1
2
git --no-pager diff           # Review the full scope of changes
git --no-pager diff --stat # Quickly see how many files and lines changed

Review checklist:

Check What to Look For Red Flag
File scope Only target-related files were touched Unrelated files show up
Deletions Whether removed code is still referenced Large deleted blocks with no replacement
Code style Naming and indentation match existing code A foreign style creeps in
Hardcoding Config values extracted into constants Magic numbers scattered around
Comments Non-obvious logic has brief explanations Noisy, redundant comments

If everything checks out, tell Claude to continue or commit. If not, point out the exact issue and have Claude fix it before moving on.


When Things Go Sideways: The Escalation Ladder

Not every session goes smoothly. When Claude veers off track, I climb a four-level escalation ladder:

Level Situation Action Example
Level 1 Slightly off target Steer the prompt in the current session “Wrong direction—I want X, not Y. Revert and redo.”
Level 2 Completely derailed / muddled context Reset the session with /clear Start fresh with a tighter prompt
Level 3 Repeats the same mistake across tasks Document it in CLAUDE.md Codify the convention in project rules
Level 4 Ignores a written rule Enforce it with a Hook Automated check that cannot be bypassed

Level 1: Adjust the Prompt

Most issues stop right here. If Claude misread your intent, correct it directly:

1
2
You're heading in the wrong direction. I need client-side filtering on the frontend, not a backend query change.
Revert the previous edits and modify only UserList.tsx.

Level 2: Clear and Restart

Once a conversation grows long, Claude keeps “remembering” the earlier wrong turn and drifting back toward it. Don’t fight stale context:

1
2
3
/clear
# Restart with a sharper prompt
claude "Modify only UserList.tsx to add a frontend search box that filters the user list. Do not touch backend code."

Level 3: Codify the Rule

When Claude keeps making the same mistake—for instance, my project uses 5-digit business error codes, yet it keeps writing 3-digit ones—that’s a documentation gap, not a model flaw.

1
2
3
4
5
# Add to CLAUDE.md
## Error Code Conventions
- Business error codes: 5-digit numbers where the first two digits identify the module
- Examples: `40001` (User module), `50012` (Order module)
- Do not use HTTP status codes as business error codes

CLAUDE.md is a soft constraint—Claude tries to follow it, but there’s no guarantee it remembers every rule on every turn.

Level 4: Enforce with a Hook

Still seeing occasional violations after adding the rule? Promote it to a Hook so it becomes a hard guardrail:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"if": "Bash(git commit *)",
"command": "cd /path/to/project && go test ./... || { echo 'Tests failed; commit blocked' >&2; exit 2; }"
}
]
}
]
}
}

This Hook runs the test suite automatically right before Claude executes git commit. If tests fail, the commit is blocked. Hooks operate at the system boundary and cannot be skipped—that’s the fundamental difference between a Hook and a CLAUDE.md guideline.


Finishing a Task: 3 Wrap-Up Steps

1. Review the Final Diff

1
2
git --no-pager diff           # Inspect every change in full
git --no-pager diff --stat # Summary of changed files and line counts

This is your final line of defense. Check three things:

  • Was every single change actually requested?
  • Did any required file get missed?
  • Are there leftover debug logs or temporary snippets?

2. Verify Locally

Match the verification step to the kind of work you just did:

Task Type Verification Command What to Confirm
Backend code go test ./... or npm test All tests pass
Project config hexo clean && hexo server Local server starts cleanly
Blog post hexo server → browser preview Layout, links, and images render properly
CI/CD changes Validate workflow syntax Triggers and steps are accurate
Bug fix Replay the original repro steps Bug is resolved with no regressions

3. Commit and Push

1
2
3
git add src/pages/UserList.tsx          # Stage only relevant files
git commit -m "feat: add search to user list page"
git push

Follow Conventional Commits for commit messages:

  • feat: new feature
  • fix: bug fix
  • post: blog post
  • docs: documentation update
  • refactor: code refactoring

**Never run git add .**—it sweeps up everything in your working tree, including scratch files you never meant to commit.


Weekly Maintenance: 10 Minutes

Spend 10 minutes once a week keeping your project configuration lean and accurate.

Audit CLAUDE.md

1
wc -l CLAUDE.md   # Check total line count

Quick audit checklist:

  • Are last week’s new rules still needed? Drop rules tied to finished initiatives
  • Have any project changes made existing rules stale (e.g., switching test frameworks)?
  • Has the file grown past 200 lines? Trim it down—bloated rules dilute Claude’s attention

Check Hook Logs

Inspect .claude-output/logs/ to make sure your Hooks are firing as expected:

  • False positives (blocking valid actions) → tighten the matcher
  • False negatives (letting disallowed actions slip through) → expand the matcher

Clean Up Leftovers

1
2
3
# Check for leftover temporary files
git status
# Remove unneeded files and update progress notes

Summary

The entire SOP in one table:

Phase Action Key Command / Habit
Kickoff Confirm directory pwd
Kickoff State the goal Crisp prompt: what + scope + reference
Kickoff Read before editing “Inspect the code and share your plan first; don’t edit yet”
Execution Checkpoint loop Review git diff every 3–5 steps
Recovery L1–L4 escalation Steer → /clear → CLAUDE.md → Hook
Wrap-up Review + verify + ship git diff → local verification → git add/commit/push
Weekly Config hygiene Audit CLAUDE.md + Hook logs + clean up leftovers

A good SOP doesn’t need to be complicated—it just needs to be followed every time. Running this routine catches most mistakes before they happen instead of burning time cleaning up afterward.


Series Navigation