Hooks Reference¶
The draft-only PreToolUse guardrail (registration, matcher, full deny/allow matrix) the advisory decision-checkpoint hook, and the advisory scope-drift and breakpoint hook.
Overview¶
The agentic-contributor plugin registers two PreToolUse hooks plus a PostToolUse, a Stop, and a UserPromptSubmit hook. The first PreToolUse hook is the draft-only guardrail, which runs before every Bash call and every GitHub MCP tool call and denies outbound and mutating actions before they execute. The second is an advisory decision-checkpoint hook for Edit/Write. The PostToolUse, Stop and UserPromptSubmit hooks are one advisory script (track-breakpoint.sh) for scope-drift alerts, breakpoint questions, and predict-then-reveal (predict: auto by default for new sessions: fixed rules switch it on or off; --predict / --no-predict force it). The advisory hooks are active only inside an /oss track session.
The guard applies to every session where the plugin is enabled
The hook is registered by the plugin, not by /oss, so it checks every Bash call in every
Claude Code session while agentic-contributor is enabled, including work that has nothing to
do with /oss. In those sessions git push, gh pr create, and the other commands below are
denied too, and so are write tools on any GitHub MCP server (for example
mcp__github__create_pull_request). To push or open a PR from Claude Code, run the command yourself in a terminal, or
disable the plugin via /plugin and restart the session (hooks are registered at session
start); re-enable it the same way.
Registration (hooks/hooks.json)¶
{
"description": "Draft-only guardrail: blocks all outbound/mutating actions …",
"hooks": {
"PreToolUse": [
{
"matcher": "Bash|mcp__.*[Gg][Ii][Tt][Hh][Uu][Bb].*__.*",
"hooks": [
{
"type": "command",
"command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/scripts/guard-outbound.sh",
"timeout": 30
}
]
},
{
"matcher": "Edit|Write|MultiEdit|NotebookEdit",
"hooks": [
{
"type": "command",
"command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/scripts/track-checkpoint.sh",
"timeout": 5
}
]
}
],
"PostToolUse": [
{
"matcher": "Edit|Write|MultiEdit|NotebookEdit",
"hooks": [
{ "type": "command", "command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/scripts/track-breakpoint.sh", "timeout": 10 }
]
}
],
"UserPromptSubmit": [
{
"hooks": [
{ "type": "command", "command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/scripts/track-breakpoint.sh", "timeout": 10 }
]
}
],
"Stop": [
{
"hooks": [
{ "type": "command", "command": "bash ${CLAUDE_PLUGIN_ROOT}/hooks/scripts/track-breakpoint.sh", "timeout": 15 }
]
}
]
}
}
Matcher: Bash|mcp__.*[Gg][Ii][Tt][Hh][Uu][Bb].*__.* — matches all Bash tool calls and every GitHub MCP tool call: this plugin's own server and any other MCP server with "github" in its name (for example mcp__github__*), so a separately installed GitHub server cannot be used to post.
Timeout: 30 seconds. Typical commands finish in well under 1 second (bash string matching plus a few awk passes, no network calls). A command that contains none of the trigger words gh, git, curl, or wget (checked case-insensitively after deleting quotes, backslashes, and newlines, so g\it or "g"it still count) is allowed immediately. Segments without a trigger word are skipped one by one, so a 400-line script that runs git on every line still finishes in a few seconds. The guard fails closed on very large input rather than running into the timeout (which would allow the command): a command of more than 64 KiB, one with more than 2000 shell separators (;, |, &, parentheses, backticks, newlines, counted before parsing), or one with more than 500 segments that contain a trigger word as a whole word (height or github do not count), is denied with "command too large to analyse safely; split it into smaller commands (or write a script with the Write tool and run it)". Any analysis still running after 10 seconds is denied the same way, because a timeout would allow the command, so the guard never relies on it. The 30-second timeout leaves headroom for slow machines.
guard-outbound.sh Logic¶
The script reads the tool-use JSON from stdin, extracts tool_name and tool_input.command, then checks against deny patterns.
JSON parsing order: jq → python3 → grep (last resort). The grep fallback cannot decode JSON escapes, so it fails closed: a shell command containing any backslash escape (an escaped quote, a newline) or more than one command field is denied, with a message to install jq or python3. Simple one-line commands still work without them; jq is the recommended prerequisite.
Exit codes:
- 0 = allow (read-only / safe operation)
- 2 = deny (outbound/mutating action blocked)
Denial output: JSON emitted to stderr with permissionDecision: "deny" and a message explaining the draft-only contract and the existence of the execution/submission plugin.
Command-position safety: Deny patterns for git push and gh subcommands use a shell regex that matches only at real command positions (start of string or after ;, |, &, &&, ||, $(, backtick, newline). This prevents false positives from strings like echo "gh issue create". A brace-group opener at command position is looked through, including a function header, so the body of { gh pr create; }, function f { git push; }, and f() { git push; } is checked; a { that is not a separate word (echo {a,b}, --format={x}) does not count. Command names (git, gh, curl, wget, and wrappers such as env or sudo) are matched case-insensitively, including path-qualified ones (/usr/bin/GIT push), because macOS filesystems are case-insensitive by default and GIT push runs the real git. Subcommands and flags keep their exact case.
Per-invocation handling (v0.3.1) and heredoc bodies (v0.4.0): gh api flags are evaluated per gh api invocation (the command is split into segments on newline, ;, |, &, (, ), $( and backtick, ignoring separators inside quotes and dropping comments). Before the rules run, backslash-newline continuations are joined. Heredoc bodies are always checked as ordinary lines (the v0.3.1 heredoc-body skipping was removed in v0.4.0 because cat > run.sh <<'EOF' ... EOF followed by sh run.sh could execute a script the guard never saw). A note whose heredoc text mentions an outbound command is therefore denied; use the Write tool to create such files. gh api options are parsed from unquoted tokens, and if segmentation fails a gh api command is denied. Any other preprocessing failure falls back to the raw command. Regression tests: bash hooks/tests/run-guard-tests.sh.
Limits: a tripwire, not a security boundary¶
guard-outbound.sh reads command text. A shell command can be written in endlessly many ways, so text matching cannot block every outbound action. The guard is designed to stop an agent from accidentally pushing or posting while it follows normal draft-only instructions. It is not designed to stop a command that is deliberately written to get past it.
Known gaps are recorded as known-bypass rows in hooks/tests/guard-cases.tsv. They are reported, not counted as failures, and the harness prints a note when one starts being denied. Two kinds:
- Forms an agent may write by accident (covered since v0.5.1): global options before the subcommand (
git -C dir push,git -c k=v push,gh -R owner/repo pr create), path-qualified binaries (/usr/bin/git push,./gh pr create), wrapper prefixes and env assignments (env git push,FOO=1 git push,command,exec,builtin,nohup,time,sudo,xargs,timeout,nice,ionice,stdbuf,setsid,caffeinate,doas,watch,unbuffer,flock,chrt,taskset,coproc), dashed git binaries (/usr/libexec/git-core/git-push,git-send-email), and the extragh,git,curl, andwgetwrite forms listed in the matrix below. Each command segment is normalized (wrappers, assignments, path prefix, and global options removed) and checked in addition to the raw text, so normalization can only add denials. - Indirect routes and other tools (not planned): commands run by another program (
find -exec git push,xargs gitwith the subcommand on stdin), persistent git aliases (git config alias.x pushthengit x),ghextensions (gh extension install …and running one), and other forge CLIs (hub,glab). The read-only token is the boundary for these. - Deliberate obfuscation (not planned): variables (
p=push; git $p),eval, aliases, calling a shell function defined in an earlier command (a function body written in the same command is checked),bash -c "…"strings (and the same class:flock FILE -c "…",watch "…"),$(echo git),IFSand brace-expansion tricks, quoting tricks inside heredocs, and similar. These are realistic only if the agent is manipulated, for example by a prompt injection hidden in an issue, PR, or comment the plugin reads.
The real boundary is the credentials. Give the plugin a GitHub token without write permissions (see GitHub Access). With a read-only token, GitHub itself rejects any write that slips past the guard. git push uses your local git credentials instead, which this plugin cannot restrict; keep Claude Code's permission prompts on for commands you have not allowed.
Deny / Allow Matrix¶
MCP Tools — default DENY, read allowlist¶
Every GitHub MCP server is default-deny: this plugin's own and any other server whose name contains github in any case. The script takes the tool-name suffix after the last __ and allows it only when it names a read tool:
There is no generic *_read rule: mark_all_notifications_read mutates, so only the two named read tools pass. Even with one of those prefixes, a suffix that contains write, create, delete, submit, or fork is denied. A suffix with characters other than a-z, 0-9, and _ is denied too. Every other tool is denied, including tools the upstream GitHub MCP server adds later.
ALLOW examples: get_me, get_file_contents, get_commit, list_issues, list_pull_requests, list_releases, search_code, search_issues, search_repositories, issue_read, pull_request_read.
DENY examples: mark_all_notifications_read, dismiss_notification, manage_notification_subscription, issue_write, sub_issue_write, pull_request_review_write, add_issue_comment, add_comment_to_pending_review, create_pull_request, create_branch, create_repository, create_or_update_file, delete_file, push_files, merge_pull_request, update_pull_request, update_pull_request_branch, fork_repository, assign_copilot_to_issue, request_copilot_review.
Bash Commands — DENY¶
| Pattern checked | Blocked example |
|---|---|
git push at command position |
git push origin main |
git push, git send-email, git send-pack, git svn dcommit, git subtree push, git lfs push, git p4 submit, also after global options (-C, -c, --git-dir, --work-tree, --namespace, --no-pager, …), a path-qualified binary, or a wrapper prefix |
git -C dir push, /usr/bin/git push, env git push |
env -S / --split-string (any spelling, including -iS and abbreviations) in a command that mentions gh/git/curl/wget; the string is not analysed, so it is denied |
env -S "git push origin main" |
git -c alias.<name>=<value> whose value contains push, send-email, send-pack, or dcommit, or starts with ! (shell alias) |
git -c alias.p=push p origin main |
gh pr create/comment/review/edit/merge/close/reopen/lock/unlock/ready/update-branch/revert/--fill; built-in aliases are canonicalised first: new = create, remove/rm = delete, cs = codespace |
gh pr create --title "…", gh pr new |
gh issue create/comment/edit/close/reopen/lock/unlock/delete/transfer/pin/unpin/develop |
gh issue comment 123 --body "…" |
gh release create/edit/delete/delete-asset/upload |
gh release create v1.0 |
gh repo create/fork/delete/edit/sync/rename/archive/unarchive, gh repo deploy-key add/delete, gh repo autolink create/delete |
gh repo fork apache/airflow |
gh gist create/edit/delete/rename |
gh gist create file.txt |
gh label create/edit/delete/clone, gh workflow run/enable/disable, gh run rerun/cancel/delete, gh secret set/delete, gh variable set/delete, gh alias set/delete/import, gh codespace create/delete/edit/stop/rebuild, gh agent-task (aliases agent-tasks, agent, agents) with any subcommand other than list/view (create starts a Copilot coding-agent task that opens a PR) |
gh workflow run ci.yml, gh agent-task create "…" |
gh project create/edit/delete/close/copy/link/unlink/mark-template/item-add/item-create/item-edit/item-delete/item-archive/field-create/field-delete, gh ssh-key add/delete, gh gpg-key add/delete, gh cache delete |
gh project item-add 1 --url … |
any gh form above or gh api with -R/--repo, a wrapper prefix, or a path-qualified binary |
gh -R owner/repo pr create, ./gh pr create |
gh api with -X POST/PUT/PATCH/DELETE (also -XPOST, -X=POST, any case) |
gh api repos/… -X POST -f … |
gh api with --method POST/PUT/PATCH/DELETE (also --method=POST) |
gh api repos/… --method PATCH |
gh api with -f / -F / --field / --raw-field (unless explicit -X GET, or a read-only GraphQL query) |
gh api repos/… -f title=… |
gh api with --input (always) |
gh api repos/… --input body.json |
gh api graphql containing mutation, =@file, command substitution, or a query=$VAR value |
gh api graphql -f query='mutation {…}' |
curl with -X/--request and any method other than GET/HEAD/OPTIONS (any case, also -XPOST, --request=POST) |
curl -X POST https://api.github.com/… |
curl with -d/--data/--data-raw/--data-binary/--data-urlencode/--data=…/-dVALUE/--json, -F/--form/--form-string, -T/--upload-file, or -K/--config (also inside short-option bundles such as -sd, and the curl 8.3+ --expand-<option> forms such as --expand-data). Data options combined with -G/--get are query parameters and are allowed (curl -G -d q=x …); -F, --json, -T, -K and a non-GET -X still deny |
curl -d '{"body":"…"}' … |
wget with mutation flags (--method POST/… in any case, --post-data, --post-file, --body-data, --body-file); wget's -X, -d and -F are not mutation options (exclude-dirs, debug, force-html) and are allowed |
wget --post-data '…' … |
Bash Commands — ALLOW¶
Everything not matched by a deny pattern:
- Help only:
git push --help,git push -h,gh pr create --help(built-in gh groups only; a gh shell alias given--helpwould run, so it is not exempt) curl -G -d q=x …(data options under-G/--getare query parameters)git clone,git status,git log,git diff,git fetch,git checkout(local),git add,git commit(local)gh pr view,gh pr list,gh pr checks,gh pr diffgh issue view,gh issue listgh release list,gh release viewgh project list/view/item-list/field-list,gh ssh-key list,gh gpg-key list,gh cache list,gh repo deploy-key list,gh repo autolink list,gh repo set-default(local only)gh api repos/…(plain GET, no write flags)gh api graphql -f query='query {…}'(read-only query: nomutation, no=@file, no--input)gh api -X GET search/issues -f q=…(explicit GET; fields are query parameters)- Heredocs whose body contains no outbound command text, e.g.
cat > notes.md <<'EOF' … EOFwith plain notes (a body that mentionsgit pushorgh pr createis denied; use the Write tool) gh auth status- Read-only forms with the same prefixes:
git -C dir log,/usr/bin/git status,env git diff,gh -R o/r pr view 1,gh label list,gh workflow list,curl -X GET … - Build/test commands:
mvn,gradle,pytest,npm test,./breeze, etc. cat,grep,find,jq, and other read-only shell commands
track-checkpoint.sh (advisory)¶
Not a safety boundary. The guard above is unchanged. This hook turns a few reviewer-relevant edits into "choose, not approve" questions inside a tracked session and records the answers in the private decision ledger. Concept and usage: Tracked Sessions & Checkpoints. Ledger format: skills/pr-preparation/references/decision-ledger.md.
Matcher: Edit|Write|MultiEdit|NotebookEdit. Timeout: 5 seconds. Bash is not watched (npm install, rm are not caught).
Opt-in. The session pointer is <gitdir>/agentic-contributor/track-active, in the git dir of the repository containing $CLAUDE_PROJECT_DIR (else the hook's working directory). The hook finds it by walking up to the first .git; a .git file (linked worktree, submodule) is followed through its gitdir: line. Without that pointer the hook exits before reading stdin, prints nothing, and spawns no subprocess (builtins only), so large edit payloads cost nothing. Tracked sessions require git: outside a git repository the hook is inactive. A .oss-drafts/.track-active file or ledger committed to a repository is ignored, because git never clones the git dir. Kill switch: OSS_TRACK_DISABLE=1. Paused (no question, no ledger write, a one-time notice) when the checked-out branch differs from the ledger's branch or the pointer is older than OSS_TRACK_MAX_AGE_HOURS (default 24, 0 = off); /oss track resume re-arms it. Also silent when the ledger says status: stopped, in permission_mode: plan, when the edited file is outside the repository root, or when the pointer is invalid (it must name .oss-drafts/track-<name>.md inside the root, no .., no symlinks).
JSON parsing: jq → python3 → silent allow (no grep fallback; this hook fails open).
Output: one hookSpecificOutput JSON object on stdout with exit 0. Exit 2 is never used.
| Situation | Result |
|---|---|
| no session, stopped session, plan mode, any internal error | silent (no output) |
trigger (test weakening, dependency manifest or lock file, opt-in api_paths, outside scope), id not yet settled, budget left |
deny with instructions to ask via AskUserQuestion, append a ledger entry, and retry |
| id already settled, or already logged over budget | silent |
id declined (latest entry has outcome=declined: the user chose not to make the change) |
deny: do not retry; no new question, no ledger line, no budget |
lock file whose sibling manifest has any settled id (dependency:<dir><manifest>#…) |
silent: no question, no ledger line, no budget |
budget spent (default 3 questions asked; scope checkpoints have a separate budget of the same size), or budget: 0 |
additionalContext plus a short systemMessage (no permission decision); a logged-over-budget line is appended |
| second retry without a ledger entry (loop guard) | deny again once; the third attempt gets additionalContext plus a systemMessage (no permission decision) and a skipped line |
append-shaped Edit of the active ledger |
allow (so a checkpoint costs one interruption, not two) |
| any other edit of the ledger (frontmatter change, rewrite, Write, MultiEdit) | no decision: Claude Code's normal permission prompt applies |
The ledger auto-allow is deliberately narrow: only Edit (never Write, MultiEdit, or NotebookEdit) that appends one entry (old_string is <!-- track:end -->, new_string ends with it, no replace_all, and the added text holds no sentinel, track:pending, track:consumed, track:drift (including track:drift-paused), track:breakpoint, track:predict-auto or source=hook), only the active ledger path read from the pointer (compared after normalizing //, ./, .. and logical versus physical roots), a raw file_path with no .., . or empty segment, and nothing when the ledger, the pointer, or .oss-drafts/ is a symlink. Every other edit, including widening scope:, status: stopped and other files in .oss-drafts/, gets no allow, so it still works but is never silent. A decided or skipped entry settles an id only when the hook asked about it (a track:pending line exists), so a pre-written entry settles nothing.
Paths and comments. File paths are normalized before use: src/../package.json and ./src/app.js give the same id as the plain path, and a path outside the repository gets no checkpoint. Comment-only lines (//, # not followed by [ or !, *, and /* ... */ blocks that start a line) are not counted as assertions or skips, so commenting out an assert counts as removing it. Assertions and skips are counted only for test paths, line by line (a token never spans lines), and a payload or existing test file over 512 KiB skips the test-weakening check (fail open).
Not-applicable acknowledgements are matched by count, not timestamp: a status=not-applicable entry answers one pending line and lets one edit through (a track:consumed marker records it). After 3 acknowledged edits for one id the hook logs logged-over-budget ... reason=na-cap instead of asking again.
Checkpoint ids are <class>:<repo-relative path>; a lock file maps to its manifest (yarn.lock is dependency:package.json#…, with the lock file's own #<change>). A lock-file edit is silent once any id of its sibling manifest is settled, so adding a dependency costs one question, not two; a lock file edited with no settled manifest id (for example npm update) is still checkpointed. Test and dependency ids end in #<change>, 8 hex digits of the cksum of the edit's changed-line set (+added / -removed lines, trimmed, sorted; context lines cancel out), so a retry of the same edit keeps its settled id while a second dependency in the same manifest or a second, different test weakening is a new checkpoint (over 512 KiB the id falls back to the bare path). Budget pools: scope checkpoints count against their own budget, the same size as budget, so out-of-scope edits never use up the questions for test, dependency, and api checkpoints. The hook appends only the class, the edited file's repo-relative path, the change checksum, and timestamps with a single >>; it never writes old/new strings or file content into the ledger. A path (or cwd) containing a control character such as a newline or carriage return makes the hook fail open without writing, so a file name cannot forge ledger marker lines.
No ledger text in output. The ledger is repository-writable data, so the hook never echoes scope, api_paths, or any other frontmatter value into permissionDecisionReason, additionalContext, or systemMessage. Messages say "the ledger's scope" or "an API path listed in the ledger" and name only the edited file's repo-relative path.
Context-only notices. The over-budget and loop-guard notices rely on additionalContext in a PreToolUse hook without a permission decision, which needs a Claude Code version that supports PreToolUse additionalContext. On older versions Claude does not see the note, so the hook also sets a top-level systemMessage that the user sees either way.
Locking. Reading state, checking the budget, and appending a pending marker happen under a mkdir lock (<ledger>.lock). The holder writes its pid to <ledger>.lock/pid. A lock whose pid is dead is stale and is broken at once; a lock with no pid file is stale after about 5 seconds (its mtime comes from stat -c %Y (GNU) or stat -f %m (BSD), validated as a number). A stale lock is renamed to a per-process name before removal so a fresh lock is never deleted. If a live holder keeps the lock busy for about 2 seconds the hook fails open.
Harness: bash hooks/tests/run-track-tests.sh (bash 3.2 compatible; builds a fixture git repo in a temp dir per case).
track-breakpoint.sh (advisory)¶
A separate, advisory hook for tracked sessions only. Like track-checkpoint.sh it is not the safety guard, fails open (any internal error means no output and exit 0), prints nothing and starts no subprocess when no session is active (builtins only), needs jq or python3 (else silent), stays silent while the session is paused (other branch, or pointer older than OSS_TRACK_MAX_AGE_HOURS; the checkpoint hook gives the one-time notice), honours OSS_TRACK_DISABLE=1 and permission_mode: plan (PostToolUse and Stop are silent in plan mode; the UserPromptSubmit predict note still runs, see decision-ledger.md section 15), and never reverts, stashes, or edits code. It reads hook_event_name and handles three events:
| Event | What it does | Output |
|---|---|---|
PostToolUse (Edit\|Write\|MultiEdit\|NotebookEdit) |
appends the edited path to the session state file <ledger>.state (ledger writes are never logged). Runs a drift check only when the path is new to the session or every 5th edit; skips the check inside a subagent (agent_id present) |
hookSpecificOutput.additionalContext with a "choose: keep / separate PR / drop / skip" alert. Over the drift cap or with budget: 0 the marker is recorded silently (no output). A new alert waits for a later turn when a question (including a predict question) already interrupted this one. Context, never a block |
Stop |
when stop_hook_active is true, only appends a t turn mark to the state file (under the ledger lock, no parse, no git, no output) and exits, so edits made while a stop was held never count toward the next, possibly chat-only, turn. Otherwise runs the drift check once (skipped when a checkpoint, drift or predict question already interrupted since the last stop, including on the session's first stop before any state file exists, and deferred when the agent's last message already asks the user), then at most one explain-back question, only when the agent edited code since its previous stop (a chat-only turn is never interrupted; deferred edits wait for the next turn with edits) and about a change of at least 5 lines (EXPLAIN_MIN_LINES) |
{"decision":"block","reason":...} with the instructions, at most one block per stop; drift takes precedence. A top-level systemMessage (alone, or with the block) is shown to the user only, the agent does not see it: it summarises drift logged without asking (with budget: 0 or a spent cap nothing is asked) |
UserPromptSubmit |
in any active session (predict on or off), appends a t turn mark to an existing state file (one builtin append, no fork, no parse), so edits before an interrupt never count toward the new turn. Then, with predict: true, or predict: auto when the fixed rules (newcomer, skipped explain-back, many prior unknowns; off after two "no idea") compute on, budget > 0, an active session, fewer than predict_max (default 4) predict:<n> ledger entries, and a prompt that is not empty, not a slash command (/name or /name; a path like /src/a.c:4 is text) and not trivial (24 UTF-8 bytes or fewer, no ?, no diagnosis or planning keyword), adds the predict-then-reveal instruction. No git. Plan mode still predicts. Writes: in auto, a track:predict-auto switch marker under the ledger lock (busy lock = skip, fail open), logged when auto is evaluated; and a p<TAB><sid> line in the state file after the first full note (later prompts get a short reminder) |
hookSpecificOutput.additionalContext (hookEventName: "UserPromptSubmit"), never a block. The text shows (auto: <reason>) in auto mode. The instruction is scoped with "only if this prompt asks you to diagnose a problem or propose a plan"; the agent records a predict:<n> entry itself (outcome: pending, then a separate track:outcome block at the reveal). A predict entry counts toward the explain-back watermark |
Caps (separate pools, in the ledger frontmatter): checkpoints budget 3, drift drift_max 2, breakpoint questions explain_max 4 at least explain_interval_min 20 minutes apart. budget: 0 is quiet mode. Drift thresholds are drift_lines 400 and drift_files 10 (strictly greater; the alert labels each limit with its source, default when it is at its default value), plus out-of-scope modules that no checkpoint covered (a logged-over-budget log does not count as covered).
Loop safety: stop_hook_active exit (after the t turn mark), the ledger marker and the state b line are written before the block is emitted, the state m watermark is advanced on every stop (the state file is created if needed), including one that holds for a drift question, and is written before that block, ledger-based count and interval caps, and a per-session non-interactive latch so claude -p never hangs. Rate-limit state lives in the ledger (track:drift, track:breakpoint), so the disposable state file cannot lift a cap. Timestamps use the same normalisation as v0.8.0 (a malformed or future epoch=/at= reads as oldest) and the same <ledger>.lock directory (a lock with no pid file is stale after about 5 seconds, a dead holder's lock is broken at once; a busy lock fails open).
Git use is read-only and bounded: GIT_OPTIONAL_LOCKS=0 GIT_LITERAL_PATHSPECS=1 git -C <root> -c core.quotepath=off ... --no-ext-diff --no-textconv plus --no-renames (scope and module paths) or -M (size totals and the explain-back target), never inside the ledger lock. If the agent does not act on PostToolUse context, emit_json post can switch to a block (a one-line change).
Opt-in and input. Same session lookup as track-checkpoint.sh: the git-dir pointer is checked before stdin is read; a committed in-worktree pointer is ignored. A file_path, cwd, or other input field with a control character is treated as empty (fail open, nothing written). Ledger text (scope, drift_source, any frontmatter value) is never echoed; the drift source is shown as a fixed label.
Base moved. If the session base is no longer an ancestor of HEAD, or a merge commit landed since it, drift and explain-back pause and the hook says once "base moved — drift paused; restart tracking (/oss track stop + start) to re-baseline" (a track:drift-paused ledger line records it). A fast-forward pull is not detected.
Input fields by Claude Code version. Two optional fields need a Claude Code version that sends them: last_assistant_message on Stop (skip the breakpoint question when the agent's last message already ends with ?) and agent_id on PostToolUse inside a subagent (defer the drift check to the main thread). Without them the hook still works: a breakpoint question may follow a question the agent just asked, and a subagent's edits run the throttled drift check themselves.
State file. <ledger>.state is compacted above 400 lines to a short prefix plus the newest 100 lines, preserving what the hook reads (see decision-ledger.md section 11).
Code shared with track-checkpoint.sh lives between # --- shared: <name> (keep identical in track-*.sh) --- and # --- end shared --- lines (session lookup, list cleaning, manifest map, glob match, lock helpers) and is checked for byte-equality by the harness.
Harness: bash hooks/tests/run-breakpoint-tests.sh (bash 3.2 compatible; fixture git repo per case with the pointer in the git dir, run from the fixture root; loop, parallel-lock, python3-fallback, shared-code, base-moved, compaction, ledger-injection, and .git-file worktree checks).
Back to docs index | Related: Draft-Only Guardrail | Commands | GitHub Access