Agent Harness Reference
This page holds the facts of the agent harness. Read it to look one fact up. It covers which hook blocks what, which command-line scripts help the main loop, and what the installers change. The story of a call, the lookup for a denial text and the routes by kind of work are on Agent Harness. The rules for model, effort and cost are on Dispatch Economy.
On this page: Routes · Hooks at a glance · Hook catalogue · Turn guard · Timer waits · Lane nudge · Process ownership · Refresh gate · Brief gates · Command-line scripts · State files · What the installer changes · The global CLAUDE.md block · Install step · Evidence
The harness never changes WHICH reviews run. The rosters, the mandatory core and the gates stay in
verification-routing.md and in the pipelines. Economy prices a reviewer and never removes one.
|
evidence §N on this page cites section N of the evidence file named in Evidence.
|
Routes
The main loop is the Claude Code session in which you talk to the orchestrators. It decides and approves but does not do the work. A lane is one running top-level orchestrator. The table of routes by kind of work is on Agent Harness, Which route a kind of work takes.
Below the orchestrators, the leaves write code (*-coding-agent, and ft-ui-ux-design for
presentation). The reviewers refute the code (verifier lenses and ft-test-adversary). The doc writer
documents it. ft-ui-ux-design routes each design property to its skill and never reviews its own diff
(evidence §71).
Other pieces of the harness:
| Piece | What it does |
|---|---|
|
The canon for model and effort per dispatch, escalation, unit size, slices, who decides and the report lines. |
|
The orchestrator’s own context: one sanctioned reset, and where knowledge is written by what it costs to load. |
|
Jev, a small external decision model that is asked first on enumerable choices. See Decision model (Jev). |
|
The orchestrator calls it after each unit. It compares the delivered size and the new files with the pick and journals the result in one command. |
|
Hosts ONE |
|
Runs ONE operational batch on |
|
The install step that wires the hooks into |
Preview push of the git safety hook
The hook has one exception to the push block. The exception exists only for the release ring preview in
Release rings. It runs for Claude Code only. Codex installs no ring hook, so no preview ring runs there. Codex runs two hooks, the readonly-role-guard and the spawn price gate, and neither is a ring. See Codex.
Flag. Only ft-ops starts the hook with --allow-preview-push. Any other agent keeps the normal block on every push.
The flag has an effect only when the command starts with git -C ` and contains ` push --force-with-lease=refs/heads/preview/.
Every other command takes the normal path unchanged.
Command form. The command must match this form exactly. The <repo> value is an absolute path of the characters A-Z a-z 0-9 _ . / -. The <last sha sent> value is empty for the first push of a run, so the lease ends with the colon.
git -C <repo> push --force-with-lease=refs/heads/preview/<slug>:<last sha sent> origin <sha>:refs/heads/preview/<slug>
Allowed repositories. The hook pushes to an origin that is one of these two repositories, with the base branch in the second column.
| Repository | Base branch |
|---|---|
|
|
|
|
Checks. The hook runs seven checks in order. The first failing check refuses the push with exit code 2 and names the step.
| Step | Name | What the hook checks |
|---|---|---|
1 |
form |
The command matches the canonical form. |
2 |
slug |
The lease slug and the push slug are equal. The slug has 1 to 100 characters of |
3 |
target |
The directory is a work tree. |
4 |
config |
The repository sets no local |
5 |
base tip |
|
6 |
held |
The pushed commit changes no held path between the base tip and the pushed commit. |
7 |
content |
No added line of any commit between the base tip and the pushed commit, and none in the cumulative diff from the base tip to the pushed commit, holds a token signature. In |
Held paths. The held list lives only in the script. To see the step that refuses a push, run git-safety-check.sh --preview-check '<the push command>'.
The command pushes nothing. It prints ok and exits with code 0, or prints the refusing step and exits with code 2.
The held list covers workflow files, the Maven build files, Dockerfiles and the repository profile. These are the inputs that run in a step that holds a registry credential.
It is not a list of files that a preview may never carry for any other reason.
The command --preview-check also scans the workflows of the base tip: every file under .github/workflows that ends in .yml or .yaml, in any letter case, listed from the top of the repository. Every event must be on a fixed list of events that creating a branch cannot start (for example pull_request, workflow_dispatch or schedule); create, workflow_run and any other name refuse. A push trigger needs a branches, branches-ignore, tags or tags-ignore filter. A branches entry passes only in two cases, where a plain name holds only letters, digits, ., _ and -: the entry is a plain name with no /, such as main (a bare preview or refs passes too, because it cannot equal preview/<slug>), or its first path segment is a plain name other than preview or refs and the first / is followed by nothing, a plain-name character or , such as release/. Every other entry refuses, for example , , v*, //, pre/?view/, pre/{0}view/**, previ{1}ew/**, !main, null, ~ and every preview/… or refs/… entry in any letter case. A branches-ignore list passes only when one entry surely covers preview/<slug> and no entry starts with !. An entry that starts with **/ refuses. The two delivered preview workflows, build-preview.yml in oneiot_backend and preview.yml in ft-acs-qa-console, are not judged while their content is exactly the delivered one. A file the reader cannot read refuses. The real push does not run this scan.
Failure mode. The preview branch is fail-closed. An unexpected error (ERR trap) or a deadline of 20 seconds for all git calls and the scans exits with code 2, never 0. The refusal names the step in progress. The allow branch runs as its own process, and the hook reads its exit status: anything but 0 is a refusal.
The normal path is fail-open: it allows a command that it cannot read. One case is excluded: a helper process of the hook that did not do its job. That is a grep with a status above 1, any non-zero status of awk, sed or tr (a SIGKILL under heavy load, status 137, is the usual cause, but a plain failure counts too), and a jq or cat killed by a signal (status 128 or above; a jq that rejects a malformed payload stays fail-open).
The command was then judged on an empty or partial copy, so the hook blocks it with the text the helper process '<name>' failed (status N), so the command could not be judged and is refused. Retry the command. (fail-closed, exit code 2).
The ft-ops hook entry sets a timeout of 30 seconds, which is longer than the internal deadline.
Hardening of the normal path. The hook also matches each command after it removes ', " and \, so git 'push' origin main blocks.
It first joins a line that ends in \ with the next line, as the shell does.
It also blocks git send-pack, git http-push and git subtree push.
It blocks a gh api call that writes: a REST call with a method other than GET, or with a field or input flag, on a path with git/refs, git/tags, /contents/, /merges, /merge, update-branch, /branches/<name>/rename, /dispatches, /pulls or default_branch,
and a gh api graphql call when the command names a ref, merge, pull request creation or revert mutation on any of its lines, or reads the query from a file. A gh api read passes.
It blocks the gh commands that reach the same writes: gh pr create (and its alias gh pr new), gh pr revert, gh pr update-branch, gh workflow run, gh repo sync and gh repo edit --default-branch.
A gh option before the command group, between the group and its command, or before api does not hide the command or the write. This holds for a value glued to its flag (-R<owner>/<repo>) and for a quoted value with spaces.
The hook also reads a quoted argument as the one word the shell passes, so a ;, & or | inside quotes does not split a command.
These readings can block a gh api read whose text names a write path or a mutation. That is the fail-safe direction.
Declared residual. The hook checks typed commands only. It does not stop a git or gh alias that is defined and then invoked, a script file that pushes,
another language that calls git, or a background job that changes configuration or refs between the check and the push.
Its reading of shell quoting is partial.
A $'..' (ANSI-C) string is decoded the way bash decodes it before the command is judged again: git $'push', git $'\x70ush', gh $'pr' create and gh api -X $'DELETE' .. block, and $'a b' is one word. The decoder handles \a \b \e \E \f \n \r \t \v \\ \' \" \? \nnn \xHH \uHHHH \UHHHHHHHH \cX; a result that is syntax outside quotes (a space, ;, &, |, a quote, a backslash, a control character) becomes _, and a code point above 127 becomes ?. It is run in two quote-state readings (one per line with the comment rule, one across lines without it), like the quote copies below. The decoder also reads a $'..' inside "$(..)" and inside backticks in double quotes, and drops the $ of a locale string $".." (bash reads it as ".."). A $' left open on a line (for example in a heredoc body) ends with that line in the per-line reading.
Declared residuals of this decoder (fail-open): a decoded space or newline that the shell reads again as syntax (eval $'git\x20push origin main', bash -c $'git\x20push'), because the decoder makes it word text; a $'..' in a run without jq, where the raw JSON quote state hides it; a heredoc body and a $' that share a command in a way the decoder’s own quote reading does not follow.
A space or ;, &, | escaped with \ outside quotes counts as part of its word. The hook judges six readings of the quotes: one whose quote state ends at each line, three that carry over lines (one copies the body of a heredoc as it is, so an odd quote in a plain heredoc body does not corrupt the quote state; one is the narrower round-4 form of the same, kept unchanged; one skips nothing), and two that do not treat as a comment start, one per line and one carrying over lines (a after $(..), inside backticks or inside ${..} is word text). It blocks if any reading blocks. So an unbalanced quote in a comment or a heredoc body no longer corrupts the reading of the command below it, and a word quoted across lines stays one word.
The body of a quoted heredoc is not read as a command in one narrow shape only: the whole command is cat > F <<'W', cat <<'W' > F or tee [-a] F <<'W', optionally after cd <word> &&. F is one plain word ending in .md, .adoc or .txt, with no $, no .git/, no /dev/ and no /proc/. Line 1 holds exactly one <<. The body ends at the first line equal to W, and only blank lines follow it. Anything else is read in full, which is a fail-safe false block: a second statement, a second <<, <←, an unquoted delimiter, a pipe, a variable in the file name, or a follow-up such as git add F in the same command.
The carry-over readings take the command before its backslash-newline pairs are joined and join them themselves outside heredoc bodies, so a \ at the end of a quoted heredoc body line neither merges the line with the terminator nor swallows the command below. The reading that skips heredoc bodies reads the delimiter as the shell does (quotes and backslashes removed): <<\EOF, <←EOF, << -EOF (the delimiter is -EOF), <<END-X, <<a.b and <<E"O"F each have their own delimiter, one line may open several heredocs (their bodies follow in order), and a heredoc inside "$(..)" counts. A << inside $.. or $[..] is a shift, not a heredoc (a bare .. is not tracked by this reading; the earlier reading of round 4, which copies a plain-name heredoc body as it is and does not know .. or backslash-continued delimiters, is kept and judged as an extra pass on the joined command, together with the carry-over readings on both the joined and the unjoined text, so every form blocked before round 5 is still blocked and the newer readings only add blocks). In an unquoted-delimiter heredoc a backslash-newline joins body lines before the terminator is compared. So an odd quote in the body of these heredocs no longer lets a write whose quoted word spans lines through.
Declared residuals (fail-open), found by the Gate B review and not closed in round 5: an empty delimiter (<<""), a delimiter with $(..), and a heredoc inside "$(..)" whose substitution holds an inner " or a bare ) before it (the substitution depth is a counter, not a parser). Also open and older than round 5: git itself is judged only on the plain and quote-stripped copies, so a git -c value with a newline in quotes before the subcommand hides it; git pu$()sh, git${IFS}push and {git,push} are allowed.
Also open, fail-open, and the same on c0a6790: a gh write that sits inside a quoted string and has a quoted word with a space in it, such as "$(gh pr --title 'a b' create)", eval "gh pr --title 'a b' create" and bash -c 'gh pr --title "a b" create'. The hook turns the spaces inside quotes into word text, so it no longer sees gh as a command word there. Reading quoted text as a command again would also block ordinary messages that only mention such a command, so it is left open on purpose. The same text without a space inside the inner quotes (eval "gh pr create") is blocked.
A heredoc delimiter continued over a line (<<E\<newline>OF) is refused outright, because the readings cannot follow it (a rare false block). The vault exemption covers only a push whose arguments are plain words: an argument that starts with a quote, a backslash, $ or a backtick, or that holds a + (a forced refspec), is not exempt, so git -C "$FT_VAULT_PATH" push '--force' and push origin +main block.
Indirect execution (cat f | bash), a file that a later tool call runs, and a process started by an earlier call that reads the file are not seen, because the hook checks typed commands only. This fails open. A .md file that Claude Code itself runs (command or skill files with ! lines) is not seen either.
A multi-line commit message that quotes a PR-creation phrase on a later line is now blocked (a fail-safe false block), because the per-line reading sees that phrase outside a quote. A gh api read that carries -X GET -H X:\ -X\ DELETE is also blocked, because the copy without backslashes is judged first.
gh api /graphql, a graphql URL, and either with a query string, a fragment or a trailing slash are read as GraphQL, because on github.com gh sends them to the same endpoint. On a GitHub Enterprise host that path is not the GraphQL endpoint, and the reading there is the fail-safe one.
A command long enough to outlast the hook timeout is allowed, because the normal path is fail-open. The gh api segment checks no longer fork a process per segment and run the whole-command GraphQL search once, so a command with many gh api segments is faster than before (60 GraphQL segments: 367 grep calls, now 9).
Residual: a killed helper under load. Under a load of about 10 to 14 on this host, short child processes were killed from outside with SIGKILL (the shell reports Killed: 9; status 137). The hook’s own watchdog was not the sender: it kills only at the 20 second deadline or past the output cap, and each of those refusals says timeout or git output above, which no failing run showed. Before this fix a killed awk, sed, tr or grep on the normal path read as no match, and a real push passed (fail-open); a test that kills each helper in turn reproduced it. Now the normal path refuses with the text above. The preview branch was already fail-closed: a killed child gives a refusal such as cannot size the git output, and the caller turns any status but 0 into exit code 2. A self-test row that expects another refusal text can therefore fail under heavy load without a product defect; it is not a budget problem, because FT_PREVIEW_ROOM (read only under --selftest) already gives those rows 120 seconds. Rows pin that: one runs the script as its own process with the payload on standard input, FT_PREVIEW_ROOM=1 and a git that answers 3 seconds late, and it must reach the repo allowlist (the production process ignores the room and keeps its 20 seconds); the same child under --selftest must refuse with timeout; and a push on standard input must exit 2 with and without --allow-preview-push. The self-test’s check rows tell a dead helper from a verdict: a block that came from a dead helper is retried twice and then fails with helper failure (no verdict, not a pattern result), instead of passing a row that wants a block. The kill-the-n-th-call loop also covers the preview branch: for each tool the branch calls, killing the n-th call (every n) of the happy-path push must give exit code 2, never 0. The production budget of 20 seconds and the 600 second limit of the regression test are unchanged. A killed jq or cat refuses the same way (the raw payload is not the command text). The helpers read their input from a here-string, which bash may route through a temporary file; if that file cannot be created the status reads as no match, and the earlier sed on the same input fails first and blocks. Declared residual: if the hook process itself is killed, no script can refuse; Claude Code reads a status other than 2 as non-blocking.
bash 3.2. The hook runs through #!/usr/bin/env bash, which is bash 3.2 on a stock macOS. The hook itself needs nothing newer: /bin/bash git-safety-check.sh --selftest passes. Before round 5 it printed 108 FAIL lines there, all from one idiom of the self-test code (a case pattern without its leading ( inside $( ), which bash 3.2 cannot parse), none from the hook. A self-test row now fails if that idiom comes back.
The commands gh release and gh pr merge stay allowed for the hook agents, because ft-ops performs releases and merges.
Work push of the git safety hook
The hook has a second exception to the push block. The owner ruling of 2026-11-10 allows an agent to push a work branch, open its pull request and rerun its CI. The exception runs for Claude Code only.
Flag. Only ft-ops starts the hook with --allow-work-push. The frontmatter of agents/ft-ops.md sets it next to --allow-preview-push. Any other agent keeps the normal block on every push.
The hook checks the flag only for a command that the normal path blocks, and for a command that starts with gh run rerun. It never turns an allowed command into a refusal.
Admitted commands. The hook admits exactly three commands. Each must be the whole command, with no chaining, quote tricks or redirection.
| Form | Command |
|---|---|
Push |
|
Pull request |
|
CI rerun |
|
Conditions of the push. The push sends one 40-character hex commit to a refs/heads branch that is not protected. The origin of the directory must be a Friendly-Technologies repository on github.com, and the repository must pass steps 3 and 4 of the preview push. Give the directory with cd or with -C, not both. Without either, the hook uses the working directory of the call.
The protected branches are master, main, release/, feature/generic-hazel-bridge, preview/, HEAD and refs/*, in any letter case.
Owner exception. The owner can name repositories outside Friendly-Technologies in ~/.local/state/ft-ai-toolkit/push-exception.json: {"repos": ["owner/repo", "owner/"], "until": "YYYY-MM-DDTHH:MM"}, in local time; owner/ covers every repository of that owner. Until that time a push to a listed repository passes the same canonical form to any branch, the protected ones included, except HEAD and refs/*. Every other condition and refusal stays. A missing file, no jq, a broken file or a past until means no exception. Deleting the file closes it.
Conditions of the gh commands. Exactly one -R Friendly-Technologies/<repo> is required. gh pr create also needs exactly one --head <branch>, so gh does not push the current branch itself. The options --admin and --auto refuse. gh run rerun takes a numeric run id first, then only --failed and -R.
Refused. The hook refuses a protected branch, a force (a + refspec, --force, --force-with-lease), a delete (:<branch> or --delete), any option after push, and any chaining or shell syntax (;, &, |, a redirection, $, a backtick).
Refusal text. The hook exits with code 2 and writes this format to stderr. The <rule> names the failed rule, for example chain, form, flag, remote, refspec, branch, target, repo or head.
git-safety hook: work command refused: <rule>: <detail>
Failure mode. The work branch is fail-closed in the same way as the preview branch. It runs as its own process, and any status but 0 is a refusal.
Declared residual. The strictness for gh run rerun is no boundary: a command with a leading space, such as ` gh run rerun x`, takes the normal path, which allows it. The hook does not see the shell environment of the agent (GIT_CONFIG_*, GH_REPO, a shell function named git or gh).
Auto mode. The classifier of Claude Code auto mode is a separate layer. You configure it in the settings of the user, not in this hook. A command can pass this hook and still need a permission there.
Hooks at a glance
Eleven hooks have install code a in the Hook catalogue. The installer registers ten of them
in settings.json. The eleventh, git-safety-check.sh, runs from the frontmatter of four agents. The table shows the
event that each hook fires on and what it blocks or does. Three of the eleven never block: main-compact.py,
main-rules.py and artifact-registry.py. lane-nudge.py blocks one stop, and at most once an hour for each
session. The health notice of lane-nudge.py is a block of its own, at most once every 300 seconds. The Hook catalogue states the same facts with the reason and the step for each hook.
| Fires on | Hook | Timeout | Blocks or does |
|---|---|---|---|
|
|
15 s |
Unpriced dispatch, route rules, lane cap, leaf past 200K |
|
|
5 s |
Maven or git write in a guarded checkout (sub-agent); |
xargs kill`); |
|
|
5 s |
Unquoted heredoc with backticks |
|
|
5 s |
A decoded payload ( |
|
|
None stated. The |
push, PR, |
|
|
10 s |
A hand-back of a sub-agent that leaves live things of its own unnamed, once for each set of things |
|
|
10 s |
Never blocks. It ends the unnamed wait commands of a finished agent and writes a record. |
|
|
5 s |
A refresh brief that declares no inputs (once), and a refresh whose inputs did not change |
|
|
10 s |
Turn end with nothing running |
|
|
10 s |
Never blocks. It types |
|
|
15 s |
A stop while fewer lanes run than the status line says, at most once an hour |
|
|
5 s |
Never blocks. It gives the main loop its own rules. |
|
|
5 s |
Never blocks. It records the link of a published artifact. |
|
|
5 s |
Hook catalogue
deploy/templates/hooks/ ships 29 scripts and 3 JSON policy files. The Installed line of each hook uses three
codes. They are checked against deploy/scripts/economy.py, install.sh and install.ps1:
| Code | Meaning |
|---|---|
a |
Copied to |
b |
Copied to |
c |
Shipped in the repository only. No installer copies or registers it. To use one, copy it to |
Every hook fails open: an internal error exits without a decision and denies nothing. Seven hooks of
code c ignore a call from a sub-agent (a payload with an agent_id): phase-gate.py,
reuse-gate.py, verify-gate.py, durability-gate.py, rules-loader.py, design-gate.py and
context-guard.py. Most of them deny each item at most once per session. verify-gate.py blocks at
most twice per session. phase-gate.py denies until you record a route. A blocked call passes on retry
after you satisfy the denial text.
| Hook, install code, event | What it denies or does | Why | If it blocks you |
|---|---|---|---|
|
Refuses a dispatch that is not priced. It checks model, effort, lane cap, unit size, the route rules ( |
An unpriced dispatch is paid for before anyone can object. |
Read the deny text: it names the rule. Add the missing line to the brief or use the named route. The rules are on Dispatch Economy. |
For a sub-agent: Maven and git writes in a checkout listed in |
The Bash working directory resets to your main checkout after every call. Two shells that wait on one pattern never end. A wait on a timer ends whether or not the awaited event happened, and each wake re-reads the whole context. |
Work in a worktree under |
|
An unquoted heredoc whose text holds backticks. |
Bash runs the backticks, and a backticked command can destroy files. |
Quote the delimiter: |
|
A decoder ( |
The permission reviewer cannot read what an encoded payload runs (2026-11-13: an encoded script piped into bash inside an ssh command). |
Send the plain script: scp or rsync the file, or use a quoted heredoc. Decoding to a file or to stdout is allowed. |
|
Blocks once a turn end with nothing running, for |
The harness turns that turn end into a forced hand-back. |
Follow the instruction in the block. See The turn guard. |
|
Never blocks. When the last turn of the main loop holds 300K tokens or more ( |
No setting reaches the main loop alone. |
Nothing to satisfy. In any other terminal, type |
|
|
Never blocks. Gives the main loop the text of The |
|
Nothing to satisfy. It fails open: a missing file gives no context and the session starts. Put machine-specific main-loop rules in |
Blocks the stop of the main loop once, with a short reason, when its own status line says |
The audit of 31 October to 2 November found 28 owner messages about lanes. A lane count that follows the target needs a check in code. |
Start the next backlog items. If you cannot, say in one line |
|
|
On the hand-back of a sub-agent, it denies once when the agent still owns live things that its report does not name. It also refuses the hand-back of an |
A finished agent left worktrees, browser sessions, detached processes and wait shells behind, and nobody owned them. |
End each thing, or name it in the report as |
|
Skips a refresh dispatch whose declared inputs did not change since the last refresh. It also denies once a refresh brief that declares no inputs. See Refresh gate. |
A status page that is refreshed on a timer costs a full agent run, also when nothing changed (26 unconditional hourly refreshes, $28). |
Add |
|
Appends one JSON line for each published artifact to |
After an account switch an old link returns 404. The same audit found 7 owner requests to republish. |
Nothing to satisfy. To stop recording, remove its |
|
Asks the decision model (Jev). Prints |
An enumerable choice costs less to ask than to deliberate. |
It never blocks. Without the key at |
|
Prints the zone status, diff size, new files, new-surface paths and a |
One command replaces three to five bookkeeping turns per unit. |
It never blocks. Read the verdict line and decide on |
|
Prints a table of the running sub-agents and how long each has been silent. See lane-status.py. |
One command replaces the "where are the lanes" questions. |
It never blocks. Exit 2 when it finds no session. |
Writes a note into the team vault with its hub entry, commit and push. See vault-note.py. |
The same audit priced vault work at about $336 at list price. The steps are fixed, so one command can do them. |
It refuses a note, with a line that names the fix. Exit 1, 2, 3, 4, 5 or 130: see the script section. |
|
Prints cost, mechanical errors, waits and vault work over the last transcripts. See session-audit.py. |
The audit numbers came from one-off scans. The script repeats them on any machine. |
It never blocks. Exit 2 on a bad date. |
|
|
Chooses the verifier lenses for a change. See Brief gates. |
Routing is a computation over paths and diff lines. |
Exit 1 means a conservative default applied. Exit 2 means a refused override. |
|
Stores evidence packs and recorded verdicts. See Brief gates. |
A repeat review over identical input need not be paid for twice. |
It never blocks. |
|
Exit 2 on |
The Iron Laws (no push, no PR, no history rewrite) need a check in code, not only in a prompt. |
An agent cannot satisfy it. Do the operation yourself, with your consent, outside the agent’s |
|
Not installed, by the owner’s ruling of 2026-11-03. Registered by hand: eight brief rules, R1 to R8, plus the route citation rules R9 and R10. See Brief gates. |
A brief is checked before the dispatch is paid for. |
Fix every violation that the deny text lists in one pass, or record |
|
Denies an implementation write in the main loop until you record a route with |
Phases that |
Run the |
|
Denies once per moment until you answer the reuse check in |
Searching costs minutes. Removing a written duplicate costs a refactor. |
Search the graph and the repository. State one line: |
|
Blocks the end of a session that changed code with fewer than two different |
A change reviewed only by its author is not reviewed. |
Dispatch two different |
|
Denies once per path a note written under the scratchpad or |
The scratchpad does not survive a reboot. |
Write it where it lives: the repository docs directory, the vault, the memory directory or the run journal. For a real throwaway, say so in one line and retry. |
Never blocks. Adds the code graph’s context to a shell code search, or the file map to a whole-file read of a code file. Needs |
A whole-file read costs about 13.6 KB. The graph’s map costs under 1 KB. |
Nothing to satisfy. Read a line range after the map. |
|
|
Denies once: a full-page capture, a transcript read ( |
Images and transcript reads fill the context (measurement). |
Capture the viewport or an element, ask for a new range, or say in one line why you need the same bytes again. |
|
Denies a write once per item until the session has seen the rule modules whose |
Claude Code loads |
Read the rule modules you touch and dispatch the named standard skill. Retry. See Rules. |
|
Never blocks. Adds a pointer to |
A file-type trigger misses a controller that writes a sentence. |
Apply the user-visible Definition of Done. |
|
Denies the first edit to a user-facing file until the session names the design owner skill, or says in one line that no design property applies. A prompt that names a design property gets the owner as a hint. See UI/UX. |
Nothing executed the routing table in |
Dispatch the owner skill from the routing table, or state which properties are in play and why none applies. |
The turn guard
A background sub-agent can end a turn with plain text while no child agent and no own background
command runs. The harness then tells it to deliver its report ([handback-send-enforce]), and that
ends its run. For an orchestrator in the middle of a unit this is a lost lane. It hands back half-done
and is relaunched from its journal. This happens to orchestrators that wait on an idle child, on an
armed Monitor, or on a report that has already arrived.
turn-guard.py runs on SubagentStop, before the harness’s enforcement. It runs only for
ft-developer, bugfix-agent, refactor-agent and ft-fix-host. A probe in an interactive session verified it (evidence §11). Since Claude Code 2.1.309 the harness text
may arrive just before the block. The agent still keeps its run. The guard blocks that one turn end, once, with the instruction to follow instead:
| Situation at the turn end | What the guard says |
|---|---|
A child agent went idle on its own work and has not delivered |
Wait in the background for the child’s next |
No child is running and a |
A |
No child is open, and the turn ended on "waiting" words ("waiting", "watching", "monitoring", "once it arrives", …) |
A report that was already delivered is in your context: act on it. A job, CI run or demo step is waited for by ONE background command that ends with it ( |
The guard lets the turn end in these cases:
-
A child is running as the harness counts it. A child counts from its dispatch, or from a message of its parent that resumed it, until its first end of turn. A child that woke on its own background job no longer counts.
-
One of the agent’s own background commands has not reported back.
-
The guard already blocked once (
stop_hook_active). -
The agent has delivered its report.
-
The guard itself errors.
The guard never blocks on a file. It opens every file non-blocking, and the file must be a regular file. The size cap is 1 MiB for a meta file and for lane-ended.json, and 8 MiB for a journal or unit report. A meta file or transcript that is refused or over the cap is an error on the verdict path, and the guard allows the turn end (fail-open). Other paths have their own outcome, and none of them changes the turn-end decision:
-
A refused journal is skipped as a candidate.
-
A refused or oversized (over 8 MiB) unit report is not saved.
-
A refused or oversized leaf meta, parent meta or own transcript on the save path also means the unit report is not saved.
-
A refused own meta on the lane-end path is treated as missing, so the lane is stamped as top-level.
-
An unreadable
lane-ended.jsonis replaced by a fresh file. If the path is a directory, the replace fails and nothing is written. If it is over 1 MiB, it is reset to the stamp of the current session only.
Three effects are visible to an operator:
-
A symlinked
turn-guard.logloses its log lines. -
A symlinked
lane-ended.jsonis replaced by a regular file. -
A unit report whose final path component is a symlink is not saved. The write opens the path with
O_NOFOLLOWand fails withELOOP.
The guard logs its decisions to ~/.local/state/ft-ai-toolkit/turn-guard.log.
python3 ~/.claude/hooks/turn-guard.py --selftest runs its cases. The replay that measured the guard is
in Evidence.
Timer waits
checkout-guard.py denies a Bash command that only waits on a timer. The denial applies to the main loop and
to every agent, in the foreground and with run_in_background. A timer wait ends whether or not the awaited
event happened, and each wake re-reads the whole context. The audit of 31 October to 2 November counted 482 turns
that the harness refused for a bare sleep.
The hook denies a command when every simple command in it is a timer or noise, and at least one timer exists.
| Part of the command | Counts as |
|---|---|
Timer |
|
Timer loop |
A |
Noise |
|
These commands pass:
-
A loop that checks a job:
until <check>; do sleep 30; done, orfor i in $(seq 1 46); do grep -q <done> f && break; sleep 5; done. -
The four-minute chunk:
e=$SECONDS+240; until <check> || [ $SECONDS -ge $e ]; do sleep 20; done. -
A
sleepbefore real work:sleep 2; osascript …. -
Any command the hook cannot parse as timer-only, for example
bash -c 'sleep 5'orsleep 5 | cat.
The denial text names the replacement. If a child agent or a background command of yours runs, end the turn:
its completion wakes you. Otherwise wait on the job’s process id, done marker or log line, with a deadline.
FT_TIMER_WAIT=0 turns the denial off.
The wait card
Every denial of checkout-guard.py for a wait ends with the same card. The card is also in
rules/agents/common.md, and a test pins that the two texts are identical. A brief for a receiver that waits on
CI, a gate or a host carries the filled-in form as a Wait: line.
Wait forms (pick the first that fits; checkout-guard allows each):
- a job you start: start THE JOB with run_in_background: true; its completion wakes you; no wait command at all.
- CI of a PR: `gh pr checks <n> --watch --interval 60` with run_in_background: true.
- a log line or done marker of a job whose pid you hold: `e=$((SECONDS+3600)); until grep -qE '<done>|<fail>' "$log" || [ -f "$done" ] || ! kill -0 "$pid" 2>/dev/null || [ $SECONDS -ge $e ]; do sleep 30; done`
- a pid you hold: `e=$((SECONDS+3600)); while kill -0 "$pid" 2>/dev/null && [ $SECONDS -lt $e ]; do sleep 30; done`
Over ~4 min: run_in_background: true and end the turn. Then say which condition ended it.
The three command forms also count as waits for ownership-check.py and janitor.py. See What counts as a wait.
Foreground waits of 1-hour-cache agents
checkout-guard.py also denies a repeated foreground wait loop to a sub-agent on the 1-hour prompt cache. Each chunk of a foreground poll is a wake turn that re-reads the whole context. One background wait costs one wake.
Agents. The roster is FG_WAIT_AGENTS: ft-java-coding-agent, ft-angular-coding-agent, ft-python-coding-agent, ft-coding-agent, ft-ops, bugfix-agent, ft-fix-host, ft-developer, refactor-agent, ft-sdd and ft-ui-ux-design. The main loop and the agents on the 5-minute cache (general-purpose and the reviewers) are never affected. They keep their 4-minute foreground chunks.
What counts. A foreground bounded wait loop is an until or while loop with a sleep command in the body (the do may be on its own line) and a condition that only looks (grep -q, [ -f x ], kill -0, true, a $SECONDS test), or a for loop with a sleep command in its own body whose other commands check nothing, or are all checks and one of them leaves with && break. The hook reads loops from the parsed command, so a loop inside a heredoc, a quoted string or a comment never counts, and while read h; do ssh $h uptime; sleep 1; done is real work. A loop that does real work, with or without a throttling sleep or a break that does not guard a check, never counts. A sleep that is only an argument is not a sleep command. The hook reads the deadline from SECONDS+<n> or a literal product such as SECONDS+2*60, or from a literal word list, $(seq A [S] B) or {A..B[..S]} times the sleeps of the body. Anything else has no readable deadline, and so has a command that also holds an until or while loop without a $SECONDS bound. A call with run_in_background: true never counts for this foreground rule. The background rule in Background waits with no deadline applies to it.
The sleep-check chain. A foreground sleep N; <checks> also counts as a wait of N seconds. It counts only when all of these hold:
-
N is a literal number of 30 or more. A
sleepwith several arguments or an unreadable argument does not count. -
The chain has no loop, no command substitution and no heredoc.
-
Every other command is a read-only check (
grep,tail,cat,ls,wcand similar) or a variable assignment. A leadingcd <dir>is allowed. Agitcommand counts as a check only forstatus,log,diff,show,rev-parseandls-remote. Aghcommand counts only forpr checks,pr view,pr list,run viewandrun list. -
No command can write or act elsewhere. These never count:
ssh,docker,kubectl,oc,systemctl,wgetandawk,sed -i,curlwith a method, body or output flag,find -deleteor-exec,sort -o,killwith anything but-0, and any redirect other than to/dev/null.
For this chain, the 15-minute window and the duplicate rule in the next table apply from 30 seconds, not from 60. The chain applies to the agents of the roster only. Sleeps alone are a timer wait (see Timer waits).
When the hook denies. The hook keeps the time and the command of the last allowed wait of each agent_id, and the list of its allowed waits in the window, at most 32. It denies the call in any of the three cases.
| Case | Condition |
|---|---|
(a) |
The loop has a deadline of 60 seconds or more (or the hook cannot read the deadline), and the same agent ran an allowed foreground wait within |
(b) |
The agent sent the identical wait command within |
(c) |
The agent’s foreground waits in the last |
The first wait of an agent passes. A loop with a deadline under 60 seconds passes only while the agent’s waits in the window stay under 60 seconds in total, and it is not a duplicate of the previous command. A sleep-check chain of 30 seconds or more falls under case (a).
Denial text. The text starts with checkout-guard: and gives one reason: the identical foreground wait was sent twice within seconds., a second foreground wait of 60 s or more within <n> s of your last one. (30 s for a sleep-check chain), or a second foreground wait within <n> s of your last one: your foreground waits in the last <window> s add up to <total> s, 60 s or more. The text then tells the agent to start the wait with run_in_background: true and to end the turn, because the completion wakes it. It ends with the wait card.
State. The hook writes fg-wait.json in FT_LANE_STATE_DIR (default ~/.local/state/ft-ai-toolkit), mode 0600. The file holds the time and the command of the last allowed wait of each agent, and a list of its allowed waits as a time and a number of seconds, at most 32. A state entry written by an older version counts as one wait of 0 seconds. The hook drops entries older than one day.
Failure mode. The guard is fail-open. A payload without agent_id or agent_type, an unreadable state file or a failed write allows the call. A corrupt state file is replaced.
Background waits with no deadline
checkout-guard.py denies a command with run_in_background: true that holds a wait loop with no deadline. The rule applies to the main loop and to every agent. Its harm does not depend on the prompt cache: a loop that never ends keeps running after its lane ends, and the sandbox cannot kill it. On 2026-11-13, an until loop polled every 20 seconds for a line that never came. It ran for hours after its lane ended.
A loop is bounded when its own condition or body compares $SECONDS or date +%s with a value, quoted or not, such as [ $SECONDS -ge $e ], SECONDS < e or [ "$(date +%s)" -lt "$end" ]. A test in the body counts only when it leaves the loop (&& break, exit). An echo $SECONDS, an ls -lt, a date +%s > file, a file count compared with -ge, or an e= assignment that no test in the loop reads is not a deadline. A for loop is also bounded when it has a readable round count. $EPOCHSECONDS is no clock: the harness’s zsh has no zsh/datetime loaded, so it is empty and a test on it never comes true. Any other background wait loop is denied.
The denial text starts with checkout-guard: a run_in_background wait loop with no deadline. It gives this form and ends with the wait card:
e=$((SECONDS+N)); until <done> || [ $SECONDS -ge $e ]; do sleep 30; done
N is the longest the job may take. FT_BG_WAIT_GUARD=0 turns this denial off. An error in the check allows the command.
The same until or while loop sent in the foreground is denied too, to the main loop and to every agent. A for loop is not denied in the foreground, because its rounds end it, except a C-style for ;; with no condition, which never ends. At its Bash timeout the harness moves a foreground command to the background instead of ending it, so a loop whose condition never comes true runs on there. On 2026-11-29, a verifier’s foreground until grep waited for a line that its finished job never printed. The harness moved it to the background, and it ran for 3 days. In the 13 hours from 2026-12-01 19:00 UTC, 25 such loops ran and 10 of them were moved. The denial text starts with checkout-guard: a foreground wait loop with no deadline. An agent on the 1-hour prompt cache gets its own loop bounded for the background. Any other caller gets its own loop bounded inside its own call timeout and kept in the foreground: e=$SECONDS+T, where T is the call’s timeout minus 10 seconds (110 for the default 120 s), so a 4-minute chunk stays a 4-minute chunk. A loop that sits inside a for, an if or a { }, or whose work after it carries a # comment, is never rewritten, and every offered form must parse in bash and zsh; otherwise the denial offers the wait card’s form. A loop whose body counts rounds (n=$n+1) reads as work, not as a wait, and passes. A test that only ends the loop when its producer is gone (! kill -0 $p) is no deadline. FT_FG_DEADLINE_GUARD=0 turns the foreground half off.
Every denial that tells you to send a form with run_in_background: true says on its second line what the turn after the launch is: no call at all, no echo, no sleep and no read of the output, until the completion notice wakes you. On 2026-12-01 and 2026-12-02, 22 of 53 such launches were followed at once by one of those calls, and another rule denied it.
FT_FG_WAIT_GUARD=0 turns the guard off. It also turns off the sleep-check chain rule.
Background commands that read stdin with no input
checkout-guard.py denies a command with run_in_background: true that runs a stdin reader with no input. The rule applies to the main loop and to every agent. The harness leaves the stdin of a background command open and never writes to it. The reader waits for data that never comes, and the call never ends. On 2026-12-01, a stray cat >/dev/null in a background command held a lane for 1 h 57 min.
The readers are cat, head, tail, wc, sort, uniq, tee, read, mapfile, readarray and python that reads - or has no script. cat, head, tail, wc, sort and uniq are readers only when they have no file operand, or when the operand is -. read, mapfile and readarray are readers only without -u, which reads another file descriptor, and read also only without -t, which times out. python with -c, -m, --version or any --help option is not a reader. A simple $… counts as one word, so head -n $N+1 file has its file operand.
A reader is fed in these cases:
-
A pipe goes into it.
-
A
<redirect, a heredoc or a herestring is on it. -
The same redirect is on the loop or the group that holds it.
-
An earlier
exec <redirects stdin.
The denial closes the stdin of the whole command, never of one reader: a reader that a pipe feeds would read nothing. For a one-line command the text starts with checkout-guard: send this instead, with run_in_background: true, then end your turn: and gives the command in this form:
{ <command>; } </dev/null
If the command has more than one line, a comment, a backtick, a trailing & or a long text, the denial tells the agent to wrap the whole command in a line {, the command, and a line } </dev/null, or to name the file the reader should read. A form is offered only when the hook allows it and bash -n and zsh -n parse it. When neither form passes, the hook allows the command.
FT_BG_STDIN_GUARD=0 turns this denial off. An error in the check allows the command.
Known misses. The check does not see these cases:
-
A reader inside
$(…), backticks,bash -coreval. -
A command that the hook’s tokenizer splits where the shell does not. The check allows such a command: a pipe into a
{ }or( )group, an output process substitution>(…), an escaped operator such as-exec … \;, a heredoc delimiter that is not a plain word, a blank or comment line after a trailing|, a function definition, acase, or a$…with parentheses inside. Quoted strings and comments do not count. -
An operand that expands to nothing, such as
cat $FwithFempty. -
A reader behind a wrapper other than an assignment,
env,nohup,time,command,execor!, such asnice,sudo,stdbufor/usr/bin/env. -
A reader that the list does not name, such as
grep,sed,awk,jq,xargs,sshwithout-n, orbashorshwith no script.python3 -i script.pyis also missed; a barepython3 -iis denied. -
A foreground call. The Bash timeout bounds it.
Known residual. A background wait loop with no deadline that also runs a starved reader is denied twice: first for the loop, then for the reader in the bounded form.
No-op waits and sleep-check chains
Two wait shapes added to checkout-guard.py cost a turn and wait for nothing. Between 2026-11-08 and 2026-11-11, agents sent about 120 echo waiting turns. On 2026-11-10, one agent polled one background job with 13 calls of sleep 58; grep …. Each call re-read the whole context.
Shape 1: a command that only prints a waiting word. The hook denies it for every agent and for the main loop. The command must be exactly one echo whose text is a waiting word: waiting, wait, idle, pending or standby. The word may be quoted, may continue with words joined by -, _ or a space, may end with ., ! or :, and is not case-sensitive. These commands are denied:
echo waiting
echo "waiting on bfd7e07um"
echo waiting-for-green
echo 'Waiting for CI...'
The denial text starts with checkout-guard: a command that only prints a waiting word. It says that waiting needs no command. If a child agent or a background command of yours runs, end the turn with no tool call, and its completion wakes you. The text ends with the wait card.
Shape 2: a sleep-check chain. For the agents of the roster, the hook counts a foreground sleep N; <read-only checks> as a foreground wait. The previous section describes the conditions and the rules that follow.
| Command | Result |
|---|---|
|
Counts as a foreground wait of 58 seconds. The second one within 900 seconds is denied. |
|
Counts as a foreground wait of 30 seconds. |
What still passes.
-
echo okandecho done. Verifier and ops agents use them as liveness probes. -
Any
echothat holds a$, a backtick, a redirect, a pipe or a second command, for exampleecho waiting > formake; echo wait. -
sleep 2; osascript …and anysleepbefore real work. A command that is not a read-only check is work. -
A
sleepof less than 30 seconds in a chain. -
Every command with
run_in_background: true. -
The main loop and the agents on the 5-minute cache, for shape 2.
The hook is fail-open for both shapes. A command that the hook cannot parse, or a sleep argument that is not a literal number, passes.
| Variable | Meaning |
|---|---|
|
Turns off both shapes: the |
|
Turns off the foreground-wait guard, and with it the chain rule. The |
Replayed against the logged calls of 2026-11-08 to 2026-11-11, shape 1 newly denies 99 calls, and all 99 were polls with nothing to read. Shape 2 counts 51 unique chains, and all 51 were polls of background output.
The leaf bound
checkout-guard.py also bounds a coding leaf. A coding leaf is a sub-agent whose type ends with -coding-agent. The main loop and every other agent never reach this check. A coding leaf re-reads its whole context on every turn. Leaves reached 417K to 542K tokens of context while they read test consoles. The canon is rules/agents/common.md, section "Context bound for coding leaves". The hook is an economy guard: it fails open, it runs in Claude Code only, and it does not parse bash -c or eval.
The hook has three parts.
-
Output guard. The hook denies a build or test runner whose output is unbounded. The runners are, for example,
mvn,gradle,pytest,npm test,go testand a test script. The denial applies in the foreground and in the background. The output is bounded when the runner writes its stdout to a file, or when the last command of the pipeline istail,wcortest_verdict.py. The hook also denies acatof a.logfile, a.outputfile or a/tasks/path. The denial text gives the one-command form: redirect to a log, printrcandtail -n 40, and on a failuregrep -m 3 -A 30of the failure lines.FT_LEAF_OUTPUT=0turns this part off. -
Context note. On the first
Bashcall of an agent pastFT_LEAF_CTX(200000 tokens), the hook adds a note once. The note says to hand back at the next settled point only if more than about B tool calls of work remain. If fewer remain, the leaf finishes the unit. B falls as the context grows. The note prints B for 200K, 250K, 300K and 400K.FT_LEAF_NOTE=0turns this part off. The note ends with the hard line when the hard line is on. -
Hard line. Past
FT_LEAF_HARD_CTX(400000 tokens), the hook denies every new runner, bounded or not. The denial tells the leaf to write the## HANDOFFand returnStatus: HANDBACK. Other commands still run.FT_LEAF_HARD_CTX=0turns this part off.
The hook has no size trigger. The dispatcher judges the size of a unit.
| Variable | Default | Effect |
|---|---|---|
|
|
|
|
|
|
|
the state directory |
A path for |
|
|
The line for the context note. |
|
|
The hard line. |
|
|
An estimate of the cost of a fresh continuation, in input-equivalent tokens. B is computed from it with the saving model of |
The note is sent once for each agent id. The hook records the agent in leaf-note.json before it prints the note. If the file cannot be written, the hook prints no note. Two leaves that write the file at the same time may lose one entry. The effect is that one note is sent again.
A hand-back is not a failure. price-gate.py does not flip the arm of a continuation, which has the description <unit> continue (fresh) or a line handback: fresh in the first 600 characters of the brief. The rules of the dispatcher are in Dispatch Economy Reference, Leaf hand-back.
The ops nudge
checkout-guard.py also notes a main loop that runs many git, gh, ssh or scp calls with a large context.
Each call re-reads the whole context. The note applies to the main loop only (a payload without agent_id). It
never denies a command.
A command counts when a simple command starts with git, gh, ssh or scp, after a cd <dir> && prefix and
VAR=value prefixes. Only a call made while the last turn holds more than 200000 tokens of context counts. The
third counted call within 10 minutes adds this note as additionalContext:
checkout-guard: main loop at ~300K context; this is git/gh/ssh call 3 in 10 min, and each one re-reads the whole context. Hand the batch to ONE ft-ops agent with the list and what done means (main-rules: "Main loop over ~200K"); keep only approvals and rulings.
The number in the text is the real context size and call count. A denied command gets no note.
| Variable | Default | Meaning |
|---|---|---|
|
on |
|
|
200000 |
Tokens of context above which a call counts. |
|
1800 |
Seconds between two notes. |
The state file is main-ops-nudge.json in the state directory. The hook removes sessions untouched for 7 days.
A failed write or an unreadable transcript gives silence.
The lane nudge
The main loop ends a turn with a status line such as lanes 14/25: running lanes, then the target. This is
the literal form that main-rules.md asks for. The hook also reads the forms lanes ~12/25 and the Russian
forms that the transcripts show. lane-nudge.py runs on Stop. It takes the status line from the turn’s final text in the Stop payload (last_assistant_message); without it, it re-reads the transcript for up to 2 seconds until the turn’s final message has landed, and stays silent if it has not. When the transcript counts fewer running
background agents than the target, it blocks the stop once and asks for the next backlog items. The reason is
fixed text and holds only numbers:
lane-nudge: your last status line says lanes 5/25 and the transcript counts 3 running background agents;
their own sub-agents are not counted. Start the next backlog items now. If you cannot, say so in one line:
"backlog empty", or "backlog waits on <event or owner decision>". Details: python3 ~/.claude/hooks/lane-status.py
A line without a target, such as lanes 38 — backlog: …, is a status too. The hook then takes the target from
the last lanes R/T line that this session wrote (target in lane-nudge.json), else from FT_MAX_LANES. The
session’s own line wins, because it carries the number that you asked for. The reason names the source. With
neither, there is no refill decision. The next lanes R/T line replaces the stored target. The hook removes a session’s entry after 7 days without a change.
hold_target in the same file is never used as a target, so a wrong value that an older version stored there has no effect.
The hook also compares the claim with the count. When the final text claims more than 5 lanes above the count, and more than 50% above it, the hook blocks the stop, at most once per hour. The text gives both numbers and asks the session to recount, or to list what else it counts as lanes (trains, CI runs). A hold does not silence this check.
The hook counts every running background agent of the main loop, helpers such as Explore and ft-ops
included. It reads the count from the transcript: a launch starts an agent, and a finish notice, a hand-back
or a stop ends it. A SendMessage to an agent starts it again, and a finish notice or a hand-back stamped
before that message ends nothing. The sub-agents of these agents are not counted. An agent silent for more
than 3 hours is presumed dead and is not counted.
The hook reads a finish notice or a hand-back only at the start of a message, so quoted text cannot end an agent:
-
A
<task-notification>counts only when the text starts with it, after blank space. The hook takes the first notification of the text and ignores any later one. -
The hook reads the task id and the status only from the head of the notification, before its first
<summary>. The head must start with<task-id>. A title or a report that quotes these tags cannot end an agent. A notification with no id and status before its<summary>, or with another tag before the id, ends nothing. -
A
[Subagent hand-back]text counts only when its first line is an<agent-message from="…">tag. The hook accepts the prefixAnother Claude session sent a message:before the tag. It takes the first agent name only. -
The marker
[Subagent hand-back]counts only right after the head. The hook allows up to two harness warning lines between them. A line counts only when it starts with one of the two live prefixes,Note: The server-side auto mode classifierorSECURITY WARNING: auto mode blocked, and is at most 500 characters long. Other text between them means no hand-back. -
The stop text
Successfully stopped task: <id>counts only when it starts the message and the tool result carries atask_id. -
A line of origin
humannever ends an agent, and neither does a line that holds a tool result. -
A queued line (
queue-operationwithenqueue) counts only when its text starts with the notification tag. A queued owner prompt that quotes a notification does not end an agent.
A missed finish keeps an agent counted. That suppresses a nudge for up to 3 hours and never causes one.
For the refill, the hook compares the count of the transcript with the target, not with the running number in the
status line. With lanes 8/12 and a count of 8, the hook fires, unless one of the cases below applies. The refill
nudge stays silent in these cases. A case that also silences the claim check is listed again below:
-
It is switched off (
FT_LANE_NUDGE=0, or the file~/.local/state/ft-ai-toolkit/lane-nudge-off). -
The caller is a sub-agent, or the stop is already the result of a hook block (
stop_hook_active). -
The last status line is older than your newest message, or the target is 0 or unknown.
-
The main loop has said why the work waits. A message that says the backlog is empty, or that the backlog waits on an event or on an owner decision, is a hold. The hook matches phrases such as
backlog emptyandbacklog waits on, and their Russian equivalents. A negation cancels the match:the backlog is not empty,backlog isn’t done yetandnot blockedare not holds. So are a work item (backlog item 3 done) and a statement about running agents (the rest of the agents wait for CI). The state filelane-nudge.jsonrecords the hold. A hold ends when the target changes, when you write a new message, or after 2 hours. -
The previous nudge of this session is less than 1 hour old.
-
The transcript walk did not finish in its 8 seconds.
-
The final text is neither in the payload nor in the transcript within 2 seconds.
-
Any error occurs (fail open, exit 0).
The claim check compares the claim of the final text with the count. These cases silence it. A hold does not:
-
It is switched off (
FT_LANE_NUDGE=0, or the filelane-nudge-off). -
The caller is a sub-agent, or
stop_hook_activeis set. -
The final text has no status line, or its only
lanes <number>line is one that the hook cannot read. An older status line is never judged in its place. -
The final text has only a
lanes R/Tpair inside prose, such asMerged. Lanes 64/73 wait for CI.Such a pair names lanes and claims no count. -
The final text is neither in the payload nor in the transcript within 2 seconds.
-
The hook is killed at its 15 second timeout. The saved walk then stays on disk, so the next stop goes on from it.
-
The claim is 5 lanes or fewer.
-
The claim is at most 5 lanes above the count, or at most 50% above it. A claim below the count is never judged.
-
A claim check blocked less than
FT_LANE_NUDGE_GAP_Sago. -
The transcript walk did not finish in its 8 seconds.
-
Any error occurs.
-
The state file cannot be written.
The count is fast only with a saved walk. The first stop on a large transcript reads at most 8 seconds of it and
saves the offset it reached. That stop decides nothing that needs the count. The next stops go on from the saved
offset until the whole transcript is read. After a walk that took more than 4 seconds, the health notice also waits
for the next stop. The offset is in lane-health/<session id>.json, also with
FT_LANE_HEALTH=0. When that file cannot be written, a transcript that takes more than 8 seconds is never counted.
The saved walk assumes that a transcript is only appended to. A transcript rewritten in place with the same inode
and at least the same size is not walked again from its start.
With FT_LANE_HEALTH=0, the cached health verdicts in that file are ignored, so no lane is left uncounted by an old
verdict. A stored time more than one day ahead of the clock counts as no time, so it cannot silence the hook.
Two terms differ in meaning: the lane target and the lane cap. The target is the number in the status
line, and the nudge counts all background agents against it. The cap is FT_MAX_LANES in price-gate.py
with a default of 6, and it counts only top-level orchestrators. The cap can therefore deny the launch that
the nudge asks for. The denial says to start the lane when a lane hands back, or to resume a paused one. Set
FT_MAX_LANES to at least the number of orchestrators that you want to run at once. See
Dispatch Economy, The lane cap.
| Variable | Default | Meaning |
|---|---|---|
|
on |
|
|
3600 |
Seconds between two nudges of one session, and between two claim checks that block. |
|
none here |
The target for a |
|
7200 |
Seconds that a hold lasts. |
|
10800 |
Seconds of silence after which an agent is not counted. |
|
|
Directory of |
The hook reads these variables from its own environment. The installer sets none of them and adds no key to
settings.json env, because a new key there reaches the shell of every agent. The hook writes its state
before it prints the block, so a failed write gives silence and never an unlimited block.
Known limits:
-
After a nudge, a shortfall can go unnudged for up to 59 minutes.
-
A hold can silence the hook for up to 2 hours when the main loop launches lanes and then falls short again.
-
A dead agent that the hook still counts suppresses a nudge for up to 3 hours. It never causes one.
-
lane-nudge.pyandmain-compact.pyboth run onStop, side by side. When the nudge blocks the stop, it writes the markerlane-nudge-block.json(session id and time) before it prints the block.main-compact.pytypes nothing for the same session within 60 seconds of that marker. The nudge writes the marker after its transcript walk, which can take more than a second. So the detached sender ofmain-compact.pyreads the marker again after a 2-second wait, throughmain-compact.py --clear <session id>, and sends nothing when the marker is present or the check fails. A marker that appears after that second look still lets the/compactland in the continued turn. No live Terminal.app run drove this case, or a permission dialog that an Enter answers. -
The status line is the last line of the message that starts with
lanes R/Torlanes Nand then ends or goes on after a dash,·,(,[,.,;,:, a comma, a` or the word `running`. A comma followed by a word that holds a digit starts a list (`lanes 64, 73`, `lanes 64, K31`). A `counts only when a spaced em dash follows later on the line. Markup may sit around the number and the word (lanes 38,lanes: 38). A line that starts withlanes <number>but goes on in another way is unread. It hides older status lines only when its message has no readable one, so the hook never quotes an older one as the last. When no line of the message is such a status line, the hook takes the lastlanes R/Tpair that starts a line or a sentence, and never stores its target. A pair inside a bracket, a list item or a comma list is a set of lane names, such asbatch D2 (lanes 64/73), and not a status. A line that starts withлейныorлейновis read like alanesline. In prose, the Russian forms need a target. R and T are numbers of at most 9 digits each. A longer number is not a status. A date shape such aslane 11/02 mergedis not a status. A day below its month, such aslane 10/31 merged, reads as a status. -
Two sessions that stop in the same instant can overwrite each other’s entry in
lane-nudge.json. The cost is one repeated or one missed block. This is accepted. -
A queued owner prompt that starts with a pasted notification ends the agent, because a queued line has no origin to tell the two apart.
-
A hold phrase in the past tense still holds. Example:
the backlog was empty yesterday, now 40 new. The cost is one silence of 2 hours.
The health notice
lane-nudge.py has a second branch beside the nudge. It finds lanes that ended, froze or never reported. It runs
with or without a lanes R/T status line, and a hold does not silence it. It runs at most once every
FT_LANE_HEALTH_GAP_S seconds (default 300) for each session. A pass stops after 4 seconds, and the agents that
it did not reach are not judged.
The pass looks only at top-level background agents that the nudge counts as running. A harness flag finished
means that the agent is stopped right now. It does not mean that the agent ended. Each turn end sets the flag,
and a resume clears it. An agent counts as stopped when finished is true and its transcript was not written
later than 60 seconds after the meta file. Any other agent is run. The pass classifies a stopped agent in this
order:
| State | Meaning | Counted as running |
|---|---|---|
|
A hand-back was delivered, and its report never reached this session. |
No |
|
A job of the agent still has a writer, or a child of the agent is alive. Nothing to do. |
Yes |
|
Open jobs exist, none has a writer, and no child is alive. Its wait is gone and nothing will wake it. |
Yes |
|
Only open monitors exist, and the agent was silent for 3600 seconds or more ( |
Yes |
|
Nothing wakes the agent, and it gave no successful hand-back. |
No |
A child is alive when the agent started it, the transcript holds no completion notice for it, and the child is
run or wait. A child that is deeper than one level counts as alive. A job that the harness moved to the
background, a child that the agent resumed by SendMessage, and a child that a queued message will resume all hold
the agent in wait, and a completion notice stamped before that message does not end the child, even when the
transcript writes it later. Only the sender’s own children reopen, and both wordings of a moved job open one: the
harness moves a command either after its timeout or after a long run. The LEFT event is a record of a top-level
lane that left an unnamed live item or had a wait ended. It is announced once, and declared items never announce.
The notice has one line for each new event. It shows at most 10 lines. The rest is a count:
+N more, listed by the command below.
lane-nudge: 2 lane(s) need you:
UNSEEN a90953db "F-COR-13 Stage 3 implement" handed back at 13:46Z but the report never reached you: python3 ~/.claude/hooks/lane-status.py --session sess-1 --report a90953db11112222
ENDED acd9c8f6 "Run options resume" ended without a hand-back at 13:46Z: relaunch it from its journal, or close its backlog item
Details: python3 ~/.claude/hooks/lane-status.py --session sess-1 --project /Users/x/.claude/projects/-Users-x-app
The other lines have this form, with a fixed text, the state, the id and the cleaned description:
-
FROZEN:<id8> "<description>" waits on <items>, whose process is gone (silent <time>): SendMessage <id> to re-arm it, or TaskStop <id> -
FROZEN?:<id8> "<description>" waits only on <items> (silent <time>): SendMessage <id> to check it, or TaskStop <id> -
LEFT:<id8> "<description>" left <n> unnamed live item(s) (<items>) and ended <n> wait(s) (<ids>): end what is yours or take it over (python3 ~/.claude/hooks/lane-status.py)
The Details: command names the session and the transcript directory, so it reads the right session. The class
column is 7 characters wide, the length of FROZEN?. An id that is not a safe token appears as #<sha1[:8]> and is
never part of a suggested command. An unsafe session id or directory shows as the placeholder <session-id> or
<project>, and so does the session in a --report command (--session <session-id> --report <agent id>). When the health
notice and the lane notice fire together, the health notice follows the lane reason.
| Variable | Default | Meaning |
|---|---|---|
|
on |
|
|
300 |
Seconds between two health passes of one session. |
|
900 |
Seconds of silence after which an unfinished agent is judged. A value below 60 counts as 60. |
|
3600 |
Seconds of silence after which an agent with only monitors is |
One persistent set of keys for each session decides what is announced once. The key is
<agent id>:<class>:<event time>, and the set records when each key was announced. The pass judges only the agents
that the nudge counts as running. It announces every key of such a lane that is not in the set yet, when the pass
first judges the lane, however late that is. At most 10 lines print. The keys of the lines that do not print are
also marked as announced, and the notice says +N more. A resumed agent that ends again, or a lane that goes from
FROZEN to wait and back to FROZEN, gets a new event time and so a new key. It is announced again. The hook
removes keys older than 7 days and keeps at most the 500 newest. If the state file is lost, every running lane that is
dead now is announced once more. An old state file with fields of an earlier version loads without error, and the
next save drops those fields.
If lsof is absent or times out, the writers are unknown. Then a lane with an open job is wait and never
FROZEN, and a class that was cached before keeps its class and its time. The pass sets the flag
writers_unknown in its state. lane-nudge.py stays silent on such an outage by design, and
lane-status.py prints it (see lane-status.py).
A transcript over 8 MB is read in parts. At first sight the pass reads only the last 8 MB, and the lane reads as
wait, because a job or a child that started before the tail is invisible. Each later pass scans forward from
the start, at most 8 MB per pass, until the scan is complete. Then the lane is judged like a full read. A single
line over 8 MB stops the scan, and the lane stays wait. The first agent of the rotation and its direct children
always finish a first-sight scan, with the 8 MB tail at most, whatever the clock. The 4-second limit applies
between agents. An agent that the pass defers heads the next pass. The state of a child has no cache between calls, so a child
that was read from its tail stays wait.
The pass keeps its state in lane-health/<session id>.json in the state directory, with mode 0600: the
incremental transcript walk, the announced keys and the cached verdicts. A failed write gives silence. The nudge
counts neither UNSEEN nor ENDED agents as running.
Process ownership
ownership-check.py answers one question: what did a sub-agent leave running? It reads the agent’s own
transcript and lists the things that the agent started and did not end. It runs on two events, and it routes by the
event name. It never blocks the work itself. It fails open: any error allows the call and prints nothing, because a
hand-back is the only way that an agent delivers its result. FT_OWNERSHIP=0 turns the whole hook off.
The hook reads structure, not text. A job is a Bash call with run_in_background: true that has a matching tool
result. Quoted text inside a tool result never creates an item or ends one. Only the agent’s own lines count.
| Kind | What it is | Live while |
|---|---|---|
|
A background command of the agent. |
A process writes to its output file. |
|
A |
The agent has not ended it. The hook treats an open monitor as live. |
|
A |
The directory exists. A relative path counts only after a |
|
An |
The process in its |
|
A command with |
Its process runs: the pid that its launch printed ( |
|
A child agent that the agent launched. |
The child is alive (see The health notice). |
The hand-back check
The event is PreToolUse with the matcher SubagentHandback. A call without an agent_id is allowed. The hook
lists the live items of the agent. An item is declared when the report names it in a live: line. If at least
one live item is undeclared, and the hook did not yet deny this set for this agent, the hook denies:
ownership-check: your hand-back leaves 3 live thing(s) of yours unnamed:
job bj1 (pid 4312) -> end it: kill 4312 | or name it
browser sel-cases -> agent-browser --session sel-cases close | or name it
worktree /abs/path -> git -C /abs/repo worktree remove /abs/path | or name it
End each one, or name it in your report as a line "live: <kind> <id> · <what> · <next step for whoever takes over>"
(delegation-contract.md §10). End a process only by the pid shown, never by its name: other lanes run the same scripts. To wait for a pid, in the background: `e=$((SECONDS+3600)); while kill -0 "$pid" 2>/dev/null && [ $SECONDS -lt $e ]; do sleep 30; done`. Then hand back again.
The other line forms are detached <program> (pid <pid>: <command>) → kill <pid> | or name it,
agent <id8> (alive child) → TaskStop <id> | or name it, and <kind> <id> (inherited) → end it, or name it.
A detached line never suggests a name pattern, because a lane cannot tell its own process from another lane’s by
name: only a $! pid that still carries the program name gets a kill, a pid found by its start time under this
call’s harness shell, or with none above it, gets → kill only a pid you know is yours, and an item with no known
pid asks for & echo $! next time. The health
notice reads no process table, so it lists a detached item as before.
The browser session default (no --session, or --session default) is one name that every lane shares, so it never
causes a deny, a close command or a LEFT notice: when other items cause a deny, it appears as the note line
browser default (shared by every lane) → not yours alone: leave it open, use --session <name> next time.
An id that is not a safe token appears as #<sha1[:8]>, and its line has no suggested command. The second
hand-back with the same set passes. The deny state is one file for each agent,
ownership/<session id>/denied-<agent id>.json. If the hook cannot write that file, it allows the hand-back.
The reviewer floor
The same hand-back check refuses the hand-back of an ft-fix-host that ends without an independent reviewer.
The floor is met when the agent’s own transcript holds at least one verifier and one ft-test-adversary
dispatch (an Agent or Task tool use with that subagent_type, or its -next variant, whose result is there
and is not an error; a background launch counts). A dispatch made by a child, such as the bugfix-agent, does not
count, and a reviewer name inside a prompt or a result does not either. Without both dispatches, the report must
carry one reviewers: line at a line start in its first or its last 4000 characters (right after the TIER_AB
line is simplest; a line cut by the start of the last window does not count), in the grammar of
agents/ft-fix-host.md item 8:
-
reviewers: none - <OUTCOME>: <reason>, for a run that ships no code: the outcomes that skip to Stage 5 in/ft-fix, plus the stops.PARTIALLY_CONFIRMED,EXTERNAL_GAPandINTENTIONAL_DIVERGENCEship a fix, a workaround or a diff with a registry entry, so they are not outcomes here. The first 600 characters of the report must not say "fixed", "ready", "done" or "committed" in any case, or name a commit: a hash of 7 or more hex digits after the wordcommitand a space, a colon or a backtick. So "not done" and "already fixed" also count as claims. The scan stops at 600 characters, so aChanges:block further down is not read. -
reviewers: self-check - <verifier|adversary|both> unavailable, with the skill’s prominent self-check line. Each role that the line names needs at least one attempted dispatch (an error result counts), and the role that it does not name must have run. A line that names the verifier needs "self-check only — no independent review"; one that names only the adversary may carry "no independent test-adequacy review" instead. The hook reads that line anywhere in the message, so a pasted deny text, which quotes it, also satisfies it when the dispatch checks hold. This is a declared residual.
A dash can be -, an en dash or an em dash, and the line can be a bullet or bold. The floor checks a declared
escape, not the quality of a review. It refuses at most 3 times (keys floor#1 to floor#3 in the deny state);
a refusal logs ` floor=1` at the end of its log line, and a hand-back that passes under the floor logs ` floor=open`.
A hand-back under the floor whose deny state cannot be written passes and logs ` floor=nostate`.
When live items and the floor both fire, the agent gets one deny with both texts. A transcript with no
lines of the agent’s own, an unwritable deny state, or an error inside the floor allows. Other agent types are never
checked, except ft-developer (below). FT_REVIEWER_FLOOR=0 turns the floor off.
The ft-developer floor
The same check refuses an ft-developer hand-back that claims delivery without a review of its own. The grammar is
the Hard-rules item "Reviewer floor" of agents/ft-developer.md; this section holds the mechanics.
-
The claim.
READY,DELIVEREDorDONE, in upper case and as a whole word, in the first 3 non-blank lines of the report (TIER_ABlines skipped). A word with "not", "no" or "nothing is" up to 40 characters before it, cut at the last period, is no claim. A report whose first line starts with a stop, in upper case and as a whole word (after markdown and aSTATUS:orState:key;Split viewis no stop) claims nothing and is never refused. A stop phrase,boundary C reached,not yet completeorStage 6 DONE, silences only the claim words from it on, on its line and the later ones:DONE - X shipped (Stage 9 DONE)still claims, and a first line that opens withboundary C reachedclaims nothing. -
The launch head. The exemptions and the journal are read only from the launcher’s lines of the first prompt: the text before
Original request:. A slice brief carries no such marker, so with none a lineMode: sliceis the head by itself when it is the first non-blank line or follows only the brief openers, in this order and each optional: one lineContext: … budget <k>KB(the opening line of every brief,delegation-contract.mdsection 1, which may go on after the budget) and oneBounds:line (the brief templates write it as their second line). The parent writes those lines and no ticket text can precede them; a second opener, another order or any other line beforeMode: slicemeans no head. SoMode: slicemay come afterContext:only, afterBounds:only, or afterContext:thenBounds:.Mode: sliceis the whole word:Mode: slice-ishis another mode. Any other prompt without the marker has no head, so it gets no exemption and no journal read. Exempt: a run whose parent is an ft-developer, checked whatever the prompt says: its own.meta.jsoncarries aparentAgentIdthat is a plain token of letters and digits (the id price-gate_launch_parentreads), and the parent’sagent-<id>.meta.jsonbeside it hasagentTypeft-developerorft-developer-next. Both metas are read as regular files of at most 1 MB. A parent of any other type (ft-fix-host,bugfix-agent,general-purpose), an id with a dot or a slash, or a meta that is missing, corrupt, a directory or nested too deep leaves only the head rule. Also exempt: aMode: sliceline, aGroup:line with a name other thanmerge, and a head that startsResumed from a splitwith noGroup:line (a split seed; the/ft-dev grouplaunch that carries aGroup:line is not this). The parent of those runs reviews the merged result. -
Form A. A
verifierorft-test-adversarydispatch (or its-nextvariant) or acode-reviewSkill call of the agent’s own, whose result is there and is not an error. A background launch counts; a child’s dispatch does not. If the agent’s owndecide.py --kind graderesult saysgrade: DECIDED architecture-led, a verifier dispatch must also name checkpoint F (checkpoint ForcpF) in its description or the first 600 characters of its prompt, and the deny names "checkpoint F (diff)" and does not offer the journal route below, which never stands in for checkpoint F. Off that grade, a head that startsResumed fromalso passes when the journal on itsJournal:line holds aStage 4orStage 7checkpoint block, acpF-r<n>round, the wordadversaryorcode-review. The journal is read only as a regular*.mdfile of at most 2 MB under the run directory. A head with noJournal:line, or a journal that cannot be read, fails open and is not logged. -
Form B. A line
reviewers: none - NO_CODE: <reason>, and no git commit, merge, cherry-pick, am, rebase, revert or pull of the agent’s own that ran. The hook splits each Bash command into simple commands and skips the global options of git (-C,-c,--git-dir,--work-tree,--namespace), socd /wt && git -C /wt commitcounts andgit merge-base, anechoand a heredoc body do not. A command that ran includes one that exited non-zero; a command a hook denied did not run. A command that does not parse counts as a write. The vault note’s commit,git -C "$FT_VAULT_PATH" commit, counts too: a run that commits a note uses form A or C. -
Form C. A line
reviewers: self-check - <verifier|adversary|both> unavailable, at least one attempted dispatch for each role it names, and a prominent line that covers each named role: "self-check only — no independent review" covers both, "no independent diff verification was performed" covers the verifier, and "no independent test-adequacy review" covers the adversary. A role it does not name need not have run (the lightweight path has no verifier).
The reviewers: line follows the rules of the ft-fix-host floor: a line start, the first or the last 4000
characters, dashes, bullets and bold. The bound, the deny state, the log suffix and FT_REVIEWER_FLOOR=0 are shared.
Declared residuals: the floor checks a declared escape, not the quality of a review; a lone adversary or
/code-review meets form A on any grade except a decided architecture-led one; a weak or forged journal passes a
resumed run; a resumed, dossier or self-graded architecture-led run is not checked for checkpoint F; a merge launch
without Group: merge is exempt when it starts Resumed from a split; a -next dispatch that cannot run satisfies
the attempt of form C; a report with a lower-case claim or no claim word is not checked; a delivered diff left
uncommitted passes form B, since only the agent’s own git writes are seen and its leaves never commit; a hand-written
group or slice prompt with neither the marker nor a Mode: slice first line gets no exemption (with no commit of its
own it passes form B); form C naming only the adversary passes an architecture-led run with no checkpoint-F verifier
(the cp1 design; the ft-fix-host floor differs); a decide.py --kind grade and a git commit in one Bash command
count as the grade only, so that commit is unseen; with no parentAgentId in its meta, a Mode: slice line is
honoured with no proof that a parent launched the run; a ticket text that quotes Original request: makes the text
before it the head (the same shape as price-gate _launcher_head); an agent that can write files can write its own
.meta.json, its parent’s or its transcript and so forge the exemption, the same trust class as the transcript
evidence of form A. A git write is not seen
through eval, $(…), backticks, sh -c, command git, env git, sudo, nohup, time, xargs, exec,
nice, a variable such as $g commit, or a git alias; the global options --config-env, --attr-source and
--super-prefix are not skipped, so a write after one with its value as the next word is unseen; plumbing (commit-tree then update-ref) is not a
write it knows. The unchanged Held._git has the same gaps.
The hook declares an item in these cases:
-
The
live:line holds the item id as a whole token. Text outside alive:line never declares. -
A job: the line holds a pid of one of its writers.
-
A detached item: the line holds the program name or a pid that the deny shows.
-
The id is compared without one trailing
/. -
The
live:lines come from the message, and from therecovery:field of the last## HANDOFFof each journal that the agent cites. The hook reads a journal only when it is a regular*.mdfile of at most 2 MB under~/.local/state/ft-ai-toolkit/run/. It reads at most 5 journals.
Inherited items come from the newest ## RESUMED block of the journals that the first prompt of a resumed agent
cites. Only the outcomes kept and re-armed <new id> are inherited. The outcomes killed and gone are not.
An inherited item is live unless the transcript of the successor ended it. It feeds the deny, the declaration
check and the record. It is never killed.
The bugfix-agent and refactor-agent floor
The same check refuses a standalone bugfix-agent or refactor-agent hand-back that holds a diff of its own and no
reviewer, at most 3 times. It reuses the ft-developer evidence; it adds no second mechanism.
-
A diff. An own git commit, merge, cherry-pick, am, rebase, revert or pull that ran, or an own
Edit,WriteorNotebookEditthat ran, except a write under the run-journal directory (~/.local/state/ft-ai-toolkit/run/). A diff typed by a delegated leaf is unseen. A hand-back with none of these is never refused. -
A stop. Only a hand-back led by
CONTEXT_RESETwhose first 600 characters carry no fix claim (thereviewers:claim words andcommit <sha>) is never refused.PARTIAL,BLOCKED,STOPPEDandSPLITmay ship code, so they get no exemption. -
A reviewer. A
verifier,ft-test-adversaryor/code-reviewof its own that ran (a background launch counts, a child’s dispatch does not). -
The escape. The
reviewers:line ofagents/ft-fix-host.mditem 8, in the same grammar:reviewers: none - <OUTCOME>: <reason>for a run that ships no code (a refactor addsNOT_WORTH_IT,BEHAVIOR_CHANGE_REQUIRED,BLOCKED_NO_SAFETY_NET,SCOPE_BREACH), orreviewers: self-check - <verifier|adversary|both> unavailablewith the prominent line. -
Exempt. A brief that carries a line
Pipeline: ft-fixanywhere beforeOriginal request:(theprice-gate.pymarker; also after a reset relaunch’s line-startResumed from a reset. Original brief: ` prefix), read only from the first user message: its host enforces the floor. Residual: a brief with no `Original request:marker is read whole, so a quoted ticket linePipeline: ft-fixexempts it; that text is the parent’s, never the agent’s, andprice-gate.pypairs the marker the same way.
FT_REVIEWER_FLOOR=0 turns it off. The log suffix ` floor=1`, then ` floor=open`, is the same.
The stop event
The event is SubagentStop, for every agent type. It never blocks and prints nothing. The hook treats the stop as
final when the agent delivered a successful hand-back (the tool result must read success: true), or when the
agent ran in the foreground. A stop that is not final writes no record and kills nothing. A hand-back
that reports success: false (a duplicate after new work) is not final.
The harness can fire the stop before it writes the hand-back’s own tool result to the transcript. When the last
tool use is a hand-back whose result is not there yet, the hook reads the transcript again every 0.1 seconds for at
most 2 seconds. If the result has still not arrived, the stop is not final.
At a final stop, the hook ends each live wait job that the report does not name. The kill rule:
-
The job is an own job, not an inherited one, and
is_waitis true for its command. -
The process is a writer of the job output. The hook reads the writers with one
lsofcall that has a 3-second timeout. -
The process has the same user id.
-
The command line of the process contains
/shell-snapshots/snapshot-, so it is a shell of the harness. -
The process is still a writer when the hook sends the signal.
-
The hook sends
SIGTERM, thenSIGTERMto the direct children of that process. It never signals grandchildren and never sendsSIGKILL.
FT_OWNERSHIP_KILL=0 turns the kill off and keeps the record. Gates, servers, detached processes, browsers,
worktrees and every declared item stay alive and are only listed.
What counts as a wait
is_wait is conservative. When it cannot prove that a command is a wait, the command is not a wait. Six rules apply
in this order:
-
The command is not a wait, with no further parsing, if it holds one of these:
(but$is allowed),<<, a backtick,$',${(, or a backslash before a newline (a line continuation). -
The command is not a wait if the parser cannot close a quote or a substitution, finds no simple command, or reaches a
(or)outside quotes and outside$(,$,<(and>(. So a subshell( sleep 5 ), an arithmetic command((…, a zsh glob qualifier*(…)and zsh=(…)are not waits: the last three can run code. -
The parser checks every word for expansions, with the quotes of that word. Outside single quotes, only these are accepted:
$NAMEand${NAME}(never followed by[),$?,$$,$#,$@,$*,$<digits>,$#NAME, a literal$, and$…when its body holds no substitution, backtick,<(,>(or[. Any other$form makes the command not a wait, for example$_(the previous command’s last word),$(,${!x},${x@P}and${x:-..}. Single quotes are inert. -
Every simple command starts with an allowed word:
sleep,test,[,[[,true,false,:,echo,printf,date,grep,egrep,tail,head,cat,wc,stat,ls,kill -0,gh pr checks … --watchorgh run watch. The wordsuntil,while,do,doneand!are allowed as shell syntax. A command with&, a subscript, or-vor-tintest,[or[[(zsh evaluates-t’s operand as arithmetic) is not a wait. `printftakes a literal format (no$, brace or glob, not starting with-:printf -v NAMEassigns) with only%s,%b,%qand%%(zsh evaluates a numeric argument).test,[and[[take no brace, glob,[or positional parameter in an operand, an operand starting with-is a literal operator (never-$v), and they must not name a variable given a single-quoted value; a[[that compares numbers (-eqand the like) reads only what a$…body may read (rule 5).ghtakes no--web/-w, no brace or glob word and no variable but one this command gave digits or$…. Anything else is not a wait:ssh, a script,mvn,docker,python,curl,gh pr view. -
A
VAR=valueprefix or assignment must be a literal or a single-quoted value that does not start a word with-(it would expand into an option), to a lower-case name that is not a zsh tied array (path,fpath,cdpath,manpath,mailpath,module_path,psvar,argv), or to one ofGH_TOKEN,GITHUB_TOKEN,GH_REPO,TZ,LANG,LC_ALL,NO_COLOR. Any other upper-case name is the environment’s and is refused (PATH,IFS,LD_*,GH_BROWSER,GIT_*). A$…body may read only a variable this command gave nothing but digits or$…, orSECONDS,EPOCHSECONDS,RANDOMandLINENO; never a positional parameter. Arithmetic re-evaluates a value, soy=PATH=0or aPATHfrom the environment would assign or recurse. -
At least one command really waits:
sleep,tail -fortail -F,gh pr checks … --watch, orgh run watch.
A heredoc is recognised only on an unquoted << that the parser reaches. Rule 1 makes such a command not a wait anyway.
Consequence: a wait that contains #, a backtick, <<, a line continuation or a subshell is not recognised as a
wait. Declare it in the report with a live: wait <id> · <what> · <next step> line. An undeclared command of this kind is listed,
and it is never ended.
The record
At a final stop, the hook writes one record for each agent: ownership/<session id>/<agent id>.json, mode 0600,
written atomically.
{"ts": 1730745600.0, "agent_id": "a90953db...", "agent_type": "bugfix-agent", "description": "...",
"final": true, "live": [{"kind": "job", "ident": "b33eu1rrs", "detail": "...", "wait": true, "pids": [4312]}],
"declared": ["bx0qg9odf"], "killed": [{"ident": "b33eu1rrs", "pids": [4312]}],
"undeclared_left": ["3f2a9c1b0e"]}
The record has one more field, idents: the real paths of the live worktrees of the agent. janitor.py and the health notice read these records. The log ownership-check.log in the state directory gets
one line for each event: <time> <event> <agent id> <agent type> final=<true|false> live=<n> declared=<n>
killed=<n> verdict=<allow|deny|record|skip>, and on the hand-back of a floor role under the reviewer floor one
more field, floor=<1|open|nostate> (refused, passed after the last refusal, passed because the deny state could
not be written). The log rolls to ownership-check.log.1 after 1 MB. If the hook crashes, it still allows the call and prints nothing. It
logs one line that ends in verdict=error error=<ClassName>, with the class name only and never the message. The detail
field is redacted: it hides the values after --password, --token, --api-key, --passphrase, -u user: and
Authorization:, the user information of a URL, sshpass -p, docker login -p, PGPASSWORD=, MYSQL_PWD=, any
PASS, TOKEN, SECRET or KEY variable prefix, and the password of sqlplus user/pass@.
| Variable | Default | Meaning |
|---|---|---|
|
on |
|
|
on |
|
|
|
The state directory of the records and the log. |
Known limits:
-
The writer check needs
lsof. Iflsofis absent or times out, the writers are unknown. Then a job with an output counts as live, the hook denies nothing for it, and it kills nothing. -
The hook ends only waits. A gate, a server, a detached process, a browser or a worktree is listed and left in place.
-
The hook sees only what the transcript shows. A process that the agent started in a way the transcript does not show is not an item.
-
A failed write of the deny state allows the hand-back, so a broken state directory removes the check.
-
A hand-back that names a thing passes, even if nobody takes the thing over later.
The canon for the report is in rules/agents/delegation-contract.md §10 and rules/agents/run-journal.md: the
recovery: field lists each live thing as live: <kind> <id> · <what> · <action>, with the kinds job, wait,
gate, monitor, worktree, browser, stand, forward, detached and agent, and the actions re-arm, kill,
keep (<who watches it>), remove and close. A resumed run settles each live: item first and appends a
## RESUMED <time> block with one line for each, ending in re-armed <new id>, killed, gone or kept.
The test stand convention
A test stand is a set of containers that an agent starts for a test. rules/agents/common.md requires these
labels: ft.owner=<agent id or lane>, ft.ttl=<hours> and ft.created=<ISO-8601 UTC>. The compose project is
ft-stand-<owner>-<yyyymmddHHMM>. Stop it with docker compose -p <project> down -v. Do not use down or rm
without -v, because the orphaned volumes reached about 250 GB. Until the stand is stopped, it is a
live: stand <project> item of the agent that started it. The pool part of janitor.py lists an expired stand and
never removes it.
Refresh gate
refresh-gate.py avoids an agent run that would republish the same page. It runs on PreToolUse and
PostToolUse for Agent and Task. Any other tool passes. It fails open on every path except the two denials
below: a bad payload, a cap, a deadline, a git or regex problem, or a corrupt state file allows the call.
A brief opts in with lines that start at the beginning of a line of its prompt:
| Line | Meaning |
|---|---|
|
The files that the refresh shows. Commas or spaces separate the items; prose after the paths is dropped, and a line with no readable path lets the dispatch through. |
|
Lines that match are left out of the fingerprint of an input file. The file must be 5 MB or smaller. An invalid regex allows the call. |
|
The name of the refresh. The default is the description in lower case with the digits removed, so |
|
An unchanged refresh older than this runs again. |
|
Run the refresh anyway, and record it. |
The PreToolUse event computes a fingerprint: a hash over the sorted path, size and modification time of each
input file, or over the content without the ignored lines. The hook walks globs itself. The whole check stops after 2 seconds, and the call is allowed.
A git rev-parse has a timeout of 2 seconds. More than 200 files or 50 MB also allow the call, with no record. The fingerprint waits under the tool_use_id of the call.
The PostToolUse event promotes that fingerprint to the record of the key, only when the launch succeeded. It
never computes the fingerprint again. A dispatch that price-gate.py denied, or that failed to launch, records
nothing.
Two denials exist:
refresh-gate: nothing in Refresh-inputs changed since the refresh at YYYY-MM-DD HH:MMZ (<key>), still inside its Refresh-max-age of Nh; it would republish the same page. Skip it, or add "Refresh: force" when it must run.
If the brief has no Refresh-max-age: line, the text between the key and the semicolon reads
, no Refresh-max-age set so it does not expire.
refresh-gate: a refresh brief declares what it shows: add "Refresh-inputs: <files>" (and "Refresh-ignore: <regex>" for lines you write yourself); it is then skipped when none changed. Sent again unchanged, it passes.
The second denial applies only to a status page refresh by its shape: a general-purpose call (or one with no
subagent_type) whose description holds the word refresh or republish (the whole word, in any case), whose
description or prompt names a publish word or a page, and whose prompt holds no Refresh-inputs: line. A coding,
review, ops or doc agent that mentions refresh is never denied; a Refresh-inputs: line opts any agent in to the
first denial. It fires once for each key in a session. Sent again unchanged, the call passes.
State: refresh-gate.json in the state directory, mode 0600, written atomically. The hook removes keys older
than 30 days and parked fingerprints older than 1 hour. The hook has no environment switch. Known limits:
-
A refresh agent that launches and then fails leaves the record. The next refresh runs only after an input changes, after
Refresh: force, or afterRefresh-max-age. -
Two hooks that run at once can lose an update. The hook then fails open.
Brief gates
Three scripts were built to make delegation cheap without removing a reviewer: delegation-gate.py,
evidence-store.py and diff-router.py. Only diff-router.py runs today. Each has a boundary document that states what it enforces and
what it cannot do. The shared contract is rules/agents/delegation-contract.md. It is installed as
~/.claude/rules/agents/delegation-contract.md.
| Contract rule | In short |
|---|---|
Brief |
A brief is an evidence pack: a goal, references (paths, not contents) and a declared budget. It never carries the parent transcript. The first line is |
Definition of done |
Measurable: an artifact at a path, a command with its outcome, or a |
Write scope |
The brief’s file list is the write boundary. A needed edit outside it stops the work and returns |
Four bounds |
Rounds, agent-runs, turns and wall-clock minutes. They are declared before the work. A receiver at a bound stops and returns what is proven. |
|
Any stop that is not a completed run writes a |
The overriding rule: economy never removes the last independent reviewer. The mandatory core of
rules/agents/verification-routing.md section 1 is emitted unconditionally for each checkpoint. The core
is Correctness, Security and API-contract, or Requirements-coverage, Security and
API-contract at checkpoint D. diff-router.py plan --drop-lens on a core lens exits 2. No gate rule
denies a core-lens dispatch.
The one named exception is the port-lane profile. It keeps Correctness, and it never removes
the last independent reviewer.
| Script and policy | What it does | What you see | What it cannot do | Installed |
|---|---|---|---|---|
|
Not installed. Registered by hand, it is a |
Nothing today. Registered by hand: one deny message that lists every violation. A repeat review with a recorded verdict is answered in the deny text, and the dispatch is not paid for. |
It judges structure, not content. It does not check that a receiver honored the |
c. Not installed, by the owner’s ruling of 2026-11-03: the installers neither copy nor register it. |
|
Stores immutable evidence packs (addressed by hash) and review verdicts (addressed by a key over contracts, diff, task, lens, role, pack and test state). Replays a verdict only for an identical key. |
No replay today: only the deny text of |
It cannot record a verdict by itself, and no pipeline calls its |
b. Both installers copy it, with no caller. |
|
|
A lens list with a cited reason for each lens and for each skipped lens. Exit 1: a conservative default fired every routed lens. Exit 2: a refused override. Exit 3: no diff to route. |
It cannot make a lens run. It matches paths and diff lines, not meaning. The caller supplies |
b. Both installers copy it. |
By the owner’s ruling of 2026-11-03, the installers (economy.py, install.sh and install.ps1) do not copy delegation-gate.py,
do not copy brief-schema.json and do not register the hook. The evidence replay path lives inside this
gate. The pipelines still call diff-router.py. No pipeline calls evidence-store.py. Nothing
replays a verdict or checks a brief.
|
The port-lane profile
The port-lane profile is the one named, scoped exception to the mandatory core. The owner ruled on 2026-11-29 that
this lighter review is accepted for ft-acs-qa port lanes. It is not a general relaxation. The canon is the paragraph
"The one named exception" in rules/agents/verification-routing.md section 1. The router behavior is in
deploy/evals/diff-router.md section 7. The review rules are on
Quality Pipelines Reference, The port-lane profile.
Commands. The orchestrator runs these commands. Each one needs the lane journal.
| Command | Effect |
|---|---|
|
Stage 1. It prints one |
|
Stage 7, round 1. It selects Correctness, Security when it fires, and the first test-adversary pass. |
|
Stage 7, after the one fix batch. It compares the final diff with the manifest that the orchestrator emitted after round 1. |
Exit codes. Exit code 4 is new. profile and plan exit with 4 when the router refuses the profile. The output lists
every failed token, for example branch-not-port or grade-not-simple-addition. A refused plan routes as it does
without --profile and adds the line PROFILE REFUSED <tokens>. --post-fix also exits with 4 for a manifest that does
not belong to the run. With --post-fix, exit code 3 means no diff. Treat exit code 3 as a finding, never as "nothing
new to review". For exit codes 0 to 2, see the table above.
Observed and self-asserted facts. The router checks the origin, the branch, the degraded observation and the launcher marker itself. The grade, the user-visible flag, the round, the checkpoint and the journal are values that the caller states. The router checks them against the journal where a check exists. It does not prove them.
Budget. price-gate.py raises the run-cost budget from 6 to 12 agent-runs. It does this only when all four
predicates hold:
-
The launcher marker
Profile: port-laneis recorded on the lineage root. -
The first Stage 1 section of the journal names the grade
simple-addition. -
The last
profile: port-laneline of that section isaccepted. -
No
regrade:line stands in the journal.
If one predicate fails, the grade table applies. budget_source names the failed predicate.
Post-fix check. --post-fix takes its baseline from the manifest file that the orchestrator emitted after round 1, not
from the route store. It spawns Security for each new citation: a new secret-read or security-class line, a removed
security-class line, or an edit of a security-path file. It spawns Security also when a round-1 citation is gone from the
final diff (a security-class line added in round 1 and removed by the fix batch). It spawns Correctness for each new,
renamed or deleted file. If nothing is new, it prints post-fix: nothing new to review and exits with 0.
Residual. Lines that the fix batch changes inside an already-reviewed file, without a new citation, get no independent re-read. The egress of an already-read secret is outside the Security trigger.
What the profile cannot enforce.
-
It cannot compel an orchestrator that never calls the router.
-
It cannot detect an
--emitfile that someone edited and hashed again. The self-hash catches accidents only. -
It cannot prove the values that the caller states.
Failure mode. The router reads the lineage marker through price-gate.py. A host installed with SKIP_ECONOMY=1 has
no price-gate.py. A host that cannot read the marker refuses every profile. The refusal fails closed to the full
mandatory core.
Command-line scripts
Five scripts are commands. The main loop and the agents run them through Bash, and you can run them
yourself. artifact-registry.py is also registered as a hook. The installer copies the five to
~/.claude/hooks/, and main-rules.md names them to the main loop. Each has --selftest, which runs offline
on temporary files.
| Command | What it replaces | Exit codes |
|---|---|---|
|
The question "where are the lanes", asked by hand |
0 ok; 2 no session or unusable argument; 3 |
|
The manual cleanup of merged worktrees, orphaned processes and dead waits. Dry run by default. |
0 ok or nothing to clean; 2 bad arguments; 3 a command failed |
|
The manual steps to write a vault note |
0 ok or unchanged; 1 internal error; 2 refused; 3 conflict; 4 git failure; 5 lock; 130 interrupted |
|
Finding the arguments of an old |
0 ok; 2 no match, several matches, bad arguments or an unreadable registry; 3 local file missing |
|
The one-off scans of the transcripts |
0 ok or no transcripts; 2 bad date |
lane-status.py
python3 ~/.claude/hooks/lane-status.py [--session ID] [--project DIR|NAME] [--all] [--report AGENT_ID]
The command prints the running sub-agents of one session, oldest action first. Without options it reads the
newest session of the current project under ~/.claude/projects. --project takes the directory name or a
path. Write a name that starts with a dash as --project=-Users-x. The command is read-only and uses no network.
If it finds no session, it names the directory that it searched and exits with 2. The message also names the next
action: run the command from the project directory, or pass --project. A --session id that matches no file is
named in the message, with the advice to drop --session or pass --project. --help describes every flag.
The command continues the saved walk of the health branch (lane-health/<session id>.json) and never writes it. It
reads at most the last 128 MB of the transcript past that point. When it has to skip a part, it prints a
partial: line: agents launched in the skipped part are missing, and agents that ended in it can still be counted.
It looks for the stops of children in the last 64 MB of the main transcript. A child stopped before that can show as
running, until it is silent for longer than the limit.
session b66ef1dc status line: none since your last message counted by the nudge: 2 running, 1 silent over 3h (--all)
AGE CTX TYPE LAST DESCRIPTION
1m 180K ft-developer - Resume part B at checkpoint F
1m 44K verifier Bash cpF lens Test-plan adequacy executor round 1
| Field | Meaning |
|---|---|
Header, |
The newest status line after your last message and its age, or |
Header, |
The number that |
|
Time since the last line of the agent’s own transcript, in seconds, minutes or hours. The file time replaces it when that line has no time. No claim of the agent counts. A row can show 4h while the nudge still counts the agent, because the nudge goes by the file time. |
|
Tokens of context in the agent’s last turn. |
|
The agent type. Children of a running agent are indented under it. The nudge does not count children, and the footer gives the row count with children. |
|
The last tool that the agent called. |
The table has a STATE column between LAST and DESCRIPTION. It shows the verdict of the health check of
ownership-check.py for each top-level agent, without the 4-second limit of the nudge. The verdicts are the same
as in The health notice.
STATE |
Meaning |
|---|---|
|
The agent works. |
|
The agent is stopped, but a job or a child of it is alive. |
|
The agent handed back, and the report never reached this session. |
|
The agent ended without a hand-back. |
|
The agent waits on a job that no process holds. |
|
The agent waits only on monitors and was silent for |
When the health check is unavailable, the column shows ? and a line says so. When lsof gave no answer in this
pass, a lane with an open job shows wait, and the line health: lsof unavailable, FROZEN not judged appears
above the attention: lines. Under the table, one
attention: line for each row that is not run or wait gives the same action text as the notice. A line
left by finished agents: <n> item(s) counts the live items that finished agents left. UNSEEN and ENDED agents
are not counted by the nudge, so the number in the header stays the number of the nudge.
python3 ~/.claude/hooks/lane-status.py --session <session id> --report <agent id>
--report prints the report of an agent that never reached you. It needs --session. The notice prints both. The
id is a full agent id or a unique prefix of 4 to 128 letters, digits, - or _. An ambiguous prefix exits with 2.
The command reads only <project>/<session>/subagents/agent-<id>.jsonl under ~/.claude/projects. It prints the
message input of the last SubagentHandback that succeeded, indented, redacted and capped at 20 KB, as data. If
the agent made no successful hand-back, it exits with 3 and prints one line. Exit codes of the command: 0 ok;
2 no session or an unusable argument; 3 --report found no hand-back.
janitor.py
python3 ~/.claude/hooks/janitor.py [--apply] [--root DIR]... [--min-age-h 12] [--only worktrees|processes|waits|runlogs] [--min-age-days 7] [--min-size-mb 10] [--json]
python3 ~/.claude/hooks/janitor.py --pool [--host H]... [--apply]
python3 ~/.claude/hooks/janitor.py --selftest
The command finds what finished lanes left behind: merged worktrees, orphaned processes, dead waits and old bulky logs. It is a
command, not a hook. The installer copies it to ~/.claude/hooks/ and registers nothing for it. It changes
nothing without --apply. Without --apply, each candidate prints as
<class> <target> · <why it is ours and idle> · <command>, with the command quoted for a shell. With --apply,
it runs the argument lists itself, never through a shell and never with a forcing flag. It prints
removed|ended|skipped <target>: <reason> for each candidate and then the counts. ended means that the command sent
SIGTERM. The summary line adds , failed N (exit 3) when N commands failed.
Exit codes: 0 ok (also janitor: nothing to clean), 2 bad arguments, 3 a command failed while the others ran.
--pool with --only or --root exits with 2. A root equal to $HOME or / exits with 2. A name taken from the
file system must match ^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$, or the command skips it.
Laptop mode is the default. It has four classes. The roots are the immediate children of each --root, else
FT_JANITOR_ROOTS, else ~/Projects.
| Class | What the command removes or lists |
|---|---|
Worktrees |
A linked worktree when every condition holds. The worktree exists, is not locked and is not prunable. It was untouched for |
Processes |
Only processes of your user that are older than 1 hour. |
Run logs |
Bulky machine output in the run directory, |
Lane state |
With |
The local Stop hook ~/.claude/scripts/detect-stuck-rig-procs.sh, which is not in this repository, still runs until the FLOW24 trial ends. It kills a parentless process with ForkedBooter in its command line with kill -9 on every turn and warns about the same containers. rig-jvm and rig-container cover the same cases in this manual command, with SIGTERM on a fork older than 1 hour.
A wait is over in one of three cases: (a) the consumer is gone (parent process 1), (b) the agent that started it is
settled, or (c) the target finished. Case (b) does not apply to a wait that its agent declared in an ownership record of
the last 24 hours. The line then reads declared kept by its agent (ownership record). Cases (a) and (c) still end a
declared wait, by design: they are facts (no reader is left, or nothing is left to wait for), while a declaration only
overrides the guess that case (b) makes about ownership. Case (b) holds when the transcript that structurally started the job shows a delivered hand-back (success: true), or the
agent state is stopped. The command judges the agent with the writer table of its own lsof call. In case (c), the target finished:
gh pr checks <n> on a merged or closed pull request, gh run watch <id> on a completed run, or a kill -0
loop on a literal pid that no longer exists. The target check accepts only literal digits and a -R owner/repo
that matches ^/[A-Za-z0-9._-]$. A GH_REPO= or GH_HOST= prefix, or a missing literal, makes the
shell list-only. If no case applies, the command keeps the shell and prints
harness wait of task <id> kept: consumer live (ppid <n>), no delivered hand-back of its agent found, <target reason>.
If the lsof call failed, the state of the agent is unknown. The command keeps the shell, replaces that part with
whether its agent <id> finished is unknown (lsof of its job outputs failed), marks the item as failed, and exits with 3. The gh calls share a budget of 30 seconds. Before each signal, the command reads the process
again and skips it when the start time or the command line changed.
Pool mode (--pool) is local only. It needs ~/.claude/mvn-slot.sh, which this repository does not ship.
Without that file, the command prints
janitor: pool mode needs ~/.claude/mvn-slot.sh (local-only, not shipped by this repo); skipped and exits with 0.
The hosts come from --host or FT_JANITOR_POOL_HOSTS. The command never reads the hosts file. For each host, it
runs one mvn-slot.sh call with an embedded POSIX shell payload. The payload refuses to run unless the user is
mvnslot and /var/lib/mvn-slot exists.
| Target on the host | Action |
|---|---|
Dangling volumes older than 1 day |
|
Unused images older than 7 days |
|
|
Removed only when the newest file in the tree is older than 3 days and no process of the user has its working directory or an open file there. Otherwise listed. |
|
Listed only. |
Test stands (containers with the label |
Listed only, with |
Make the first pool run a dry run on one host: janitor.py --pool --host <h>. Read the list before you
add --apply. Never run it on a host unattended. A host that fails or refuses is reported with the last line of
mvn-slot and is not retried. The payload uses GNU find and /proc, so it is Linux only.
|
On Windows (os.name is nt), the command prints janitor: process and pool classes are POSIX-only; worktrees only
and runs only the worktree class. lsof is absent there, and a failed lsof call keeps every worktree
(the check fails closed), so the command keeps every worktree on Windows.
FT_JANITOR_ROOTS, FT_JANITOR_POOL_HOSTS and FT_JANITOR_SELFTEST_RE are the only environment settings for
users. The names JANITOR_TMP, JANITOR_WORK and JANITOR_EXPECT_USER exist for tests and work only with
JANITOR_SELFTEST=1.
vault-note.py
python3 ~/.claude/hooks/vault-note.py --repo <slug> --type bugfix|decision|feature --key <JIRA-or-slug> \
--title "<title>" --body-file <path|-> [--severity minor|major|critical] [--update] \
[--hub <slug>] [--create-hub] [--jira K] [--area A] [--summary "<hub text>"] [--vault P] [--dry-run]
The command writes one note into the team vault, adds its entry to the hub note, commits the two files and
pushes. The note contract is in skills/obsidian-knowledge-vault/SKILL.md. The vault is the --vault path,
else $FT_VAULT_PATH. The path must hold AI/_Index.md and a .git directory. If neither is set, the command
exits with 2 and names deploy/scripts/install.sh --doctor. Until the vault works, print the note in your report.
You supply the body: the sections of the note, in English. The command writes the frontmatter, the title line
and the Hub line. --help prints the header of the script: the flags, the exit codes and the named residuals
of this page.
| Type | New note path | Required sections |
|---|---|---|
|
|
Symptom, Root cause, Fix, Notes (or Notes / follow-ups) |
|
|
Context, Decision, Alternatives, Consequences |
How the command decides, in order:
-
It refuses a bad argument, a body with text before the first
## ` heading, a missing section, Cyrillic text and a secret pattern. A refusal writes nothing, leaves `git statusof the vault clean and exits with 2. A refused note is reworded, never written by hand. -
It takes
.git/vault-note.lock. It waits up to 60 seconds, breaks a lock older than 300 seconds, and exits with 5 when it gets none. -
It runs
git pull --rebasebefore it writes anything. A conflict is aborted withgit rebase --abort, and the command exits with 3. Another writer’s uncommitted edit also exits with 3. After exit 3, nothing is written: clear the conflict or ask the other writer to commit, then run the command again. A failure such as no network exits with 4. -
It looks for an existing note with the same repo and key, in
AI/Bugfixes,AI/DecisionsandAI/. The lookup ignores case: the keydev-2841findsDEV-2841andDEV-2841-some-slug. Two notes whose names differ only by case exit with 2. A path that exists but is not a note (a directory, a broken link) exits with 2. A note exists and--updateis missing: exit 2, so you read the note and merge first.--updatereplaces every section from the first `## ` heading on and keeps the head of the note. -
It adds
- [[<note>|<summary>]]to the hub note of the repo, or of--hub. A missing hub note exits with 2 unless you pass--create-hub, so a mistyped slug creates no stray hub. TheHubline of the note and the hub entry name the same hub. With--update, the hub is--hub, else the hub that theup:line of the note names when that hub exists, else the hub of the repo. Anup:line that names a note which is not a hub exits with 2. -
It commits only the note and the hub, then pushes. A rejected push is retried once after a new pull. Every git call has a timeout of 120 seconds, and the whole run stops after 240 seconds.
An interrupt (Ctrl-C, SIGTERM or SIGHUP) aborts an open rebase and exits with 130. If the push was cut off, the
message says that the commit may have reached the remote. A later --update on an unchanged note still pushes
a local commit that an earlier run could not push. The line then says pushed existing local commit <sha>.
A rerun without --update after such an unpushed commit says that the note already holds this run’s body and
sits in a local commit that was never pushed. It says so only when three conditions hold:
-
Every unpushed commit that touches the note carries the commit subject of this tool (
<type>(<repo>): <key> …, case ignored). -
The note is clean.
-
The note on disk equals what
--updatewith this body would write (case ignored).
The message then tells you to rerun with --update and the same body, or to run git push in the vault clone.
The --update rerun rewrites no note text. It pushes every local commit that the clone has ahead of the
remote, not only the commit of this note.
In every other case it gives the plain note exists advice.
A stop after the write says what it left in the vault clone. If the commit failed, the message lists the files
that are written but not committed and gives the commands: git add, git commit and a push command. The push command is git push. If the branch
has no upstream, it is the command that gives the branch one (see below). The message tells you to run these
commands first and only then to run the tool again, because the tool refuses while those files are left in the vault. The exit 3
message offers git restore for an edit that is not yours. If the commit worked and the push failed, the message
names the local commit and says to run git push. If the branch of the vault clone has no upstream, the message
gives git branch --set-upstream-to=<remote>/<branch>. It picks the remote in this order: the branch remote
configuration, origin, the only remote, the push remote of the branch, else the placeholder <remote>. A
remote is ignored when its name does not look like a remote name, for example a URL, a value with @ or a
value that starts with -. This holds for configured remotes and for the names that git remote lists. The only-remote
choice still counts the raw list, so one valid remote is not chosen when an invalid one sits beside it. If the remote answers that it does not have the branch (an exact match of
refs/heads/<branch>), the message gives git push -u <remote> <branch>. If the remote cannot be asked, the message
never gives git push -u. A vault file that the command cannot read or write exits with 4.
Exit 1 is an internal error, a bug of the script. The message names the exception class and never the content.
Nothing is pushed unless the output already held a commit line. Check git status in the vault clone.
On success the command prints one line: vault-note: <created|updated> <path> commit <sha> pushed. It adds
hub created, head kept N lines (stale text in the head stays visible), the scan state and, when a checkpoint
note for the same key exists, still owed: fold and delete <checkpoint note>. The command never folds or
deletes a checkpoint note. --dry-run prints the note and the hub line and touches nothing.
The command removes control and format characters from every line it prints, on success, in the --dry-run
preview and in error messages. Each such character shows as ?, and a tab shows as four spaces.
The secret scan covers every text value. It refuses key shapes (API keys, tokens, private keys), assignments such as
password: x, commands that carry a password and connection strings with a password. The message names the
line and the class and never repeats the value. There is no override.
A pattern cannot tell a pair of ordinary words from a user name and password. For that case, create the file
~/.config/ft-ai-toolkit/vault-secret-values with mode 0600. Write one secret per line. Never write an
ordinary word: the scan matches a value anywhere in the text, so a plain word would refuse many notes. The
command skips blank lines and never prints a value. The file may start with a byte order mark (BOM, the UTF-8
signature that Notepad and PowerShell 5.1 write): the command reads the file as utf-8-sig, so the mark does not
stick to the first value. If other users can read the file, the success line says to run chmod 600 on it. If the file is absent, the success line and --dry-run
say secret scan: shapes only, no values file. The command works without the file, but it then cannot catch
such a pair. Credentials do not belong in CLAUDE.md or in a vault note.
Named residuals of the script:
-
The scan judges shapes. A flag form such as
--password <value>and a bare<user>:<password>@hostpass. Add the value to the values file. -
A rerun can call a note "already holds this run’s body" after a clean rebase under a teammate’s edit to a part that the body keeps. The advice stays true, because
--updatethen changes nothing but the push. -
The command breaks a stale lock with a check and a delete. That is not atomic, and the window is a few microseconds.
-
--update --dry-runprints the existing head of the note without a scan. The H1 line that the command copies into the hub entry and the commit subject, when you pass no--title, is not scanned either.
artifact-registry.py
The script has two roles. As a PostToolUse hook on the Artifact tool, it records each published link. As a
command, it prints what a new Artifact call needs.
python3 ~/.claude/hooks/artifact-registry.py list
python3 ~/.claude/hooks/artifact-registry.py show <title|url|file>
python3 ~/.claude/hooks/artifact-registry.py backfill [--days N] [--root DIR]
| Mode | What it does |
|---|---|
Hook (no arguments, input from a pipe) |
Appends one JSON line to |
|
One row for each link, newest first: age, title, file state ( |
|
Prints the arguments of one |
|
Reads the publishes of the last 30 days ( |
Limits:
-
The script records and prints. It cannot call
Artifact. -
After an account switch an old link returns 404. That link belongs to the other account, and the tool refuses a republish that passes its
url. Drop theurland publish: the link changes. Whoever holds the old link must get the new one. -
The script cannot restore a local file that a reboot removed from
/private/tmp. -
Unverified: the hook reads
tool_responseas a dictionary with aurl, or as text. No livePostToolUsepayload was captured. The first publish after the install confirms the shape.backfilldoes not depend on it: it reads the structured tool result in the transcripts.
session-audit.py
python3 ~/.claude/hooks/session-audit.py [--from YYYY-MM-DD] [--to YYYY-MM-DD] [--project TEXT] [--top N] [--json] [--jobs N]
The command reads the transcripts under ~/.claude/projects and reports where the tokens and the turns went.
The default window is the last 3 days (UTC). --project filters the project directories by a substring. The
command skips the scratchpad probe projects unless --project names them. It is read-only, offline and
needs only Python. A bad date exits with 2. A window with no transcripts prints one line that names the project filter and the dates, with the advice to widen
--from and --to or drop --project. With --json, that line is a JSON object. An unreadable transcript is named
on stderr and skipped.
Costs are the notional list price of deploy/evals/spend-report.py: opus 5 and 25, sonnet 2 and 10, haiku
1 and 5 dollars per million input and output tokens, cache read at 0.1x and cache write at 1.25x. One assistant
message counts once, even when it spans several transcript lines.
session-audit 2026-10-31..2026-11-02 UTC project=all files=4493 (notional list price)
cost $N: read $N, write $N, output $N, input $N
main $N (runs N, turns N) | sub-agents $N (runs N, turns N)
top agents: $ turns peak-context-tokens type description
by type: type runs $ median-$ median-peak-context-tokens
mechanical errors: N turns (exit and other not counted): <class> N, ...
waits: N turns, $N (bash sleep/until/watch, Monitor)
vault work: N turns, $N (from the first vault write ... the messages touching the vault themselves: N turns, $N)
owner asks (regex, approximate): lanes N, status or stuck N, republish N
-
Mechanical errors are failed tool results. The classes are
hook-deny,perm-denied,edit-miss,file-missing,too-large,timeout,exit,cancel,otherandsleep-blocked, the refusal of a baresleep. -
Waits are messages that run a Bash
sleep,untilor watch loop, or callMonitor. -
Vault work has two figures on one line. The first is a window: it runs from the first message that writes to the vault or runs git on
$FT_VAULT_PATHto the end of that agent. It includes every later turn of that agent, so it is the upper bound. The second figure counts only the messages that touch the vault themselves. The two figures differ on purpose, and the report keeps both. The manual audit of 31 October to 2 November found about $336 with its own scan. The script gave $1868 for the window and $408 for the touching messages on 4884 files (run journal, not re-run for this page). -
Owner asks count your own messages that match a pattern. The count is approximate.
The text report prints agent descriptions with control characters removed. --json prints counts, classes and
numbers, and never a description or any raw text, because transcripts hold credentials.
State and logs
File under ~/.local/state/ft-ai-toolkit/ |
Written by, and what for |
|---|---|
|
|
|
|
|
|
|
|
|
The notes' "already said" state ( |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
The run journals and packs that the orchestrators write ( |
|
|
|
|
price-gate.py reads these caps and paths from its own environment. The installer sets none of them.
| Variable | Default | Meaning |
|---|---|---|
|
2 |
The checkpoint F round after which the hook denies a |
|
2 |
The number of resets that a group or merge instance may make. A relaunch past it is denied ( |
|
10 |
The number of instances that one lineage may hold. A relaunch that carries |
|
|
The path of the lineage state file. The lock file has the same path with the suffix |
|
1 |
The value |
|
3 |
The number of boundary-hold events for each harness compaction epoch. |
|
4 |
The number of held resends that the bound root must still be able to pay, with the relaunch, before the hook holds. |
|
|
The path of the boundary-hold state file. The lock file has the same path with the suffix |
decide.py reads Jev’s key from ~/.config/ft-ai-toolkit/openrouter.key (FT_DECIDE_KEY_FILE).
vault-note.py reads the optional file ~/.config/ft-ai-toolkit/vault-secret-values. The file is described under vault-note.py.
What the installer changes in ~/.claude
The installers apply all of it in one step (Install step). This is the exact list, so you can check it or apply it by hand.
| File | Change | If you already have something there |
|---|---|---|
|
Copied from |
Overwritten when it differs from the toolkit copy. |
|
Copied from |
Overwritten when it differs from the toolkit copy. |
|
Copied (both installers). The bugfix and refactor agents call it from their frontmatter and skip it when absent. |
Overwritten. |
|
One entry: matcher |
Left alone when any |
|
Matcher `Bash |
Monitor`, command |
Left alone when any |
|
Matcher |
Left alone when any |
|
Matcher |
Left alone when any |
|
The rule |
Left alone when any rule already contains |
|
Copied from |
Overwritten. |
|
|
Left alone when set. |
|
|
Left alone when set. The key reaches the shell of every agent. A machine with |
|
One entry, no matcher: command |
Left alone when any |
|
Matcher |
Left alone when a |
|
No matcher, command |
Left alone when a |
|
Matcher |
Left alone when a |
|
Matcher |
Left alone when a |
|
Two entries, no matcher: |
Each is left alone when any |
|
One entry: matcher |
Left alone when any |
|
Two entries: matcher |
Each is left alone when any |
|
|
Your own value is kept. |
|
Set to |
Never re-enabled. |
|
A block between |
Replaced in place on every run. Nothing outside the markers is touched. Created when the file is absent. |
|
|
Overwritten like every agent. |
|
Checked for presence and mode |
The settings entry, for a hand edit:
{
"autoCompactWindow": 600000,
"env": {
"CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS": "30",
"PONYTAIL_SUBAGENT_MATCHER": "^no-subagent$"
},
"permissions": {
"allow": ["Bash(python3 ~/.claude/hooks/diff-router.py plan:*)"]
},
"hooks": {
"PreToolUse": [
{
"matcher": "Agent|Task|SendMessage",
"hooks": [{ "type": "command", "command": "python3 ~/.claude/hooks/price-gate.py", "timeout": 15 }]
},
{
"matcher": "Bash",
"hooks": [{ "type": "command", "command": "python3 ~/.claude/hooks/checkout-guard.py", "timeout": 5 }]
},
{
"matcher": "Bash",
"hooks": [{ "type": "command", "command": "python3 ~/.claude/hooks/heredoc-guard.py", "timeout": 5 }]
},
{
"matcher": "SubagentHandback",
"hooks": [{ "type": "command", "command": "python3 ~/.claude/hooks/ownership-check.py", "timeout": 10 }]
},
{
"matcher": "Agent|Task",
"hooks": [{ "type": "command", "command": "python3 ~/.claude/hooks/refresh-gate.py", "timeout": 5 }]
}
],
"SubagentStop": [
{ "hooks": [{ "type": "command", "command": "python3 ~/.claude/hooks/turn-guard.py", "timeout": 10 }] },
{ "hooks": [{ "type": "command", "command": "python3 ~/.claude/hooks/ownership-check.py", "timeout": 10 }] }
],
"Stop": [
{ "hooks": [{ "type": "command", "command": "python3 ~/.claude/hooks/main-compact.py", "timeout": 10 }] },
{ "hooks": [{ "type": "command", "command": "python3 ~/.claude/hooks/lane-nudge.py", "timeout": 15 }] }
],
"SessionStart": [
{
"matcher": "startup|resume|clear|compact",
"hooks": [{ "type": "command", "command": "python3 ~/.claude/hooks/main-rules.py", "timeout": 5 },
{ "type": "command", "command": "python3 ~/.claude/hooks/main-rules.py --part 2", "timeout": 5 }]
}
],
"PostToolUse": [
{
"matcher": "Artifact",
"hooks": [{ "type": "command", "command": "python3 ~/.claude/hooks/artifact-registry.py", "timeout": 5 }]
},
{
"matcher": "CronCreate|CronDelete",
"hooks": [{ "type": "command", "command": "python3 ~/.claude/hooks/main-rules.py", "timeout": 5 }]
},
{
"matcher": "Agent|Task",
"hooks": [{ "type": "command", "command": "python3 ~/.claude/hooks/refresh-gate.py", "timeout": 5 }]
}
]
}
}
The global CLAUDE.md block
economy.py writes deploy/templates/claude-md/economy.md into ~/.claude/CLAUDE.md, between the
markers <!-- ft-ai-toolkit:economy:begin --> and <!-- ft-ai-toolkit:economy:end -->. Claude Code
delivers that file to the main loop and to every agent on every turn, so the block holds only the rules
that every agent must obey. The rules of the main loop alone are in main-rules.md, which the hook
main-rules.py delivers at session start.
| Situation | What the installer does |
|---|---|
The markers are present |
Replaces the text between them. Nothing outside the markers changes. |
The markers are absent |
Appends the block. Creates the file when it is absent. |
The block sits under the old |
Renames the markers and replaces the block in place. |
Lines inside the markers are not in the template |
Prints a |
|
Reports |
|
Prints |
Put your own rules below the end marker. The block holds no credential, and no credential belongs in
CLAUDE.md: Claude Code delivers the file to every agent on every turn.
The block is short on purpose, because it costs tokens in every agent. The rules that only the main loop needs
live in ~/.claude/main-rules.md (routes, lanes, relaunch after a context reset, the four commands of
Command-line scripts, operational batches). main-rules.py delivers that file as SessionStart
context. A probe showed that this context reaches the main thread only, and it arrives again after a compact.
Sub-agents therefore do not pay for it. The status line of the main loop keeps the literal form
lanes <running>/<target>, which lane-nudge.py reads.
What the block tells every agent (economy.md):
-
A lane messages the main loop only on a blocker or a decision that is not its own. Routine progress goes to its journal.
-
Run any wait over about 4 minutes in the background and end the turn. The stack’s agents keep a 1-hour cache, so the wake is a cache read. An agent on the 5-minute cache (
general-purpose, the reviewers) waits in 4-minute foreground chunks for a wait under about 40 minutes. A short wait is ONE foreground command.checkout-guard.pydenies a baresleep(see Timer waits). -
Avoid the shell traps that cost the most turns: quote
==and globs in zsh, use BSDsed -i '', expect a refused foregroundsleep, read a file beforeEdit, call the toolBash, and runToolSearchbefore a deferred tool. -
Write knowledge by what it costs to load:
CLAUDE.mdfor must-obey rules,.claude/rules/for one area, the vault for decisions and history.
What the main loop gets in addition (main-rules.md):
-
Route code work through the orchestrators: features
/ft-dev, bugs/ft-fix, cleanup/ft-refactor. -
End the prompt with
Resets: handledwhen you launchft-developerorbugfix-agentyourself, and relaunch a fresh one onCONTEXT_RESET. Start the pending units of aSPLITas separate runs. Never send a message to a retired agent. -
Send a MAJOR or CRITICAL bug through
/ft-fix, hosted by oneft-fix-hostwhen you keep your context small. Never send it to a barebugfix-agentor ageneral-purposehost. Relaunch a host that returnsCLIMB: opuswithClimb: opus. -
Send a small change with no design choice in it to
bugfix-agentas MINOR, or to the stack’s coding agent. Send a small addition that follows an existing pattern to/ft-dev(simple-addition). See Quality Pipelines, Choosing the entry point. -
Send UI/UX work on an existing screen to one
ft-ui-ux-design. Larger builds go to/ft-dev. -
Send a design document for people to one
ft-sdd, never to a fork or ageneral-purpose. -
Keep the number of running lanes that the owner last asked for. When a lane ends, start the next backlog item in the same turn. Every status line says
lanes <running>/<target>. -
Over about 200K of context, hand operational batches to one
ft-opsagent. Keep the approvals and design choices. Past 300K the price gate adds a note that asks you for/compact, and in Terminal.appmain-compact.pytypes the command for you. See Dispatch Economy. -
Audit before fixing: 1 to 3 audit rounds, then ONE fix batch. Write by day and run heavy batches in the evening.
Install step
install.sh and install.ps1 both run deploy/scripts/economy.py right after the rules sync. They run
it again, with --check, in the verification pass of every run and of --doctor (-Doctor on
Windows). There is one implementation and two thin callers, so the two installers cannot drift. The
install commands, the preview and the options are on Deployment & Usage.
deploy/scripts/install.sh --doctor # verify only: "economy hooks, settings.json wiring, CLAUDE.md block"
SKIP_ECONOMY=1 deploy/scripts/install.sh # leave the economy step out (and out of verification)
-
The step first removes the toolkit’s own superseded
-nextagents, entry skills and rules from~/.claude. It touches nothing else. -
The step is idempotent. Each item prints one
ok,dry-run,MISSINGorWARNline. A second run reports every lineok. -
An unreadable
settings.jsonstops the step with exit 2 and leavessettings.jsonandCLAUDE.mduntouched. -
The step needs Python 3 (
python3, orpythonon Windows). Without it the step warns and is skipped. -
The claude-mem offer follows the installer’s usual rule: a TTY
y, orASSUME_YES=1.
Evidence
The numbers on this page are measured in deploy/evals/dispatch-economy-evidence.md. It is the same
record as on Dispatch Economy. evidence §N names a section of that file.
How Claude Code behaves underneath
The rules on this page rest on these observed behaviours. They were measured in Claude Code versions 2.1.29x to 2.1.31x (October 2026).
| Behaviour | Effect |
|---|---|
Every |
It returns "Async agent launched" at once, with or without |
A sub-agent that ends a turn with nothing running is forced to hand back. |
The harness answers with |
Notices travel up. |
A child that ends a turn while its own background job runs sends its parent an interim notice. Each notice is a turn of the parent, paid at the parent’s context size. No setting, env var or hook suppresses it. Version 2.1.311 fixes auto-mode wake loops and the |
The prompt cache lives five minutes for a sub-agent. |
It lives one hour for an agent whose frontmatter says |
A foreground |
A command that hits the cap moves to the background and keeps running. "Repeat on timeout" stacks copies (§6). |
Agent types load at session start. |
A running session learns a new agent type through an |
Installing hooks, rules or agents does not invalidate the cache of running agents. |
§60. |
Measurements behind the rules
| Rule | Measurement or date |
|---|---|
|
Eight denials on 2026-11-01 had no such line for a judgment lens or the test adversary on a cheaper model. |
|
One journal append ran |
|
One lane shipped a script to the pool hosts as an encoded payload piped into bash inside an ssh command, on 2026-11-13. |
|
Seven phases that |
|
One session spent 52% of its context on images and ended early. |
|
On 2026-10-23, three timeouts at 5 s in one night let dispatches through unpriced (§41). |
|
The harness default of 20 refused 56 dispatches over 2026-10-15 and 2026-10-16, at 3 to 14 lanes. |
|
Replayed over the lanes session of 2 November with the delivered code, it nudged 8 times for the UTC day when it was first repaired and 10 times at the last run. The transcript grew between the runs, and the change adds no nudge. The bar of 1 to 8 was set on a shorter transcript of the same session, and the owner accepted 8 to 10 (run journal, not re-run for this page). The earlier design with a 900-second doubling gap gave 23 nudges on that day. |
|
Replayed over 183,295 real Bash commands, it denied 428. The review of the distinct shapes found no false positive. |
|
Over 2,096 notes in the vault, the key shapes alone refuse 98 (4.68%, bar 5%). Of 5 known credential lines, the shapes catch 1 and a values file catches all 5. |
|
A run over 3 days of transcripts takes about 6 seconds. It reported waits of $427 where the manual audit found $402. For vault work it reports a window ($1868) beside the messages that touch the vault ($408), and the manual audit found $336. See session-audit.py. |
|
Over 3 days of transcripts it found 271 publishes. |
|
Replayed over 4,075 orchestrator turn ends (2026-10-10 to 2026-10-16, ftacs), it would have blocked 33 of the 41 forced hand-backs that cut a run short. It would also have blocked 75 turn ends that the harness let through, about one extra turn per lane per day. Live overnight on 2026-10-15 and 2026-10-16 it blocked 7 turn ends, and three agents kept working. |