Skip to content

Codex gets gstack's skill routing hint and destructive-command check (GST-3172) - #4512

Merged
capy-ai[bot] merged 6 commits into
mainfrom
codex-hooks-setup-routing-guard
Nov 19, 2026
Merged

capy-ai[bot] merged 6 commits into
mainfrom
codex-hooks-setup-routing-guard

Conversation

@garrytan

@garrytan garrytan commented Nov 19, 2026 •

Copy link
Copy Markdown
Owner

./setup --host codex now adds gstack's skill-routing hint and destructive-command check to Codex's ~/.codex/hooks.json, next to your own hooks, so Codex users get the same guardrails Claude Code users have.
Codex runs a hook only after you trust it, so nothing fires until you accept gstack's hooks at Codex's startup prompt or in /hooks; gstack-doctor shows whether you have.

What changed
  • Writing Codex's hooks file. bin/gstack-settings-hook has a Codex format (GSTACK_HOOKS_FORMAT=codex). It merges gstack's groups into $CODEX_HOME/hooks.json and keeps every user group value for value and in order (the file is re-indented as 2-space JSON on rewrite). It adds no tag keys, because Codex's schema rejects unknown keys. The result is checked against Codex's strict schema three times: on load, before the write, and on a re-read of the temp file before the rename. It refuses to write when config.toml already declares a gstack hook under [hooks] or doesn't parse. A new read-only trust-status verb reads Codex's trust entries; setup never writes trust.
  • Setup. On Codex 0.170 or newer, setup registers the routing hook (UserPromptSubmit) and the destructive-command check (PreToolUse) under the same off switches as Claude Code (skill_routing, destructive_guard, --no-team). It prints one line saying the hooks wait for trust, and one line recommending codex -c model_reasoning_effort=high (setup writes no reasoning setting). With older or missing Codex it says why and skips.
  • The hooks. hosts/codex/hooks/ holds two small entries that reuse the Claude Code hooks. On Codex a $skill mention counts as an explicit skill choice, and the hint wording names Codex skills.
  • Ask has no Codex equivalent. Codex rejects ask from a PreToolUse hook. In an interactive session the check denies, and the reason tells the model to stop and ask you; you can run the command yourself with !<command>, which skips hooks (confirmed live). Under codex exec it becomes a warning and the command runs. Deleting / or your home folder is denied everywhere.
  • Uninstall and doctor. gstack-uninstall removes gstack's Codex groups. gstack-doctor gets a "codex hooks" row: registered, trusted, untrusted or disabled.
  • Docs. docs/skill-routing-and-contracts.md (new Codex row and Codex section), docs/hosts.md, and the README host table.

Claude Code's hook registrations and hint wording are unchanged, and tests pin both.

Tests
  • test/codex-hooks.test.ts: the Codex format (merge, idempotence, user groups kept, strict schema, config.toml clash, trust-status), routing on Codex, the ask mapping in interactive and exec sessions, and the Claude Code output pin.
  • test/codex-hooks-setup.test.ts: setup's gate, its version floor, uninstall and the doctor row.
  • test/codex-hooks-real-codex.test.ts plus .github/workflows/codex-hooks.yml: installs @openai/[email protected] and checks that the real CLI loads the merged file and runs both the user's hook and gstack's routing hook, and that it skips untrusted hooks and a file with an unknown key. It points Codex at a dead local model endpoint, so it spends nothing.
  • All three are POSIX-only and excluded from the Windows subset by the curation patterns.
Known limits and review notes

Known limits

  • If one of your own hook groups comes after gstack's in the same event, removing gstack's group would shift your hooks to new positions, and Codex keys trust by position. So in that case ./setup's off switch and gstack-uninstall leave hooks.json unchanged and print how to delete gstack's group by hand. Uninstall can therefore leave gstack's group in place.
  • On Windows the Codex runtime folder lacks the Claude hook files the Codex hooks import, so both hooks do nothing there (they fail open). Windows has minimal support, so this is out of scope.
  • No real-Codex test drives the deny path, and the coverage audit found gaps in message and log paths.

Second-model review findings ruled below the blocking bar for this PR

  • setup:3193: the Windows gap above.
  • bin/gstack-settings-hook:423: rewriting hooks.json goes through JavaScript numbers, so an integer above 2^53 in one of your own MCP hook inputs would be rounded. Claude Code's settings.json has been rewritten the same way since before this PR.
  • bin/gstack-settings-hook:383: the shared quoting helper leaves parentheses unquoted, so a CODEX_HOME path containing ( or ) gives hook commands the shell can't run. The same helper serves Claude Code's hooks, and a small fix for both follows this PR.

Other review notes (not blocking)

  • bin/gstack-uninstall:622: when uninstall leaves gstack's Codex group in place, the reason is printed only on stderr, and hooks.json keeps naming the deleted scripts until you remove the group.
  • bin/gstack-settings-hook:430: the Codex schema check also refuses removal and trust-status when a newer Codex adds keys this copy of the schema doesn't know.
  • The destructive-command check is registered with a 10 s timeout, and its inner steps budget 8 s plus 2 s, so a slow machine can run past it.
  • .github/workflows/codex-hooks.yml runs only when the listed paths change; setup, careful/bin/check-careful.sh, hosts/claude/hooks/spawn-bin.ts and the payload fixture aren't listed.
  • Bun's TOML parser could disagree with Codex about an unusual config.toml, and trust-status's error says "refusing to mutate" although it only reads.

Second-model review of the design decisions, ruled below the blocking bar for this PR (all five go into the follow-up that fixes the quoting helper)

  • bin/gstack-settings-hook:268: if you put your own handler inside gstack's group, the refusal message's advice to delete gstack's group would delete your handler too. Setup always gives gstack its own group.
  • bin/gstack-settings-hook:193: gstack's copy of the Codex schema refuses description: null, which Codex accepts (setup then leaves the file alone), and lets a nested null in an MCP hook input through, which Codex already rejects for the whole file.
  • bin/gstack-settings-hook:1076: rollback restores your pre-write backup without re-checking it against the schema.
  • bin/gstack-settings-hook:245: the duplicate check catches a gstack hook in config.toml only when its matcher is literally Bash; under ^Bash$ the check could run twice once both copies are trusted.
  • bin/gstack-settings-hook:1181: when CODEX_HOME and hooks.json are both symlinks, gstack-doctor can report a trusted hook as untrusted.
Documentation

Status: current — the read-only audit found every doc touched by the Codex hooks change accurate, with no corrections needed.

Scope: base ed4086e2 to head d3bd5d6c, 6 commits and 24 selected committed files (nothing staged, unstaged or untracked). I checked authored docs against setup, bin/gstack-settings-hook, bin/gstack-doctor, bin/gstack-uninstall and .github/workflows/codex-hooks.yml.

Documentation health:

  • README.md: current. The Codex host row says destructive commands are blocked once gstack's hooks are trusted.
  • docs/skill-routing-and-contracts.md: current. The host table and the Codex section (trust, schema safety, removal, deny instead of ask) match the code.
  • docs/hosts.md: current. It covers reasoning effort and the hooks.json registration.
  • docs/uninstall.md: current. It covers both automatic and manual Codex hooks removal.
  • docs/skills.md: current. Its safety section still accurately describes the Claude Code session hooks.
  • changelog.d/codex-hooks-setup-routing-guard.md: reviewed only, and consistent with the docs.

Coverage debt: the Codex routing hook and destructive-command check have reference and how-to coverage (docs/skill-routing-and-contracts.md#codex), but no tutorial, and docs/troubleshooting.md has no entry for the new gstack-doctor codex hooks row. That is a common gap, not a critical one. Consider /document-generate.

Diagram drift: none; no architecture diagrams reference the changed surfaces.

Agent notes

Approvals

Approved: yes (record r-7e9e421bc4e2). The full approval record stays private.
Plan: approved (record r-428a55160e56)
Plan check: approved (record r-428a55160e56)

Refs p1/red-team#1

REVIEW_LOOP: passes=1 blocking_found=3 deferred=0 noted=8 fixed=0 scope=frozen open=3 ledgers_read=2 dispatches=5
Gate edits: none detected (6 listed, 1 read; patterns: RH-1,RH-3,RH-4,RH-12,RH-13,RH-14,RH-15,RH-16; unlisted idioms: none)
Ruled note: bin/gstack-settings-hook:268:trail-sol#1 (a-a97a699ff7cf) at d3bd5d6 ruled by Captain GStack Minder (GSTA-36) on the second-family decision-trail read
Ruled note: bin/gstack-settings-hook:193:trail-sol#2 (a-876bb9e741fb) at d3bd5d6 ruled by Captain GStack Minder (GSTA-36) on the second-family decision-trail read
Ruled note: bin/gstack-settings-hook:1076:trail-sol#3 (a-f58527b4c279) at d3bd5d6 ruled by Captain GStack Minder (GSTA-36) on the second-family decision-trail read
Ruled note: bin/gstack-settings-hook:245:trail-sol#4 (a-6ec8e8124aa4) at d3bd5d6 ruled by Captain GStack Minder (GSTA-36) on the second-family decision-trail read
Ruled note: bin/gstack-settings-hook:1181:trail-sol#5 (a-245b2b293d2e) at d3bd5d6 ruled by Captain GStack Minder (GSTA-36) on the second-family decision-trail read
Ruled note: setup:3193:outside-voice#1 at d3bd5d6 ruled by Captain GStack Minder (GSTA-36) at 2026-11-19T10:01:05.937Z: Windows fail-open is out of scope; Windows is minimal tier (approval a-6225f6510dcb)
Ruled note: bin/gstack-settings-hook:423:outside-voice#2 at d3bd5d6 ruled by Captain GStack Minder (GSTA-36) at 2026-11-19T10:01:05.995Z: Precision loss has been on main for Claude settings.json since before this PR and is hypothetical (approval a-7ff0d879c2e0)
Ruled note: bin/gstack-settings-hook:383:outside-voice#3 at d3bd5d6 ruled by Captain GStack Minder (GSTA-36) at 2026-11-19T10:01:06.059Z: gsQuoteCmd parentheses is in the shared helper on main since 11-17 and hits Claude too; its own fix PR for both hosts follows this one (approval a-bb4c0ce9fcea)

{
  "schema_version": 1,
  "pr": 4512,
  "head": "d3bd5d6ce28f5c959b04b77729b3d82011b38a0d",
  "version": "1.101.0.0",
  "base": "main",
  "gate": {
    "test": {
      "pass": 1704,
      "fail": 0,
      "skip": 0
    }
  },
  "ci_carried": [
    {
      "lane": "test",
      "run": 44503040836,
      "attempt": 1,
      "tree": "1a196690b2b0dc95b63c068d99904bd1817605d8"
    }
  ],
  "calls": 30,
  "session_kind": "unattended",
  "run": "ship-4512",
  "head_tree": "1a196690b2b0dc95b63c068d99904bd1817605d8",
  "product_patch_id": "573e4669f6da3712b9187c6b33585edd4df7bacb",
  "gstack_version": "1.101.0.0",
  "review_depth": {
    "depth": "full",
    "class": "gate",
    "runtime_lines": 598,
    "rules": "1afa38a4be3b5eef",
    "base": "f13dbb0d4a3e033cd086eadc8aed2ee1c91ac954",
    "registry": "f13dbb0d4a3e033cd086eadc8aed2ee1c91ac954",
    "gate_scan": {
      "tagged": 1,
      "head": "d3bd5d6ce28f5c959b04b77729b3d82011b38a0d"
    },
    "reasons": [
      "gate-class",
      "risk:security",
      "runtime=598"
    ],
    "risk": [
      "security"
    ],
    "mode": "panel"
  },
  "pregate": "requires-remote cleared @1a196690b2b0 (8 checks, current for d3bd5d6ce28f)",
  "requires_remote": [
    "free-tests.yml/cso-macos-launcher: https://github.com/garrytan/gstack/actions/runs/44503040836/attempts/1",
    "free-tests.yml/macos-named-regressions: https://github.com/garrytan/gstack/actions/runs/44503040836/attempts/1",
    "windows-setup-e2e.yml/windows-setup: https://github.com/garrytan/gstack/actions/runs/44497897765/attempts/1",
    "windows-smoke.yml/windows-smoke: https://github.com/garrytan/gstack/actions/runs/44497897729/attempts/1",
    "pregate.json/remote_gate: remote-gate tree=1a196690b2b0 tests=37927 skipped=104 runs=44503040836/1 profiles=ci-reuse/free-tests heads=d3bd5d6ce28f verified=2026-11-19T10:49:06.886Z"
  ],
  "issues": {
    "fixes": [],
    "refs": [],
    "flakes": []
  },
  "docs": {
    "status": "current",
    "scope": "README.md, docs/, changelog.d/, AGENTS.md, CONTRIBUTING.md (read-only audit, base ed4086e2 to d3bd5d6c)"
  },
  "review_loop": {
    "passes": 1,
    "blocking_found": 3,
    "deferred": 0,
    "noted": 8,
    "fixed": 0,
    "scope": "frozen",
    "rounds": 1,
    "ledgers_read": 2,
    "dispatches": {
      "specialist": 4,
      "red-team": 1
    }
  },
  "review_round_grants": [
    {
      "kind": "fix-check",
      "head": "48209554468a7e84ff82235a0277eea22b88ebe4",
      "pr": 4512,
      "by": "Captain GStack Minder (GSTA-36)",
      "reason": "c9823b3 records the harness pin CI's harness-version guard required; no behavior change",
      "at": "2026-11-19T09:26:10.559Z",
      "approval": "a-2d57bb9a06aa",
      "stop_run": "ship-4512",
      "findings": [
        "ci/harness-pin-c9823b3"
      ]
    }
  ],
  "ruled_notes": [
    {
      "finding": "setup:3193:outside-voice#1",
      "head": "d3bd5d6ce28f5c959b04b77729b3d82011b38a0d",
      "by": "Captain GStack Minder (GSTA-36)",
      "reason": "Windows fail-open is out of scope; Windows is minimal tier",
      "at": "2026-11-19T10:01:05.937Z",
      "approval": "a-6225f6510dcb"
    },
    {
      "finding": "bin/gstack-settings-hook:423:outside-voice#2",
      "head": "d3bd5d6ce28f5c959b04b77729b3d82011b38a0d",
      "by": "Captain GStack Minder (GSTA-36)",
      "reason": "Precision loss has been on main for Claude settings.json since before this PR and is hypothetical",
      "at": "2026-11-19T10:01:05.995Z",
      "approval": "a-7ff0d879c2e0"
    },
    {
      "finding": "bin/gstack-settings-hook:383:outside-voice#3",
      "head": "d3bd5d6ce28f5c959b04b77729b3d82011b38a0d",
      "by": "Captain GStack Minder (GSTA-36)",
      "reason": "gsQuoteCmd parentheses is in the shared helper on main since 11-17 and hits Claude too; its own fix PR for both hosts follows this one",
      "at": "2026-11-19T10:01:06.059Z",
      "approval": "a-bb4c0ce9fcea"
    }
  ],
  "gate_dispositions": [],
  "review_targeted": {
    "classes": [
      "gate"
    ],
    "rules": "23eb808423669ba0",
    "brief_sha": "7f92a0d0a8319c3c0e076fb3b1a4689c45120b2be2c14dfc7d4cb03aafa9d6a5",
    "product_patch_id": "573e4669f6da3712b9187c6b33585edd4df7bacb",
    "status": "done",
    "findings": 0,
    "raised_by": "targeted"
  }
}
{"head":"48209554468a7e84ff82235a0277eea22b88ebe4","run":"ship-4512","mark":"stop","tree":"1ffaac01e7d60db9fd2ba61700997a00edc571aa"}
{"head":"48209554468a7e84ff82235a0277eea22b88ebe4","run":"ship-4512","mark":"grant","grant":"a-2d57bb9a06aa"}
{"head":"d3bd5d6ce28f5c959b04b77729b3d82011b38a0d","run":"ship-4512","mark":"stop","tree":"1a196690b2b0dc95b63c068d99904bd1817605d8"}

Open in Capy

@trunk-io

trunk-io Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

😎 This pull request was merged.

garrytan and others added 2 commits November 19, 2026 07:19
…eck through hooks.json (GST-3172)

Setup on a Codex host merges two gstack hooks into ~/.codex/hooks.json next to the user's own hooks. They stay inactive until the user trusts them in Codex. Uninstall removes them, and gstack-doctor reports whether they are trusted.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@garrytan
garrytan force-pushed the codex-hooks-setup-routing-guard branch from 7728818 to e318100 Compare November 19, 2026 07:21
garrytan and others added 4 commits November 19, 2026 07:40
…at holds its hook helper

From a standard global install, the hooks.json cleanup ran after ~/.claude/skills/gstack was deleted, so its helper was gone and gstack's Codex hook groups stayed behind pointing at missing scripts. The cleanup now runs beside the settings.json sweep, and a test runs uninstall from an installed copy.

Review-Finding: p1/red-team#1 reader=red-team
Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
… how to remove them by hand

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
… change that moves no eval verdict

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
…a symlinked hooks.json reads config.toml from the Codex home

Removing gstack's group from hooks.json would move a user hook that follows it to a new position, and Codex keys trust by position, so codex exec would silently skip it. gstack now leaves the file unchanged and says how to remove its group by hand. config.toml is read from the Codex home even when hooks.json is a link into a dotfiles folder. The docs say that plain ./setup --no-team leaves the Codex hooks alone.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
@capy-ai
capy-ai Bot merged commit 944b41e into main Nov 19, 2026
86 of 87 checks passed
capy-ai Bot added a commit that referenced this pull request Nov 19, 2026
…T-3173) (#4522)

On Codex, gstack's /review can no longer end a session with a required
step skipped: the end-of-session check reads Codex's own session log and
sends the agent back to finish, as it already does on Claude Code.

Why: Codex users got routing and the destructive-command check in #4512,
but not the /review checklist, so a review could stop after the diff
read with no second-model pass.

To use it: run `./setup` again and trust the new hook in Codex
(`/hooks`); turn it off with `GSTACK_SKILL_CONTRACTS=off`.

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Review-Finding: p1/specialist-batched#1 reader=testing
Review-Finding: p1/specialist-batched#2 reader=testing
@garrytan garrytan mentioned this pull request Nov 19, 2026
capy-ai Bot added a commit that referenced this pull request Nov 19, 2026
- `gstack-artifact validate` no longer passes a run.json that gstack-autoplan never wrote. (#4494)
- /ship's changed-number check no longer stops on tests that only share a word with the change (#4478). (#4496)
- On Capy, /ship no longer edits or comments on pull requests as you. (#4518)
- The destructive-command check stops asking about scratch deletes and catches the real damage it used to miss. (#4513)
- The destructive-command check reads commands more carefully, closing gaps found after the last release. (#4525)
- The Codex readiness check and the second-model review now pick the same model for a custom Codex provider (GST-3089). (#4491)
- gstack's Codex hooks work when your Codex folder's path has a `(`, `&` or other shell character in it. (#4528)
- Uninstalling gstack keeps your own Codex hooks trusted. (#4528)
- Codex hook setup matches Codex more closely. (#4528)
- On Windows, setup copies the Claude Code hook code that gstack's Codex hooks import (#4528)
- /review's checklist on Codex reads shell commands more carefully. (#4528)
- On Codex, gstack now suggests the right skill for a prompt and stops destructive commands before they run. (#4512)
- On Codex, /review is now held once when it tries to finish without its adversarial pass or its report, as it already is on Claude Code. (#4522)
- On Codex, gstack's skill suggestion now names the skill the way Codex lists it. (#4523)
- On Codex, gstack's suggested prompts and docs now name skills the way Codex lists them. (#4524)
- /review on Codex with gpt-6.1-sol is no longer held back for a second-model pass it already ran. (#4526)
- On Codex, office-hours, plan-design-review and gstack-upgrade work again when you name them. (#4510)
- gstack knows when Codex is running unattended. (#4510)
- Codex reviewers start with a clean context. (#4510)
- Docs no longer say Codex has no hook support. (#4510)
- A command whose output was cut off no longer counts as a finished read. (#4492)
- A folder marked as published data can no longer hide source code or agent files from /ship's review. (#4516)
- Correction to the on-by-default helper hooks entry: the hook still routes only to /review, /qa and /verify, so skills you've installed yourself aren't suggested yet. With gstack's skills it routes 14 of 60 real bug reports (was 17), and long prompts are no longer skipped. (#4505)
- /sync-gbrain's read check now works when the first page in your code source is over 64 KB. (#4497)
- Free-suite CI no longer fails before any test runs when Ubuntu's package mirror is slow. (#4530)
- Syncing a second repo no longer makes the first one ask for /sync-gbrain again. (#4532)
- gstack's helper hooks are now on by default in Claude Code, OpenClaw and Hermes, and the prompt-routing hook fires on real bug reports. (#4503)
- `gstack-pregate clear --receipt` accepts a remote gate run from before a merged release when the release only regenerated a declared release output. (#4483)
- The second-model review now keeps the reviewer's own result, and reports a used-up budget as a budget stop. (#4515)
- When the reviewer wrote its review to the result file it was asked for, Codex then replaced that file with its short closing message ("Done, I wrote the review"), so the review was thrown away and reported as missing its markers. (#4515)
- When the provider refuses the call with HTTP 402 Payment Required (usually a metering proxy that hit its allowance, or an account out of credits or quota), gstack used to record only "exit 1". (#4515)
- The pre-commit /verify check now fails a check that times out, and its checks share one time budget (GST-3201). (#4527)
- /ship's review collector no longer reads a reviewer's own scope list or list of passed checks as findings (GST-3201). (#4527)
- Merge-queue stack tests fail when git cannot list a PR's added test files (GST-3201). (#4527)
- /ship can now review results PRs that publish raw session data. (#4511)
- /ship's review pass works when the checkout you ship isn't the project's default checkout. (#4507)
- A second review round no longer reports done when nothing was reviewed. (#4520)
- The prompt-routing hook now suggests skills you install yourself, and no longer sends ordinary bug reports to /qa (GST-3123). (#4506)
- gstack's script runner and merge-queue checks now also refuse cut-off output. (#4502)
- A failed second-model review reports the cause that actually stopped it, and the runner never deletes its own prompt. (#4519)
- `gstack-ship-queue ready` now fills in the trial merges and the second-model trail read instead of printing lines to fill. (#4529)
- Five small ship-tool fixes. (#4529)
- A ruling the owner gives while a `/ship` run is open can be relayed. (#4529)
- /ship no longer kills a working test run as stalled when the test command starts its workers in their own session. (#4533)
- /ship no longer stops a review because the state-machine reader started its reply the way its instructions say. (#4504)
- When Claude Code runs /verify right before a commit, it now gets a quick check instead of the full fix loop (GST-3150). (#4508)

Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant