Read(~/.claude) ⎿ 5 skills · 7 subagents · 6 hooks
MethodMy Claude Code setup
How I work describes the loop. This page is the loop written down as files an agent reads: skills it follows, subagents it hands work to, and hooks that run whether it remembers them or not. These are the files I use, quoted at build time from copies kept with this site's source.
What I kept typing
Repeat it → skill. Must happen → hook.Before writing any of this, I had Claude go through my own prompt history. 330 of 3,969 prompts contained the same line, "iterate through PR reviews, fixing issues and re-reviewing until you're satisfied…", and most of those went on to say "then merge" or "then merge and deploy". 37 times I'd had to ask whether it had reviewed the PR at all. Other habits showed up too: checking whether a deploy worked, spawning parallel sessions with the same instructions, and writing handoff prompts after a session got cut off.
Two rules came out of that. If I keep typing it, it becomes a skill, so the agent does it the same way every time without being asked. If it has to happen, it becomes a hook, because a skill only helps when the agent remembers to use it.
The skills
Loaded when the request matchesA skill is a markdown file with a one-line description. Claude Code loads it when a request matches that description, or when I type its name as a slash command.
/pr-loop: from "done coding" to merged
Take a change from "done coding" to merged (and optionally deployed and verified). Opens the PR if needed, runs fresh-eyes review passes in a separate reviewer agent, fixes review/bot/CI feedback, resolves conflicts, and repeats until clean. Handles several PRs in order.
Its core is a merge gate the agent has to clear, and the review in it is done by a separate reviewer subagent. It gets the diff and the PR description, but not the session's reasoning: a review anchored on the author's thinking tends to agree with it.
For anything a user sees or does, a second subagent, the evaluator, is told not to read the diff or the author's description of it. It gets only the PR's acceptance criteria, ideally agreed before the code was written. It starts the app and passes or fails each criterion by using it. If it fails on any one area (the criteria, errors, design, or a stubbed-out feature), the whole PR fails. Strong marks elsewhere don't make up for it.
**Merge gate.** All of these must hold:
- [ ] The latest `reviewer` pass on the **current HEAD** returned `VERDICT: clean`.
- [ ] For a PR that changes what a user sees or does: the latest `evaluator` run returned `VERDICT: pass` on the current HEAD, or on an earlier commit when every change since was one §1 says keeps it. If it returned `blocked` (no criteria, no documented way to run the app, or a criterion it couldn't check), fix the cause if it's yours. Rewording or dropping a criterion is never yours to do. Otherwise say so in the report, and treat the gate as not passed until Kevin accepts it. Record his acceptance in the state file (`"accepted":["<what> at <sha>"]`) so a resumed run knows.
- [ ] `merge` / `deploy` mode only: if the criteria are labeled *Written after coding*, Kevin has OK'd them in this conversation. The author wrote them after seeing what got built, so nobody has checked them against the goal yet.
- [ ] No unresolved threads, except push-backs awaiting the reviewer, with nothing new from them since.
- [ ] CI is green, or no CI ran and the local gate passed.
- [ ] If the PR has a `## Scope` section, `check-scope.sh <n>` exits 0. For each file it lists, either revert the change or, if the file really is part of the task, add it to Scope with a one-line reason under the block and name it in the report. A file under a `!` pattern belongs to another session or person: never widen over it; ask the parent session or Kevin.
- [ ] `mergeable` is `MERGEABLE`.
- [ ] The PR description matches what the code now does. Update it with `gh pr edit <n> --body-file -` if not, but leave the `## Acceptance criteria` section exactly as it is. If the code and the criteria disagree, that goes to Kevin; it isn't a description fix.skills/pr-loop/SKILL.md. Merging only happens when I pass merge or deploy, or say "then merge"."Loop until clean" had a cost I only saw in the transcripts: 3.9 reviewer passes per PR on average, and later passes were still mostly coming back with changes. Anthropic's Claude Code team hit the same thing and found most late findings were in code that had been there all along. So bugs in code the PR didn't touch are now follow-ups instead of fixes, and the loop has a cap:
**Round cap.** After **3 full reviews that came back `changes-needed`** (`fullRounds` reaches 3), stop fixing. Report to Kevin what's still open, what each round found, and whether the findings are converging or new ones keep appearing, then set `waiting-kevin`. More rounds past this point mostly find older code, not new bugs. Delta reviews and evaluator runs don't count toward the cap. Hard stop at 15 passes of any kind.skills/pr-loop/SKILL.md.Two later additions close gaps the loop couldn't see from inside one PR. A PR that comes with a list of files it may touch gets a ## Scope section, and the merge gate checks the diff against it with a short script instead of a reviewer's impression. And a fixed bug used to fix only that PR. Now the loop ends by asking which fixes should become rules, so the same mistake doesn't come back in the next one:
1. **Skip one-offs.** A typo or a slip that no rule would have caught gets nothing. Zero rules is a normal outcome; propose at most three.
2. **Write the constraint, not the incident.** Not "the billing form crashed on an empty name" but "form handlers validate required fields before calling the API". It should apply to work that hasn't been written yet.
3. **Check it isn't already a rule.** Grep the repo's CLAUDE.md / AGENTS.md, `~/.claude/CLAUDE.md`, the agents and hooks. If the rule exists and was ignored, the proposal is to make it a check, not to write it again.
4. **Pick the strongest place that fits,** in this order: a check that can fail (a test, lint rule, type, hook or script), then the repo's CLAUDE.md, then the `reviewer` agent's checklist, then `~/.claude/CLAUDE.md` for rules that hold in every repo. A check beats an instruction because nobody has to remember it.
5. **Propose, don't apply.** Put each one in `rules` in the state file and in the report: the rule, where it would go, and the finding it came from. Kevin decides; nothing lands in an instructions file, agent or hook without his OK.skills/pr-loop/SKILL.md. I approve each rule before it lands anywhere.verify-live: "deployed" isn't "working"
Prove a merged or deployed change actually works in the running environment, with evidence, before saying it does.
- **Report only what you observed.** "Should work", "looks correct", and "the code handles it" are not verification. If you couldn't observe something, say "not verified" and why.
- **Check the deploy happened before checking behavior.** Confirm the running version is the commit you merged (a version or health endpoint, a build SHA in logs, a container image tag, the deploy job's output). A pass against the old build tells you nothing.skills/verify-live/SKILL.md. Its first check is that the running build is the commit that was merged.spawn-sessions and handoff: work that outlives one context
I often run one session as a planner and several more as workers, each in its own git worktree and opening its own PR. A worker knows only its brief, so the brief has a fixed shape:
Goal: <one sentence: the outcome, not the steps>
Context: <what the parent learned that this task needs: root cause, constraints, decisions already made, links to the issue or PR>
Scope: <path globs this task may change, one per line; `!` before paths other sessions own>
Copy these lines into the PR's `## Scope` section as given; pr-loop's merge gate checks the diff against them.
Done when: <observable criteria, including tests to add or pass>
Acceptance criteria: <numbered, pass-or-fail list for the PR's `## Acceptance criteria` section, and whether Kevin already agreed it. If so, the child doesn't ask again>
Workflow:
- Implement, then run /pr-loop<" merge" / " merge deploy" if Kevin asked>: open the PR, iterate through reviews with the fresh-eyes reviewer until it's fully accurate and bug-free.
- Turn on Auto-fix for the PR once it's open.
- Follow the repo's CLAUDE.md (pre-push gate, PR notes, docs in the same commit).
- Subagents: follow the model tiers in ~/.claude/CLAUDE.md.
- If you're blocked on a decision that's Kevin's, message the parent session instead of guessing.
Report: PR link, final review verdict, CI state, proposed rules (pr-loop §9), anything not verified.skills/spawn-sessions/SKILL.md. When a worker reports back, the parent checks the PR itself before calling it done.handoff covers the other case: when a long run is about to hit a limit, or I want to start fresh, it writes the state, the decisions already made and the next step as a prompt a new session can pick up from.
Which model does what
Priced by the cost of a wrong answerSubagents can run on cheaper, faster models than the main session. The tempting rule is "cheap model for simple tasks". The rule I use is about what a wrong answer costs, and it lives in the global instructions every session loads:
- **`haiku`**: mechanical lookups whose output you'll check yourself. Finding a file or symbol, grep sweeps, listing call sites, reading logs or test output and reporting failures, extracting text.
- **`sonnet`**: routine work with a clear spec. Bounded edits, refactors, writing tests, doc updates, repeated drafting or investigation passes, summarizing a PR or thread. Not reviewers or gates: see the floor below.
- **inherit** (the session model, **usually Opus 5.5**; use the `engineer` agent to change code, `analyst` to read and conclude, or another named agent with `model: inherit`): anything whose *conclusion* you'll act on. That covers data or population analysis, prod-DB reads, real-money or gating logic, security, migrations, perf work, design or architecture, and every reviewer or verifier. Inheriting means this tier moves up with the session when Kevin switches to Fable.
- **Floor for review and gates: Opus.** Never run a reviewer, verifier or gate below Opus 5.5. If the session itself is on Sonnet or Haiku, pass `model: "opus"` for those agents instead of inheriting. A fork (`subagent_type: "fork"`) always runs on the session model, so don't use one for review from a smaller session.
- **`fable`**: only for the hardest work. That means major refactors or migrations, leading many subagents, deep quantitative analysis, or when the session model at high effort has already fallen short.
"Read-only research" isn't automatically cheap. A fast model states a wrong *population* or the wrong file with full confidence, and the main model then builds on it. If a cheap subagent's answer surprises you, check it before acting on it. For detail (effort levels, cost math, orchestration, defining agents in `~/.claude/agents/`), use the `model-delegation` skill.CLAUDE.md, the part of my global instructions that applies to every repo.The model-delegation skill holds the reasoning behind that rule: costs, effort levels, and when to split work across many workers. It's adapted from Anthropic's model-selection guide. The part I use most is the order to escalate in when output isn't good enough:
1. **Make the work self-verifying.** Give the agent a test, build, typecheck, or script it can run. This beats raising effort on cost.
2. **Raise effort one level.**
3. **Move up one model**, starting at a *lower* effort than you were using on the smaller one.skills/model-delegation/SKILL.md.The subagents carry their model in their definition, so the choice doesn't depend on the agent remembering it. The exceptions run on the session model: the engineer and the analyst, because their work gets built on, and the two gates, the reviewer and the evaluator, which a smaller session lifts to Opus.
| Subagent | Model | Job |
|---|---|---|
reviewer | same as the session (usually Opus 5.5), never below Opus | Fresh-eyes code review of a branch or PR diff, done without the author's context. |
evaluator | same as the session (usually Opus 5.5), never below Opus | Runs the change and checks each acceptance criterion against the live app, without seeing the diff or the author's reasoning. |
engineer | same as the session (usually Opus 5.5) | Implementation work that should run on the session model, in its own context. |
analyst | same as the session (usually Opus 5.5) | Analysis whose conclusion will be acted on, done in a separate context. |
researcher | sonnet | Web, docs and codebase research with a clear question, returning sourced findings. |
locator | haiku | Cheap, fast code search. |
log-reader | haiku | Reads test output, CI logs, build output, or server logs and reports each failure concisely. |
Hooks: the parts that aren't optional
SessionStart · UserPromptSubmit · Stop · PreToolUseA hook is a script Claude Code runs on an event: before a tool call, when a turn ends, when a session starts. It runs whether or not the agent remembers it. I run 6.
The review gate
In a session that pushed code, this checks every PR the session touched when a turn tries to end. If one is open and its latest commit has no clean review on record, the turn is sent back once with an instruction to run the reviewer. The agent can still stop to ask me something, but it has to say why. "Did you review the PR?" is now a question the tooling asks.
The first version was too eager: 596 blocks in its first 18 days, many of them on turns that were only waiting for a reviewer to finish or for my answer. Now it skips draft PRs and PRs whose loop state says they're waiting, and it stops nudging after three times on the same commit. The reminder can go quiet, but pr-loop's merge gate still requires the review. That part is an instruction the skill follows, not something a hook enforces.
unreviewed=()
for d in "${candidates[@]}"; do
cd "$d" 2>/dev/null || continue
git rev-parse --is-inside-work-tree >/dev/null 2>&1 || continue
branch=$(git symbolic-ref --short -q HEAD) || continue
case "$branch" in main|master|develop|trunk) continue;; esac
sha=$(git rev-parse HEAD)
[ -f "$(git rev-parse --path-format=absolute --git-common-dir)/pr-reviews/$sha" ] && continue
state="$(git rev-parse --path-format=absolute --git-dir)/pr-loop-state.json"
if [ -f "$state" ]; then
st=$(jq -r '.status // ""' "$state" 2>/dev/null); head=$(jq -r '.head // ""' "$state" 2>/dev/null)
case "$st" in waiting-*) [ -n "$head" ] && [[ "$sha" == "$head"* ]] && continue;; esac
fi
count=$(cat "$blocks/$session-$sha" 2>/dev/null || echo 0)
[ "$count" -ge 3 ] && continue
pr=$(timeout 10 gh pr view --json number,state,isDraft -q 'select(.state=="OPEN" and (.isDraft|not)) | .number' 2>/dev/null) || continue
[ -z "$pr" ] && continue
echo $((count + 1)) > "$blocks/$session-$sha"
unreviewed+=("PR #$pr in $d (branch $branch, HEAD ${sha:0:8})")
done
[ ${#unreviewed[@]} -eq 0 ] && exit 0hooks/require-pr-review.sh. The review marker is per commit, so any new push needs a new review.The database guard
My instructions have always said never to reset a local database without asking. An agent cleaning up schema drift still reaches for it now and then. Now a pre-tool-use hook blocks the command and tells the agent the safe way to fix drift instead:
patterns=(
'make[[:space:]]+([^;&|]*[[:space:]])?db\.(reset|drop)' # make db.reset, db.reset.test, db.drop
'script/db[[:space:]]+(drop|reset)' # go run ./script/db drop
"(^|[;&|[:space:]/'\"])dropdb([[:space:]]|\$)" # postgres dropdb: bare, by path, or quoted (sh -c '...')
"${sql_client}[^;&|]*drop[[:space:]]+(database|schema)" # psql -c "DROP DATABASE ..."
"drop[[:space:]]+(database|schema)[^;&]*\|[[:space:]]*${sql_client}" # echo "DROP ..." | psql
'(rails|rake)[[:space:]]+db:(drop|reset|setup|schema:load|migrate:reset|truncate_all)'
'prisma[[:space:]]+migrate[[:space:]]+reset'
'prisma[[:space:]]+db[[:space:]]+push[^;&|]*--force-reset'
'drizzle-kit[[:space:]]+drop'
'supabase[[:space:]]+db[[:space:]]+reset'
'goose[^;&|]*[[:space:]](reset|down-to[[:space:]]+0)'
# Compose down/rm and docker rm with volumes; the v flag may be combined (-sfv) but must be a flag, not part of a name.
'docker(-compose|[[:space:]]+compose)[^;&|]*[[:space:]]down[^;&|]*[[:space:]](-[[:alnum:]]*v[[:alnum:]]*|--volumes)([[:space:]]|$)'
'docker(-compose|[[:space:]]+compose)[^;&|]*[[:space:]]rm[^;&|]*[[:space:]](-[[:alnum:]]*v[[:alnum:]]*|--volumes)([[:space:]]|$)'
'docker[[:space:]]+(container[[:space:]]+)?rm[^;&|]*[[:space:]](-[[:alnum:]]*v[[:alnum:]]*|--volumes)([[:space:]]|$)'
'docker[[:space:]]+volume[[:space:]]+(rm|prune)'
'docker[[:space:]]+system[[:space:]]+prune[^;&|]*--volumes'
)hooks/block-db-destroy.sh. If I really want a reset, I run it myself.Guards against waste
Three newer hooks came from reading 90 days of my own transcripts instead of guessing. Agents had spent 322 hours in foreground sleep loops checking on background work that reports back by itself, so a pre-tool-use hook now refuses that and points to the notification:
# Polling = a sleep of 5s or more (any number of minutes or hours) plus a check on something that
# reports by itself. Two shapes: straight-line "sleep, then check", and a while/until loop with both
# inside, where the check usually comes first (in the loop condition). Newlines are flattened.
sleep_re='(^|[;&|({[:space:]])sleep[[:space:]]+(([5-9]|[1-9][0-9]+)(\.[0-9]+)?s?|[0-9]+(\.[0-9]+)?[mh])([[:space:];&|)]|$)'
check_re='/tmp/claude-|tasks/[^[:space:]]*\.output|gh (pr checks|run (view|watch|list))|BashOutput'
flat=$(tr '\n' ' ' <<<"$cmd")
if ! grep -qE "(${sleep_re}).*(${check_re})" <<<"$flat"; then
grep -qE '(^|[;&|({[:space:]])(while|until)[[:space:]]' <<<"$flat" && grep -qE "$sleep_re" <<<"$flat" && grep -qE "$check_re" <<<"$flat" || exit 0
fihooks/block-sleep-poll.sh. A wait loop in the background is still fine.95% of subagent calls named no model, so my rule about choosing one by what a wrong answer costs was mostly not being followed. A rule the agent forgets is a hook, so a general-purpose subagent with no model is now refused, with a pointer to the named agents that carry their own. The third watches context size. The median main-session call was reading 271k tokens, and I'd hit usage limits 188 times. At 300k, 450k and 600k it asks the agent to offer a handoff or a compaction at the next natural break.
The last one installs dependencies when a session starts in a fresh worktree, so parallel sessions don't each begin with a failing test run.
The first real run
The process, applied to itselfI tried the finished setup on an open 3,600-line PR in my household meals app. The reviewer passed it clean three times. It still found a gap each time, including one in a tool description written minutes earlier, during the same run.
The run also found three problems in the skill itself, and I fixed all three the same day:
- My own settings blocked it. The cleanup step deleted a state file with
rm, which my settings deny. Now the file is marked done instead of deleted. - Every nit cost a full review. Each one-line fix set off another three-to-four-minute review of the whole PR. Now small fixes after a clean verdict get a review of just the new commits:
- **Delta review** (only the commits since `lastCleanAt`, plus the code they touch and its callers): when the last verdict was `clean` and the only fixes since were small and local, such as wording, comments, descriptions, a test added, or a one-function change of about 20 lines or fewer. Tell the reviewer: "The PR was reviewed clean at `<sha>`. Review only `<sha>..HEAD` and what it affects." A clean delta review on HEAD counts for the merge gate.skills/pr-loop/SKILL.md.- The gate only watched one repo. The session had started in a different repo from the PR, so the review gate never saw it. Now each PR's worktree is registered, and the hook checks every one the session touched.
Use them
Copy, then make them yoursThe excerpts above come from the full files, which live with this site's source. That repo is private, so if you want the complete set, email me and I'll send them. They're written for me (they address "Kevin" and assume gh, jq and git worktrees), so treat them as a starting point. What transfers is the method: write down what you keep repeating, and enforce what you can't afford to forget.
A script copies them from my ~/.claude into that repo, and refuses to if a file contains anything on this site's denylist. The skills, subagents and hooks in the repo are byte-for-byte the ones I run; CLAUDE.md and the hook settings are the shared parts of my files.
Want an engineer who works like this? Write to me.