Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions host-setup/agent-safety/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ A hook implementing these requirements bounds a mistake by an agent acting in go
Each requirement is stated as a decision rule. It is precise enough to implement against any agent's own hook or approval-gate API, and not tied to Claude Code's `PreToolUse` JSON shape. Requirement 8 is stated against the end of a session rather than against a tool call. That is because what it covers has already happened by the time any tool call is judged. Requirement 9 bounds every command whatever its
text says, because the harm it covers was never in the text.

Requirements 1 to 7 and 11 judge a command's text, read the way a simple lexer reads it. The text splits into commands on a newline, `;`, `&&`, `||`, `|`, and `&` outside quotes, honoring single and double quotes and backslash escapes. Each command is read as its words, with leading `VAR=value` assignments and redirections set aside. A `$(...)` or backtick substitution stays part of its word and is not read. A heredoc body is data, never commands. An `export VAR=value` or a `VAR=value` earlier in the text is the environment a later command sees. A `cd` or `pushd` earlier in the text moves the directory a later command runs in. Each of those ends at the closing parenthesis of a subshell holding it. A launcher such as `timeout`, `nohup`, `env`, or `xargs` is read past to the command it runs. An `env` is read as `env` applies it. Its `-C` moves the directory the command runs in, and its `-i` and `-u` clear what the command inherits. Its `-S` string is split into the words it runs. Each option it does not recognize, such as an abbreviation of `--chdir`, may or may not take the next word. A value it takes may be an `-S` string. Every combination of up to four of those choices is read. The literal string an `sh -c`, `bash -c`, `eval`, or `xargs ... sh -c` runs is read the same way. It is read one level deep and no deeper. A shape this reading does not reach is allowed, except under requirement 4.
Requirements 1 to 7 and 11 judge a command's text, read the way a simple lexer reads it. The text splits into commands on a newline, `;`, `&&`, `||`, `|`, and `&` outside quotes, honoring single and double quotes and backslash escapes. Each command is read as its words, with leading `VAR=value` assignments and redirections set aside. A `$(...)` or backtick substitution stays part of its word and is not read. A heredoc body is data, never commands. An unquoted brace expansion is read as the words the shell expands it to, so `{a,b}.txt` is two words. A quoted one stays one word. A word of a `git` or `gh` command is denied as unreadable when it expands past 64 distinct words, or 1024 words in all. Other commands are read as before. An `export VAR=value` (or an assignment to `declare`, `typeset`, `readonly`, or `local`) or a `VAR=value` earlier in the text is the environment a later command sees. A `cd` or `pushd` earlier in the text moves the directory a later command runs in. Each of those ends at the closing parenthesis of a subshell holding it. A launcher such as `timeout`, `nohup`, `env`, or `xargs` is read past to the command it runs. An `env` is read as `env` applies it. Its `-C` moves the directory the command runs in, and its `-i` and `-u` clear what the command inherits. Its `-S` string is split into the words it runs. Each option it does not recognize, such as an abbreviation of `--chdir`, may or may not take the next word. A value it takes may be an `-S` string. Every combination of up to four of those choices is read. The literal string an `sh -c`, `bash -c`, `eval`, or `xargs ... sh -c` runs is read the same way. It is read one level deep and no deeper. A shape this reading does not reach is allowed, except under requirement 4.

1. **A GitHub write with its output discarded or forced to success is denied.** The write is a mutating `gh` call or a `git push`. Its output goes to `/dev/null` (`>/dev/null`, `2>/dev/null`, `&>/dev/null`), or `|| true`, `|| :`, or `|| echo` follows it. Either hides the one signal that tells a client-reported failure apart from a server-side success. Deny it, so the write runs again with its result visible. A tail on a wrapper shell or an `eval` counts for the write inside it. A tail the reading does not attach to the write, such as one on an enclosing group, is allowed.
2. **A GraphQL mutation carrying a literal GitHub node id is denied.** Node ids resolve globally, so a fabricated, stale, or hand-typed id can land on a real object in a different repository. A literal id is an uppercase-letter prefix such as `PR_`, `PRRT_`, `IC_`, or `BOT_` followed by a long body, or the legacy `MD`-prefixed base64 form. It is denied as a `-f`/`-F` field value of a `gh api graphql` mutation, and as a quoted string in the mutation's query text. A `-F name="$VAR"` value is allowed. A static hook cannot see where a variable's value came from, and this rule's job is the literal-id mistake. The fleet's prose rule (`GOVERNANCE.md` "Repository Boundaries and Write Safety") requires that the value came from a live query. A query read from a file, as in `query=@file.graphql`, is not read and is allowed.
Expand All @@ -36,7 +36,7 @@ Requirements 1 to 7 and 11 judge a command's text, read the way a simple lexer r
- an `--org`, `--owner`, or `-o` value other than `@me`

When no `origin` resolves, no owner exists to compare against, and this requirement does not fire. A target held in a run-time word, as in `--repo "$T"`, is not read and is allowed.
4. **A git operation that would only succeed by bypassing an active branch rule is denied.** The explicit bypasses are denied whatever the branch, since each is the bypass itself. They are `--admin` on `gh pr merge` and `--no-verify` on a commit or push. They include a commit's `-n`, alone or in a short-option cluster such as `-an`. A short-option cluster is read as git reads it, up to its first letter taking a value. The rest of the word is that value, or the next word where nothing follows that letter. So `-mtest -n` carries `-n`, and `-Snkey` names a signing key rather than `-n`. They include a `-c` override of `core.hooksPath` or of an include (`include.path`, `includeIf`) on a commit or push. A push is also judged against the *live* rules of each branch it writes. Those rules deny a direct push to a branch whose rules require a pull request. They deny a force-push where history is protected, and a delete where deletion is blocked. So a code-style `develop` denies and a config-style `develop` allows with no per-repo configuration. A force-push and a delete each write the branch too. So a branch whose rules require a pull request denies them as it denies a direct push. A push writes the branch each refspec names, read as git reads `src:dst`, `+src`, `:dst`, `HEAD`, and a `refs/heads/` destination. A push naming no refspec and no `--tags` writes the branch checked out in the repository git uses, as read below. `--force`, `--delete`, `--all`, and `--mirror` apply as git applies them, and `--all` or `--mirror` is read as writing every branch protected by default. `-f` and `-d` apply the same way in a short-option cluster such as `-uf`. The rest of a cluster after its first `o` is the push option's value, as is the next word when nothing follows that `o`. The rules are those of the repository the push's remote writes, read from the remote's push URL or from a URL the push names. A remote's URL is read in the repository git itself uses. That is the one a `--git-dir`, or a `GIT_DIR` set on the push itself, names, or else the one where the push runs. A `--work-tree` does not move it. A `-c` or `--config-env` override of a `remote.` or `url.` key can change that URL in a way the reading does not apply. So can a variable set in the text whose name starts with `GIT_CONFIG`. So does a `--git-dir` or `GIT_DIR` the reading does not resolve. So does a `GIT_DIR` set earlier in the text, since whether git sees it turns on an export or an `unset`. So does an unrecognized `env` option, since it may move the push. Each leaves the repository undetermined. Behind such an option, an absolute `--git-dir`, git `-C`, or `cd` in a wrapper body still names it. **This one fails closed, but only for a branch protected by default** (`main`, `master`, `develop`). The live-rules read pins `GH_HOST=github.com` in its child environment, so an exported `GH_HOST` cannot send it to another host. When that branch's rules cannot be determined at all (network unreachable, origin unresolvable), deny rather than allow. That is because the harm is a silent success under the maintainer's own admin bypass. A push to any other branch whose rules cannot be determined passes, since there is nothing yet on record to bypass. A refspec naming no branch the reading resolves, such as a run-time word or a pattern, is allowed. So is a push an alias or a script runs. A push naming no refspec, or `HEAD`, whose branch the reading does not read is the exception. It is read as writing every branch protected by default, as `--all` is. That covers a push whose repository the reading does not determine, and one in a directory with no branch checked out to read. It also covers every such push in a command that can switch the branch checked out. Such a command is one running `git switch`, a `checkout` other than of paths after `--`, or a `rebase` naming the branch to rebase. So is one running `stash branch`, a `branch` rename, a `symbolic-ref` write, or `gh pr checkout`. The branch is read before the command runs, and a loop or a function can run any of these before or after the push. So the branch read is judged as well as every protected default. A branch change an alias or a script makes is not seen. So such a push may be refused even from a feature branch, and naming the branch in the refspec is the remedy.
4. **A git operation that would only succeed by bypassing an active branch rule is denied.** The explicit bypasses are denied whatever the branch, since each is the bypass itself. They are `--admin` on `gh pr merge` and `--no-verify` on a commit or push. They include a commit's `-n`, alone or in a short-option cluster such as `-an`. A short-option cluster is read as git reads it, up to its first letter taking a value. The rest of the word is that value, or the next word where nothing follows that letter. So `-mtest -n` carries `-n`, and `-Snkey` names a signing key rather than `-n`. They include a `-c` override of `core.hooksPath` or of an include (`include.path`, `includeIf`) on a commit or push. They also include config set through the environment on a commit or push. That is a variable set in the text whose name starts with `GIT_CONFIG`, or `HOME` or `XDG_CONFIG_HOME`. Each can change which hooks git runs. It can set `core.hooksPath` or drop the config that sets it. A push is also judged against the *live* rules of each branch it writes. Those rules deny a direct push to a branch whose rules require a pull request. They deny a force-push where history is protected, and a delete where deletion is blocked. So a code-style `develop` denies and a config-style `develop` allows with no per-repo configuration. A force-push and a delete each write the branch too. So a branch whose rules require a pull request denies them as it denies a direct push. A push writes the branch each refspec names, read as git reads `src:dst`, `+src`, `:dst`, `HEAD`, and a `refs/heads/` destination. A push naming no refspec and no `--tags` writes the branch checked out in the repository git uses, as read below. `--force`, `--delete`, `--all`, and `--mirror` apply as git applies them, and `--all` or `--mirror` is read as writing every branch protected by default. `-f` and `-d` apply the same way in a short-option cluster such as `-uf`. The rest of a cluster after its first `o` is the push option's value, as is the next word when nothing follows that `o`. The rules are those of the repository the push's remote writes, read from the remote's push URL or from a URL the push names. A remote's URL is read in the repository git itself uses. That is the one a `--git-dir`, or a `GIT_DIR` set on the push itself, names, or else the one where the push runs. A `--work-tree` does not move it. A `-c` or `--config-env` override of a `remote.` or `url.` key can change that URL in a way the reading does not apply. So does a `--git-dir` or `GIT_DIR` the reading does not resolve. So does a `GIT_DIR` set earlier in the text, since whether git sees it turns on an export or an `unset`. So does an unrecognized `env` option, since it may move the push. Each leaves the repository undetermined. Behind such an option, an absolute `--git-dir`, git `-C`, or `cd` in a wrapper body still names it. **This one fails closed, but only for a branch protected by default** (`main`, `master`, `develop`). The live-rules read pins `GH_HOST=github.com` in its child environment, so an exported `GH_HOST` cannot send it to another host. When that branch's rules cannot be determined at all (network unreachable, origin unresolvable), deny rather than allow. That is because the harm is a silent success under the maintainer's own admin bypass. A push to any other branch whose rules cannot be determined passes, since there is nothing yet on record to bypass. A refspec naming no branch the reading resolves, such as a run-time word or a pattern, is allowed. So is a push an alias or a script runs. A push naming no refspec, or `HEAD`, whose branch the reading does not read is the exception. It is read as writing every branch protected by default, as `--all` is. That covers a push whose repository the reading does not determine, and one in a directory with no branch checked out to read. It also covers every such push in a command that can switch the branch checked out. Such a command is one running `git switch`, a `checkout` other than of paths after `--`, or a `rebase` naming the branch to rebase. So is one running `stash branch`, a `branch` rename, a `symbolic-ref` write, or `gh pr checkout`. The branch is read before the command runs, and a loop or a function can run any of these before or after the push. So the branch read is judged as well as every protected default. A branch change an alias or a script makes is not seen. So such a push may be refused even from a feature branch, and naming the branch in the refspec is the remedy.
5. **A hand-rolled reply or resolve on a review thread, bypassing the one-call helper, is denied (where a helper exists).** **It is not denied when the maintainer's cross-owner grant already covers it.** Splitting a reply and a resolve into two separate hand-run API calls is what let a reply sit unresolved across a push, reading as untriaged. A `resolveReviewThread` mutation or a POST to the review-comment replies endpoint is denied in favor of a single documented helper. This holds where the agent's fleet ships one (this repo's `scripts/pr_review.py reply --resolve`). The one exception is a target the maintainer has already granted this session. The helper itself refuses a cross-owner pull request outright. So the hand-run form is then the documented fallback for that specific repository. That fallback is allowed through the same grant channel requirement 3 reads. A REST reply's own URL is checked against the grant. A `resolveReviewThread` mutation's thread id is opaque, so any active grant is the only signal available there, a residual gap this requirement accepts. A mutation the reading cannot see, such as one in a file or behind `--input`, is allowed.
6. **A mutating git operation run directly against a primary checkout is denied.** "Primary" means not a linked worktree. The decidable test is a comparison, not a filesystem-shape guess. `git rev-parse --path-format=absolute --git-dir --git-common-dir` returns equal paths for a primary checkout and unequal paths for a linked worktree. A `.git`-is-a-directory heuristic is wrong, since a submodule's `.git` is a file yet still a primary working tree that can lose uncommitted work.
- **Denied there:** `reset`, `rebase`, `cherry-pick`, `revert`, `restore`, `add`, `stage`, `commit`, `rm`, `mv`, `apply`, and `am`, whatever their arguments. Also denied are a `push` other than a delete-only one and a `merge` or `pull` without `--ff-only`. So are a `stash` other than `list` or `show`, a forcing `clean`, and a forced `worktree remove`. A `push` that writes a branch does not touch the working tree. It is denied because the only documented fleet workflow pushing a branch from a primary checkout is the in-place commit below.
Expand Down Expand Up @@ -130,7 +130,7 @@ Requirements 1 to 7 and 11 judge a command's text, read the way a simple lexer r
names, a model the hook cannot read. So does a nested session an agent launches
with the allowance set, which is circumvention rather than the mistake this guards.

11. **A blanket stage in a checkout with an `origin` remote is denied, in a primary checkout and a linked worktree alike.** `GOVERNANCE.md` "Git and Commit Rules" requires staging by explicit path. A `git add` naming no file, or naming `.`, `*`, a glob, a pathspec magic, a directory, or a run-time word, is denied. So is `-A`, `--all`, `-u`, or `--update` with no pathspec, and so is `git commit -a` or `--all`. `git stage` reads as `git add`. A `commit` naming a pathspec is judged by the same path test, and a `--pathspec-from-file` is denied since its paths are unread. A repository a `--git-dir` or `GIT_DIR` names is the one whose `origin` is read. A run-time word there, or in a `cd` or `-C` directory, reads as having one. A glob character passes only in a path naming an existing file that no other file matches as a glob. A path ending in `/`, and `.` or `..`, reads as a directory. A stray untracked file, a scratch file or one holding a secret, then never rides into a commit. `-N` and `-p` with named files, and `-v`, are allowed. So are the read-only `git add -n` and `--dry-run`, and `git commit --dry-run`. A repository with no `origin` is a disposable workspace and passes. The path test is the one requirement 6's in-place exemption uses, so "explicit path" has one meaning. The retry names each file.
11. **A blanket stage in a checkout with an `origin` remote is denied, in a primary checkout and a linked worktree alike.** `GOVERNANCE.md` "Git and Commit Rules" requires staging by explicit path. A `git add` naming no file, or naming `.`, `*`, a glob, a pathspec magic, a directory, or a run-time word, is denied. So is `-A`, `--all`, `-u`, or `--update` with no pathspec, and so is `git commit -a` or `--all`. `git stage` reads as `git add`. A `commit` naming a pathspec is judged by the same path test, and a `--pathspec-from-file` is denied since its paths are unread. A repository a `--git-dir` or `GIT_DIR` names is the one whose `origin` is read. A run-time word there, or in a `cd` or `-C` directory, reads as having one. A glob character passes only in a path naming an existing file that no other file matches as a glob. A path ending in `/`, and `.` or `..`, reads as a directory. A stray untracked file, a scratch file or one holding a secret, then never rides into a commit. `-N` and `-p` with named files, and `-v`, are allowed. So are the read-only `git add -n` and `--dry-run`, and `git commit --dry-run`. A repository with no `origin` is a disposable workspace and passes. The path test is the one requirement 6's in-place exemption uses, so "explicit path" has one meaning. A brace expansion is read as its words, so `git add {.,a.txt}` is the sweep. The retry names each file.

## Decision Flow

Expand Down Expand Up @@ -189,7 +189,7 @@ opt-in per clone, visible to anyone reading the repo, and bypassable on purpose.
The hub's own `.husky/pre-push` is the worked example there, refusing a branch push that no
recorded local review pass covers, per [`GOVERNANCE.md`][governance] "Verification Discipline".
The two layers meet at requirement 4. It denies `--no-verify`, a `-c core.hooksPath=`
override, and an include override on a commit or push unconditionally, wherever it reads them. So
override, an include override, and config set through the environment on a commit or push unconditionally, wherever it reads them. So
a Claude Code session meets a committed hook it
cannot wave through with any of them while a human keeps the escape hatch. They do not compose into a
seal, and saying so would be the more comfortable claim rather
Expand Down
Loading
Loading