Catalogue / open-todos-stop-guard
open-todos-stop-guard
Older skill: source not recordedSignedInstalls a project-local Claude Code Stop hook that reads the session transcript after each reply and, when the newest TodoWrite list still contains pending or in-progress items, holds the session open once and prints the leftovers so they can be finished, re-statused, or offered as GitHub issues wi…--- name: open-todos-stop-guard description: > Installs a project-local Claude Code Stop hook that reads the session transcript after each reply and, when the newest TodoWrite list still contains pending or in-progress items, holds the session open once and prints the leftovers so they can be finished, re-statused, or offered as GitHub issues with the user's per-item approval. Embeds the bash and jq hook script in full, appends a Stop entry to project settings without altering existing hooks, repairs a registration whose script file has gone missing without adding a second entry, checks jq and optionally gh authentication on every path, and dry-runs the hook on sample transcripts. Use when the user wants unfinished session todos surfaced and suggested as issues before a conversation closes. Not for other hook events, general hooks debugging, or issue creation without explicit approval. license: MIT ---
Open Todos Stop Guard
What gets installed
One Stop hook inside the user's project. It runs after every Claude reply and considers only the most recent TodoWrite call in the transcript.
| Newest todo list | Hook behavior | |---|---| | Absent, empty, or every item completed | Exit 0 with no output — the session closes normally | | Holds at least one pending or in_progress item | Exit 2 with the items on stderr — the session stays open once and Claude sees the list | | Stop occurred because a previous stop was blocked (stop_hook_active true) | Exit 0 immediately — a stop chain can never loop |
Everything is produced on the user's machine; nothing is fetched or run from the network.
Settle these with the user first
| Question | How to proceed | |---|---| | Run the gh authentication check? | Default yes. A refusal is recorded as an explicit skip you will report later. | | A different file already sits at the script path? | Show it (path, size, first lines) and ask. Replace only on a clear yes; otherwise keep it and let the dry runs judge it. | | Commit the two files afterwards? | Suggest it; the user types the commit themselves. |
Phase 1 — Inspect and classify
Finish steps 1 and 2 on every visit before following any branch in step 3.
jq --version. The hook parses transcripts with jq; if it is missing, report that and stop. Do not improvise a substitute parser.- Authentication. Run
gh auth status, or, if the user opted out, record "skipped by user choice" as today's observation. If theghexecutable itself is missing, record that instead of running anything. Do this even on the already-registered path that jumps ahead to Phase 4 — Phase 5 may only state a condition that was actually observed. Note exactly one of: succeeded; installed but not logged in; gh not installed; errored or ambiguous output; skipped at user request. - Classify. If
.claude/settings.jsonexists, enumerate registered Stop commands:
jq -r '.hooks.Stop // [] | .[].hooks[]?.command' .claude/settings.json
If any command runs .claude/hooks/open-todos-stop-guard.sh, the hook is registered. Combine with a check for the script file:
| Finding | Route | |---|---| | Registered, script present | Write and merge nothing. Go to Phase 4 and validate what is there. | | Registered, script missing | Repair path: Phase 2 writes the script; Phase 3 is skipped entirely so the existing registration never gains a twin. | | Not registered | Fresh install: Phase 2, then Phase 3. |
Phase 2 — Write the guard script
mkdir -p .claude/hooks. On the fresh-install path only, apply the replacement rule from the decisions table if the target file already exists; the repair path implies it does not. Write the file and chmod +x it:
#!/usr/bin/env bash
# Stop hook: hold the session open once when the newest todo list is unfinished.
set -u
input=$(cat)
# A stop following a blocked stop carries stop_hook_active; pass through so
# the session can always end.
if printf '%s' "$input" | jq -e '.stop_hook_active == true' > /dev/null 2>&1; then
exit 0
fi
transcript=$(printf '%s' "$input" | jq -r '.transcript_path // empty')
# No path or no file: nothing to inspect, allow the stop.
if [ -z "$transcript" ] || [ ! -f "$transcript" ]; then
exit 0
fi
# One line of JSON per TodoWrite call. If jq cannot parse the file end to
# end, discard everything it produced and allow the stop.
if ! last_todos=$(jq -c '
select((.message.content? | type) == "array")
| .message.content[]
| select(.type == "tool_use" and .name == "TodoWrite")
| .input.todos
' "$transcript" 2>/dev/null); then
exit 0
fi
# The bottom line is the most recent list state.
last_todos=$(printf '%s\n' "$last_todos" | tail -n 1)
if [ -z "$last_todos" ] || [ "$last_todos" = "null" ]; then
exit 0
fi
open_todos=$(printf '%s' "$last_todos" | jq -r '
.[]?
| select(.status == "pending" or .status == "in_progress")
| "- [\(.status)] \(.content)"
')
if [ -z "$open_todos" ]; then
exit 0
fi
{
echo "The newest todo list still has open items:"
echo ""
echo "$open_todos"
echo ""
echo "This guard holds the session only once; the next stop passes on its"
echo "own. Act now - finish the items, revise their statuses with"
echo "TodoWrite, or ask the user whether each leftover should become a"
echo "GitHub issue. Create an issue only if the user approves it in this"
echo "turn. Then let the session close."
} >&2
exit 2Why it is shaped this way: stdin carries transcript_path and, on hook-triggered continuations, stop_hook_active; the true-flag test exits 0 first and is the loop guard. A missing path or unreadable file passes. If jq fails partway through, the if ! capture throws away its partial output and passes — the hook never blocks on a half-read transcript. Otherwise the last emitted line is the current list; only pending and in_progress items lead to the stderr message and exit 2, which on a Stop hook keeps the session open and routes the list to Claude.
Phase 3 — Register (fresh installs only)
Repair path: skip this phase. The registration already points at the path you just filled in. Keep that entry exactly as found — its command text, timeout and position, even where they differ from the defaults below — and continue at Phase 4. Appending here would leave two copies firing on every stop.
No settings.json yet: create .claude/ and write:
{
"hooks": {
"Stop": [
{
"hooks": [
{ "type": "command", "command": "bash .claude/hooks/open-todos-stop-guard.sh", "timeout": 15 }
]
}
]
}
}Verify structurally — jq empty passes, jq '.hooks.Stop | length' returns 1, and that command points at the script. There is no prior file to diff against.
File exists: merge, never rewrite. Stop hooks take no matcher, and the relative path works because hooks run from the project root (use an absolute path if the user launches Claude from varying subdirectories). Back up, append, validate, swap in:
backup=$(mktemp) && cp .claude/settings.json "$backup"
tmp=$(mktemp)
jq '.hooks.Stop = ((.hooks.Stop // [])
+ [{hooks:[{type:"command","command":"bash .claude/hooks/open-todos-stop-guard.sh",timeout:15}]}])' \
.claude/settings.json > "$tmp" && jq empty "$tmp" && mv "$tmp" .claude/settings.jsonIf the original file fails to parse before you have changed anything, stop and report; do not guess at repairs. Then verify the invariant: everything except hooks.Stop is unchanged, and hooks.Stop is its old self plus one entry at the end.
norm='del(.hooks.Stop) | if ((.hooks // {}) == {}) then del(.hooks) else . end'
diff <(jq -S "$norm" "$backup") <(jq -S "$norm" .claude/settings.json) # must print nothing
old=$(jq '.hooks.Stop // [] | length' "$backup")
jq -e --argjson n "$old" '(.hooks.Stop | length) == ($n + 1)' .claude/settings.jsonThe normalization deletes the one key you are permitted to change and also drops a hooks object that exists only because your insertion created it, so a settings file that had no hooks key at all still compares clean against its backup. The length check proves one append rather than a replacement or reorder; a final read-back should show prior Stop entries untouched, in order, ahead of yours. If any check fails, put the backup back with a plain copy of it and report.
Phase 4 — Dry runs
Build a JSONL fixture (one JSON object per line), run four cases, clean up:
sample=$(mktemp /tmp/todo-guard.XXXXXX.jsonl)
cat > "$sample" <<'EOF'
{"type":"assistant","message":{"content":[{"type":"tool_use","name":"TodoWrite","input":{"todos":[{"content":"Wire Stripe webhook retries","status":"pending"},{"content":"Bump helm chart to 3.1.0","status":"in_progress"}]}}]}}
{"type":"assistant","message":{"content":[{"type":"tool_use","name":"TodoWrite","input":{"todos":[{"content":"Wire Stripe webhook retries","status":"completed"},{"content":"Bump helm chart to 3.1.0","status":"completed"}]}}]}}
EOF
printf '{"transcript_path":"%s"}\n' "$sample" | bash .claude/hooks/open-todos-stop-guard.sh; echo "run1:$?"
printf '%s\n' '{"type":"assistant","message":{"content":[{"type":"tool_use","name":"TodoWrite","input":{"todos":[{"content":"Wire Stripe webhook retries","status":"completed"},{"content":"Draft v3.2 changelog","status":"pending"}]}}]}}' >> "$sample"
printf '{"transcript_path":"%s"}\n' "$sample" | bash .claude/hooks/open-todos-stop-guard.sh; echo "run2:$?"
printf '{"stop_hook_active":true,"transcript_path":"%s"}\n' "$sample" | bash .claude/hooks/open-todos-stop-guard.sh; echo "run3:$?"
bad=$(mktemp /tmp/todo-guard-bad.XXXXXX); printf '%s\n' '{"type":"assistant","message":' > "$bad"
printf '{"transcript_path":"%s"}\n' "$bad" | bash .claude/hooks/open-todos-stop-guard.sh; echo "run4:$?"
rm -f "$sample" "$bad"| Run | Transcript state | Expected | |---|---|---| | 1 | Earlier list open, newest list all completed | Exit 0, no output — the newest list decides | | 2 | Newest list reopens one item | Exit 2, that item listed on stderr | | 3 | Same as run 2, continuation flag set | Exit 0 — loop guard | | 4 | Truncated, unparseable file | Exit 0 — fail open, partial output discarded |
All four must match before you call the install done. When the user kept a pre-existing script, these runs are its acceptance test; a failure means report and offer the repair path, never a silent swap.
Phase 5 — Closing report
- Files touched: script path, settings path, backup location, and whether the user wants the backup kept or deleted.
- Authentication, phrased strictly from the Phase 1 observation:
| You observed | You report | |---|---| | gh auth status succeeded | authenticated — issue filing will work when approved | | gh installed, no login | not authenticated — the user can log in later if they want issues filed | | gh executable missing | gh missing — todo prompts still work; filing cannot run until it is installed | | Errored or ambiguous output | inconclusive — describe the actual output, choose no other label | | User opted out | unverified — check skipped at the user's request |
Never round an error up to "not authenticated" or a skip down to "authenticated"; state only what you saw. Also tell the user: the hook runs after every reply, stays silent while the newest list is clean, holds a session at most once per stop chain, and its issue suggestions remain plain text until the user approves each specific issue in that moment.
Boundaries
- Never overwrite an existing script file, rewrite a settings entry, or append a second Stop entry for this guard without the explicit confirmations above.
- Never create, edit, or comment on GitHub issues on this skill's or the hook's own initiative — that is visible outside the user's machine, so each issue needs the user's approval of that exact item at the moment it is suggested, plus an authenticated
gh.
Preview shortened. The full SKILL.md is in the pack.
| File | Size | SHA-256 |
|---|---|---|
| SKILL.md | 12.5 kB | 1b2867412a3b |
| THIRD_PARTY_NOTICES.md | 1.4 kB | b1b67b78d493 |
| examples.json | 1.9 kB | 4bd2fe7e9e2e |
Published verbatim from the pinned commit. Nothing is rewritten.
| Version | Pinned commit | Signed | |
|---|---|---|---|
| 1.0.0 Current | Not recorded | 11 Oct 2026 |
Locking a skill to one version needs Pro.