[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6C37BYQ0VTGRH5YRF79TJ1W":3,"skill-same:01M6C37BYQ0VTGRH5YRF79TJ1W":92},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":48,"linkOnly":49,"markdownContent":50,"markdownBody":51,"frontMatter":52,"refName":65,"commitSha":66,"skillDirectory":67,"forksCount":68,"repositoryHtmlUrl":69,"repositoryHomepageUrl":6,"ownerHtmlUrl":70,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":71,"install":72,"resources":85},"01M6C37BYQ0VTGRH5YRF79TJ1W","cross-cli-hook-integration",null,"Ship a CLI lifecycle hook (Stop, PreToolUse, PostToolUse, SessionStart,\nUserPromptSubmit) that runs correctly across Claude Code, Codex, Cursor\nAgent, Antigravity (Gemini CLI's antigravity branding), and agy. The four\nCLIs disagree on (a) where they discover hook scripts, (b) what payload\nshape they send on stdin, (c) which JSON fields they honor in the\nresponse, and (d) which event names they emit. Vendor docs are load-bearing\nfor shape but silently omit the discovery indirection; only running real\nCLI sessions reveals the ground truth. Verified 2026-07-30 against Claude\nv2.1.220, Codex 0.144.5, Cursor 3.11.13, Antigravity, agy 1.1.8.","jleechanorg\u002Fjleechan-skills","jleechanorg","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F221404966?v=4","01M6C1VJ99XG950X1DWPEBCBGX","01M6C1VJDK5YVDNT3362RT5WSB",6,"MIT","https:\u002F\u002Fgithub.com\u002Fjleechanorg\u002Fjleechan-skills\u002Fblob\u002Fmain\u002Fhermes\u002Fskills\u002Fcross-cli-hook-integration\u002FSKILL.md",[],[18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,46,47],"hook","integration","cross cli hook integration","cli","cursor","2026","send","inline","verified","which","port","scripts","discover","across","payload","only","vendor","edit","write","read","json","Bash","discovery","lifecycle","code","sessions","gemini cli","codex","antigravity","gemini","2026-11-10 10:12:30",false,"---\nname: cross-cli-hook-integration\nversion: 1.0.0\ndescription: |\n  Ship a CLI lifecycle hook (Stop, PreToolUse, PostToolUse, SessionStart,\n  UserPromptSubmit) that runs correctly across Claude Code, Codex, Cursor\n  Agent, Antigravity (Gemini CLI's antigravity branding), and agy. The four\n  CLIs disagree on (a) where they discover hook scripts, (b) what payload\n  shape they send on stdin, (c) which JSON fields they honor in the\n  response, and (d) which event names they emit. Vendor docs are load-bearing\n  for shape but silently omit the discovery indirection; only running real\n  CLI sessions reveals the ground truth. Verified 2026-07-30 against Claude\n  v2.1.220, Codex 0.144.5, Cursor 3.11.13, Antigravity, agy 1.1.8.\ntriggers:\n  - \"cross cli hook\"\n  - \"hook for claude codex cursor antigravity agy\"\n  - \"port hook across CLIs\"\n  - \"normalize hook payload\"\n  - \"stop hook all CLIs\"\nallowed-tools:\n  - Read\n  - Write\n  - Edit\n  - Bash\ncontext: inline\n---\n\n# Cross-CLI Hook Integration\n\nA class-level recipe for any hook that must run on more than one of:\n**Claude Code \u002F Codex \u002F Cursor \u002F Antigravity \u002F agy**. Covers discovery\nindirection (where each CLI looks for hook files), payload shape (what\neach CLI writes to stdin), response schema (what JSON each CLI honors),\nand the post-deploy verification protocol.\n\nThe hard-won lesson: **vendor docs are necessary but not sufficient.**\nEvery cross-CLI hook bug class in this repo (2026-07-17 Codex apply_patch\ncase-sensitivity, 2026-07-30 Claude\u002FCodex Stop schema divergence) had a\nfixture-tested unit suite that passed against fixtures the agent wrote\nfrom the docs. The bugs only surfaced when a real CLI session drove the\nhook with a real payload. Treat the live-payload capture protocol in §4\nas mandatory, not optional.\n\n## 1. Discovery indirection — where each CLI looks for hooks\n\nThis is the #1 source of \"I shipped a hook but nothing fires\" bugs.\nVendor docs list a flat `~\u002F.claude\u002Fsettings.json` \u002F `~\u002F.codex\u002Fhooks.json`\npath but omit the *indirection* layers (wrapper scripts, fallback\nchains, dispatch routers). Get this wrong and the hook silently never\nruns.\n\n### 1.1 Claude Code v2.1.220+\n\n`~\u002F.claude\u002Fsettings.json` → `hooks.\u003CEventName>[].hooks[]` is the\nauthoritative location. Events: `PreToolUse`, `PostToolUse`,\n`UserPromptSubmit`, `Stop`, `SessionStart`, `SubagentStart`,\n`SubagentStop`, `PreCompact`, `PostCompact`, `Notification`.\n\nThere is **no `stop-hook-dispatch.sh` indirection** — whatever you put\nin the `Stop` array fires directly. Claude runs every hook in the array\nin order, with the JSON response from one hook becoming the input to the\nnext (chain semantics). If you want the cross-cli hook to always run,\nappend it as the FIRST entry in `Stop`.\n\nProject-local hooks live in `\u003Crepo>\u002F.claude\u002Fsettings.json` and are\nhonored for Claude sessions launched from inside that repo.\n\n### 1.2 Codex 0.144.5+ (verified 2026-07-30)\n\nCodex has TWO indirection layers most agents miss:\n\n**Layer A — `~\u002F.codex\u002Fhooks.json` `Stop` array is NOT executed\ndirectly.** It dispatches to `~\u002F.codex\u002Fstop-hook-dispatch.sh` (verified\non this machine, 49 lines). The dispatch script:\n\n1. reads the cwd from the payload,\n2. checks for `\u003Ccwd>\u002F.codex\u002Fhooks.json` Stop config,\n3. **sets `local_stop_configured=true` to suppress the legacy fallback\n   — but does NOT actually run the project's Stop hooks.**\n\nSo your project-local `codex_hooks.json` (or even `.codex\u002Fhooks.json`)\nStop entries will be observed (the dispatch sets a flag) but never\nexecuted. The actual hook that fires is whatever\n`stop-hook-dispatch.sh` decides to invoke.\n\n**Layer B — `codex_hooks.json` at the repo root (no dot prefix) is\nNEVER read.** Codex only reads `\u003Ccwd>\u002F.codex\u002Fhooks.json` and\n`~\u002F.codex\u002Fhooks.json`. Files named `codex_hooks.json` (which is the\nhistorical name in `jleechanorg\u002Fclaude-commands`) are decoration.\n\n**To make a new hook actually run in Codex:**\n\n```bash\n# 1. Drop the hook script in a discoverable location.\ncp .codex\u002Fhooks\u002Fcross_cli_status.py ~\u002F.codex\u002Fhooks\u002Fcross_cli_status.py\n\n# 2. Replace the dispatch script with one that runs your hook.\ncp .codex\u002Fstop-hook-dispatch.sh ~\u002F.codex\u002Fstop-hook-dispatch.sh\n\n# 3. The dispatch script must explicitly invoke your hook; don't rely\n#    on \u003Crepo>\u002F.codex\u002Fhooks.json being read.\n```\n\nThe new dispatch script's shape (verified pattern, 2026-07-30):\n\n```bash\n#!\u002Fusr\u002Fbin\u002Fenv bash\nset -euo pipefail\ninput=\"$(cat)\"\n\n# Primary: cross-CLI status hook (always run)\nfor cand in \\\n  \"${cwd:-.}\u002F.claude\u002Fhooks\u002Fcross_cli_status.py\" \\\n  \"${cwd:-.}\u002F.codex\u002Fhooks\u002Fcross_cli_status.py\" \\\n  \"$HOME\u002F.claude\u002Fhooks\u002Fcross_cli_status.py\" \\\n  \"$HOME\u002F.codex\u002Fhooks\u002Fcross_cli_status.py\"; do\n  if [ -x \"$cand\" ]; then\n    HERMES_HOOK_CLI=codex HERMES_HOOK_EVENT=Stop \\\n      printf '%s' \"$input\" | python3 \"$cand\" --no-header || true\n    break\n  fi\ndone\n\n# Secondary: mem0 save (preserve legacy behavior)\n# Tertiary: legacy stop-git-header-json.sh fallback (only if cross-cli absent)\necho '{\"continue\":true}'\n```\n\n### 1.3 Cursor 3.11.13+ (cursor agent)\n\n`~\u002F.cursor\u002Fhooks.json` (or `\u003Crepo>\u002F.cursor\u002Fhooks.json`). Events: `stop`,\n`beforeSubmitPrompt`, `beforeReadFile`, `afterFileEdit`,\n`beforeMCPExecution`, `afterMCPExecution`, `preCompact`. Schema is\nunstable; pin to the exact Cursor version in your fixtures.\n\n### 1.4 Antigravity (Gemini CLI variant)\n\n`~\u002F.gemini\u002Fhooks.toml` (TOML, not JSON) for `BeforeTool` \u002F `BeforeModel`\n\u002F `AfterModel` \u002F `AfterAgent`. The Gemini event names are lowercase;\nClaude uses `PreToolUse` \u002F `PostToolUse`. **There is no documented\n\"Stop\" event in Antigravity** — the closest analogue is `AfterAgent`,\nwhich fires once per turn.\n\n### 1.5 agy 1.1.8+\n\nagy wraps an OpenAI-compatible envelope around Claude\u002FCodex payloads.\nIt does not have its own hook system — install the cross-cli hook in\n`~\u002F.claude\u002Fhooks\u002F` (Claude's location) and agy will fire it. Mark the\nrecord with `HERMES_HOOK_CLI=agy` so the extractor picks the right\nshape.\n\n## 2. Payload shape — what each CLI writes to stdin\n\nVerified 2026-07-30 against real `claude --print` and `codex exec`\nsessions. See `references\u002Flive-payload-capture-2026-07-30.md` for the\nraw transcript + the schema registry.\n\n### 2.1 Claude v2.1.220 `Stop` payload\n\n```json\n{\n  \"cwd\": \"\u002Fprivate\u002Ftmp\u002Fcc-hooks-ratelimit\",\n  \"session_id\": \"c726962e-3185-4681-aec2-313689a33360\",\n  \"transcript_path\": \"...transcript.jsonl\",\n  \"prompt_id\": \"550e8400-...\",\n  \"last_assistant_message\": \"ping\",\n  \"stop_hook_active\": false,\n  \"session_crons\": [],\n  \"effort\": {\"level\": \"medium\"},\n  \"background_tasks\": [],\n  \"permission_mode\": \"bypassPermissions\",\n  \"hook_event_name\": \"Stop\"\n}\n```\n\n**Notable:** the Stop payload does **NOT** carry `model`,\n`context_window`, or `cost` — those appear only in the **statusline**\npayload, which is a different code path. Hooks that need those fields\nmust subscribe to the statusline, not Stop.\n\n### 2.2 Codex 0.144.5 `Stop` payload\n\n```json\n{\n  \"cwd\": \"\u002Fprivate\u002Ftmp\u002Fcc-hooks-ratelimit\",\n  \"hook_event_name\": \"stop\",                       \u002F\u002F ← lowercase\n  \"last_assistant_message\": \"pong\",\n  \"model\": \"gpt-6-sol\",                            \u002F\u002F ← top-level STRING\n  \"permission_mode\": \"bypassPermissions\",\n  \"session_id\": \"019fb560-...\",\n  \"stop_hook_active\": false,\n  \"transcript_path\": \"...transcript.jsonl\",\n  \"turn_id\": \"019fb560-...\"\n}\n```\n\n**Notable:** Codex's Stop payload also lacks `usage` (tokens + cost).\nThe \"tokens used N\" line in Codex's CLI output is rendered from a\nseparate, non-hook channel. The `model` field is a top-level STRING\n(not a dict) in Stop, contrasting with the `model.{id,display_name}`\ndict in the statusline.\n\n### 2.3 The casing disambiguator\n\nBoth CLIs share `stop_hook_active`, `session_id`, and\n`transcript_path`. The reliable disambiguator is the *casing* of\n`hook_event_name`:\n\n| CLI | `hook_event_name` value |\n|---|---|\n| Claude | `\"Stop\"` (capital S) |\n| Codex | `\"stop\"` (lowercase) |\n| Cursor | event name not in payload (separate field) |\n| Antigravity | `\"AfterAgent\"` (CamelCase) |\n\nAdd a fallback: Claude also publishes `session_crons` and `effort`\nthat Codex never does. So the detector reads:\n\n```python\nif \"stop_hook_active\" in payload and (\n    payload.get(\"hook_event_name\") == \"Stop\"\n    or \"session_crons\" in payload\n    or \"effort\" in payload\n):\n    return \"claude\"\n```\n\n## 3. Response schema — what JSON each CLI honors\n\n### 3.1 Claude `Stop`\n\n- `continue: false` + `stopReason: \"...\"` blocks the turn and surfaces\n  the reason.\n- `additionalContext: \"...\"` is appended to the next prompt.\n- Any other fields are ignored.\n\n### 3.2 Codex `Stop`\n\n- `{ \"continue\": true }` is the **only** supported response shape.\n- `{ \"continue\": false, \"stopReason\": \"...\" }` is parsed but **not\n  supported** — Codex marks the hook as failed and continues anyway.\n  Verified on learn.chatgpt.com\u002Fdocs\u002Fhooks.md, 2026-07-17.\n- Always exit 0 with `{ \"continue\": true }` on success. Exit non-zero\n  is treated as a failure; the tool \u002F turn continues.\n\n### 3.3 Cursor `stop`\n\n- `StopHookOutput = { followup_message?: string }`.\n- Empty `{}` is treated as \"no followup\"; the agent stays stopped.\n- Returning a `followup_message` re-prompts the agent with that text\n  appended to its context.\n\n### 3.4 Antigravity `AfterAgent`\n\n- `decision: \"allow\" | \"deny\" | \"block\"` controls the next turn.\n- `reason: \"...\"` is surfaced to the UI when blocked.\n- There is no documented \"followup_message\" or \"additionalContext\"\n  field; the only meaningful output is the decision.\n\n## 4. The live-payload capture protocol (mandatory)\n\n**Rule: never trust fixture tests against docs alone. Always run real\nCLI sessions before the \u002Fer PASS verdict.**\n\nThree concrete steps:\n\n### 4.1 Capture the actual payload\n\nFor each CLI you support:\n\n```bash\n# Claude\ntimeout 60 claude --print --dangerously-skip-permissions \\\n  'Reply with the single word: ping' >\u002Fdev\u002Fnull\njq '.' \"$HOME\u002F.claude\u002Fvar\u002Fcross_cli_status\u002Flast.json\"\n\n# Codex\ntimeout 60 codex exec --dangerously-bypass-approvals-and-sandbox \\\n  'Reply with the single word: pong' >\u002Fdev\u002Fnull\njq '.' \"$HOME\u002F.claude\u002Fvar\u002Fcross_cli_status\u002Flast.json\"\n```\n\nIf the JSON file is missing or empty, the hook did not fire — go back\nto §1 and re-verify discovery indirection before debugging anything\nelse.\n\n### 4.2 Bake the captured payloads into unit-test fixtures\n\nThe fixtures in `tests\u002Ftest_cross_cli_status.py::CLAUDE_LIVE_PAYLOAD`\nand `tests\u002Ftest_cross_cli_status.py::CODEX_LIVE_PAYLOAD` are the\n**regression-test ground truth** — they assert \"this is what the hook\nactually receives from a real CLI session.\" If a future vendor update\nchanges the payload shape, the unit tests fail FIRST and the agent\nupdates both the extractor and the fixture in lockstep.\n\n### 4.3 Add a regression test for every schema drift you find\n\nEvery bug class found in §3 (Codex `continue:false` ignored, Claude\nStop missing `model`\u002F`context_window`, Cursor no `rate_limit_pct`\nfield, Antigravity no public Stop event) is now a regression test:\n\n```python\ndef test_claude_stop_payload_lacks_model(self) -> None:\n    \"\"\"Claude v2.1.220 Stop payload does NOT carry `model` or\n    `context_window` (those only appear in the statusline payload).\"\"\"\n    rec = parse(json.dumps(CLAUDE_LIVE_PAYLOAD))\n    self.assertIsNone(rec[\"model\"])\n    self.assertIsNone(rec[\"context_pct\"])\n\ndef test_codex_stop_payload_model_is_string(self) -> None:\n    \"\"\"Codex 0.144.5 Stop payload has `model` as a top-level STRING,\n    not a dict.\"\"\"\n    rec = parse(json.dumps(CODEX_LIVE_PAYLOAD))\n    self.assertIsInstance(rec[\"model\"], str)\n```\n\n## 5. Recipe — shipping a new cross-CLI hook\n\n1. **Pick the event** — Stop is the lowest-risk (purely informational,\n   never blocks the turn). PreToolUse is the highest-stakes (controls\n   tool execution; needs the full response-schema discipline in §3).\n\n2. **Audit the existing hook** — read the current `codex_hooks\u002F*.sh`\n   (or equivalent) to find which fields are read, which are silently\n   dropped, and which assumptions break under a real payload.\n\n3. **Write the cross-CLI hook** as a single Python module that:\n   - reads JSON from stdin (no other CLI),\n   - detects the CLI from `HERMES_HOOK_CLI` env + payload shape\n     (per §2.3),\n   - normalizes fields into a single schema,\n   - is fail-soft by default (writes an `unknown_cli` record rather\n     than blocking the turn),\n   - emits the **lowest-common-denominator response** — for Stop,\n     that's `{ \"continue\": true }` (Codex's only supported shape).\n\n4. **Wire it into Claude** — add to `~\u002F.claude\u002Fsettings.json` `Stop`\n   array as the first entry. Copy the script to `~\u002F.claude\u002Fhooks\u002F`\n   (or `\u003Crepo>\u002F.claude\u002Fhooks\u002F` for project-local).\n\n5. **Wire it into Codex** — replace `~\u002F.codex\u002Fstop-hook-dispatch.sh`\n   with one that explicitly invokes your hook (per §1.2). Do NOT\n   rely on `\u003Crepo>\u002Fcodex_hooks.json` or even `\u003Crepo>\u002F.codex\u002Fhooks.json`\n   Stop entries being executed.\n\n6. **Wire it into Cursor + Antigravity + agy** — see §1.3-1.5.\n\n7. **Run live capture** — §4.1.\n\n8. **Bake fixtures + regression tests** — §4.2 + §4.3.\n\n9. **Document the schema drift** — append to the SKILL.md's\n   `references\u002Flive-payload-capture-\u003Cdate>.md` so future agents know\n   which fields are documented-but-absent in each CLI's payload.\n\n10. **Verify in `\u002Fer` + `\u002Fadvice`** — load `advice` skill; use the\n    cross-CLI schema verification recipe (now codified in\n    `references\u002Fcross-cli-hook-schema-verification.md` of the advice\n    skill). The 3-reviewer fan-out catches: schema-deviation bugs the\n    unit tests miss (Reviewer B), implementation bugs the docs didn't\n    cover (Reviewer A), bypass \u002F loop-storm edge cases (Reviewer C).\n\n## 6. Known limitations (don't promise more than the hooks deliver)\n\n| Limitation | Why | Mitigation |\n|---|---|---|\n| Claude v2.1.220 Stop has no `model` \u002F `context_window` \u002F `cost` | Those are statusline-only | Subscribe to the statusline event for those fields; record `null` in the Stop record |\n| Codex 0.144.5 Stop has no `usage` (tokens\u002Fcost) | Codex renders \"tokens used\" outside the hook channel | Parse the Codex CLI stdout separately if you need tokens\u002Fcost; don't expect them in the hook payload |\n| Cursor `stop` exposes no rate-limit % fields | Cursor app surfaces RL% in the UI badge, not the hook payload | Heuristic: `status=\"error\" + loop_count >= 4` → `rate_limit_pct=100, window=\"loop_storm\"` (signals a Cursor loop storm) |\n| Antigravity `AfterAgent` schema is undocumented | Gemini CLI variant has no published Stop payload | Surface whatever Gemini-shape fields are present; `decision` is the only reliable signal |\n| Codex's `unified_exec` skips PreToolUse | Codex 0.144+ has a second shell-call path that bypasses the hook chain (verified 2026-07-17) | Hook is a guardrail not a boundary; pair with sandbox + approval policy + audit log |\n\n## 7. References\n\n- Companion skill: `~\u002F.claude\u002Fskills\u002Fcross-cli-status-hook\u002FSKILL.md` —\n  the worked example: a single Python Stop hook that handles all five\n  CLIs, with 20 unit tests + a live-tmux integration suite.\n- Cross-reference: `~\u002F.hermes\u002Fskills\u002Fadvice\u002FSKILL.md` →\n  \"Cross-CLI hook schema verification recipe (added 2026-07-15)\" —\n  the `\u002Fadvice` recipe for verifying vendor-docs claims before\n  shipping a cross-CLI hook.\n- Cross-reference: `~\u002F.hermes\u002Fskills\u002Fcodex-path-deletion-guard\u002FSKILL.md`\n  → \"Pitfall #0\" — Codex 0.144+ has a `unified_exec` shell path that\n  skips PreToolUse hooks entirely. Verified regression on 2026-07-17.\n","# Cross-CLI Hook Integration\n\nA class-level recipe for any hook that must run on more than one of:\n**Claude Code \u002F Codex \u002F Cursor \u002F Antigravity \u002F agy**. Covers discovery\nindirection (where each CLI looks for hook files), payload shape (what\neach CLI writes to stdin), response schema (what JSON each CLI honors),\nand the post-deploy verification protocol.\n\nThe hard-won lesson: **vendor docs are necessary but not sufficient.**\nEvery cross-CLI hook bug class in this repo (2026-07-17 Codex apply_patch\ncase-sensitivity, 2026-07-30 Claude\u002FCodex Stop schema divergence) had a\nfixture-tested unit suite that passed against fixtures the agent wrote\nfrom the docs. The bugs only surfaced when a real CLI session drove the\nhook with a real payload. Treat the live-payload capture protocol in §4\nas mandatory, not optional.\n\n## 1. Discovery indirection — where each CLI looks for hooks\n\nThis is the #1 source of \"I shipped a hook but nothing fires\" bugs.\nVendor docs list a flat `~\u002F.claude\u002Fsettings.json` \u002F `~\u002F.codex\u002Fhooks.json`\npath but omit the *indirection* layers (wrapper scripts, fallback\nchains, dispatch routers). Get this wrong and the hook silently never\nruns.\n\n### 1.1 Claude Code v2.1.220+\n\n`~\u002F.claude\u002Fsettings.json` → `hooks.\u003CEventName>[].hooks[]` is the\nauthoritative location. Events: `PreToolUse`, `PostToolUse`,\n`UserPromptSubmit`, `Stop`, `SessionStart`, `SubagentStart`,\n`SubagentStop`, `PreCompact`, `PostCompact`, `Notification`.\n\nThere is **no `stop-hook-dispatch.sh` indirection** — whatever you put\nin the `Stop` array fires directly. Claude runs every hook in the array\nin order, with the JSON response from one hook becoming the input to the\nnext (chain semantics). If you want the cross-cli hook to always run,\nappend it as the FIRST entry in `Stop`.\n\nProject-local hooks live in `\u003Crepo>\u002F.claude\u002Fsettings.json` and are\nhonored for Claude sessions launched from inside that repo.\n\n### 1.2 Codex 0.144.5+ (verified 2026-07-30)\n\nCodex has TWO indirection layers most agents miss:\n\n**Layer A — `~\u002F.codex\u002Fhooks.json` `Stop` array is NOT executed\ndirectly.** It dispatches to `~\u002F.codex\u002Fstop-hook-dispatch.sh` (verified\non this machine, 49 lines). The dispatch script:\n\n1. reads the cwd from the payload,\n2. checks for `\u003Ccwd>\u002F.codex\u002Fhooks.json` Stop config,\n3. **sets `local_stop_configured=true` to suppress the legacy fallback\n   — but does NOT actually run the project's Stop hooks.**\n\nSo your project-local `codex_hooks.json` (or even `.codex\u002Fhooks.json`)\nStop entries will be observed (the dispatch sets a flag) but never\nexecuted. The actual hook that fires is whatever\n`stop-hook-dispatch.sh` decides to invoke.\n\n**Layer B — `codex_hooks.json` at the repo root (no dot prefix) is\nNEVER read.** Codex only reads `\u003Ccwd>\u002F.codex\u002Fhooks.json` and\n`~\u002F.codex\u002Fhooks.json`. Files named `codex_hooks.json` (which is the\nhistorical name in `jleechanorg\u002Fclaude-commands`) are decoration.\n\n**To make a new hook actually run in Codex:**\n\n```bash\n# 1. Drop the hook script in a discoverable location.\ncp .codex\u002Fhooks\u002Fcross_cli_status.py ~\u002F.codex\u002Fhooks\u002Fcross_cli_status.py\n\n# 2. Replace the dispatch script with one that runs your hook.\ncp .codex\u002Fstop-hook-dispatch.sh ~\u002F.codex\u002Fstop-hook-dispatch.sh\n\n# 3. The dispatch script must explicitly invoke your hook; don't rely\n#    on \u003Crepo>\u002F.codex\u002Fhooks.json being read.\n```\n\nThe new dispatch script's shape (verified pattern, 2026-07-30):\n\n```bash\n#!\u002Fusr\u002Fbin\u002Fenv bash\nset -euo pipefail\ninput=\"$(cat)\"\n\n# Primary: cross-CLI status hook (always run)\nfor cand in \\\n  \"${cwd:-.}\u002F.claude\u002Fhooks\u002Fcross_cli_status.py\" \\\n  \"${cwd:-.}\u002F.codex\u002Fhooks\u002Fcross_cli_status.py\" \\\n  \"$HOME\u002F.claude\u002Fhooks\u002Fcross_cli_status.py\" \\\n  \"$HOME\u002F.codex\u002Fhooks\u002Fcross_cli_status.py\"; do\n  if [ -x \"$cand\" ]; then\n    HERMES_HOOK_CLI=codex HERMES_HOOK_EVENT=Stop \\\n      printf '%s' \"$input\" | python3 \"$cand\" --no-header || true\n    break\n  fi\ndone\n\n# Secondary: mem0 save (preserve legacy behavior)\n# Tertiary: legacy stop-git-header-json.sh fallback (only if cross-cli absent)\necho '{\"continue\":true}'\n```\n\n### 1.3 Cursor 3.11.13+ (cursor agent)\n\n`~\u002F.cursor\u002Fhooks.json` (or `\u003Crepo>\u002F.cursor\u002Fhooks.json`). Events: `stop`,\n`beforeSubmitPrompt`, `beforeReadFile`, `afterFileEdit`,\n`beforeMCPExecution`, `afterMCPExecution`, `preCompact`. Schema is\nunstable; pin to the exact Cursor version in your fixtures.\n\n### 1.4 Antigravity (Gemini CLI variant)\n\n`~\u002F.gemini\u002Fhooks.toml` (TOML, not JSON) for `BeforeTool` \u002F `BeforeModel`\n\u002F `AfterModel` \u002F `AfterAgent`. The Gemini event names are lowercase;\nClaude uses `PreToolUse` \u002F `PostToolUse`. **There is no documented\n\"Stop\" event in Antigravity** — the closest analogue is `AfterAgent`,\nwhich fires once per turn.\n\n### 1.5 agy 1.1.8+\n\nagy wraps an OpenAI-compatible envelope around Claude\u002FCodex payloads.\nIt does not have its own hook system — install the cross-cli hook in\n`~\u002F.claude\u002Fhooks\u002F` (Claude's location) and agy will fire it. Mark the\nrecord with `HERMES_HOOK_CLI=agy` so the extractor picks the right\nshape.\n\n## 2. Payload shape — what each CLI writes to stdin\n\nVerified 2026-07-30 against real `claude --print` and `codex exec`\nsessions. See `references\u002Flive-payload-capture-2026-07-30.md` for the\nraw transcript + the schema registry.\n\n### 2.1 Claude v2.1.220 `Stop` payload\n\n```json\n{\n  \"cwd\": \"\u002Fprivate\u002Ftmp\u002Fcc-hooks-ratelimit\",\n  \"session_id\": \"c726962e-3185-4681-aec2-313689a33360\",\n  \"transcript_path\": \"...transcript.jsonl\",\n  \"prompt_id\": \"550e8400-...\",\n  \"last_assistant_message\": \"ping\",\n  \"stop_hook_active\": false,\n  \"session_crons\": [],\n  \"effort\": {\"level\": \"medium\"},\n  \"background_tasks\": [],\n  \"permission_mode\": \"bypassPermissions\",\n  \"hook_event_name\": \"Stop\"\n}\n```\n\n**Notable:** the Stop payload does **NOT** carry `model`,\n`context_window`, or `cost` — those appear only in the **statusline**\npayload, which is a different code path. Hooks that need those fields\nmust subscribe to the statusline, not Stop.\n\n### 2.2 Codex 0.144.5 `Stop` payload\n\n```json\n{\n  \"cwd\": \"\u002Fprivate\u002Ftmp\u002Fcc-hooks-ratelimit\",\n  \"hook_event_name\": \"stop\",                       \u002F\u002F ← lowercase\n  \"last_assistant_message\": \"pong\",\n  \"model\": \"gpt-6-sol\",                            \u002F\u002F ← top-level STRING\n  \"permission_mode\": \"bypassPermissions\",\n  \"session_id\": \"019fb560-...\",\n  \"stop_hook_active\": false,\n  \"transcript_path\": \"...transcript.jsonl\",\n  \"turn_id\": \"019fb560-...\"\n}\n```\n\n**Notable:** Codex's Stop payload also lacks `usage` (tokens + cost).\nThe \"tokens used N\" line in Codex's CLI output is rendered from a\nseparate, non-hook channel. The `model` field is a top-level STRING\n(not a dict) in Stop, contrasting with the `model.{id,display_name}`\ndict in the statusline.\n\n### 2.3 The casing disambiguator\n\nBoth CLIs share `stop_hook_active`, `session_id`, and\n`transcript_path`. The reliable disambiguator is the *casing* of\n`hook_event_name`:\n\n| CLI | `hook_event_name` value |\n|---|---|\n| Claude | `\"Stop\"` (capital S) |\n| Codex | `\"stop\"` (lowercase) |\n| Cursor | event name not in payload (separate field) |\n| Antigravity | `\"AfterAgent\"` (CamelCase) |\n\nAdd a fallback: Claude also publishes `session_crons` and `effort`\nthat Codex never does. So the detector reads:\n\n```python\nif \"stop_hook_active\" in payload and (\n    payload.get(\"hook_event_name\") == \"Stop\"\n    or \"session_crons\" in payload\n    or \"effort\" in payload\n):\n    return \"claude\"\n```\n\n## 3. Response schema — what JSON each CLI honors\n\n### 3.1 Claude `Stop`\n\n- `continue: false` + `stopReason: \"...\"` blocks the turn and surfaces\n  the reason.\n- `additionalContext: \"...\"` is appended to the next prompt.\n- Any other fields are ignored.\n\n### 3.2 Codex `Stop`\n\n- `{ \"continue\": true }` is the **only** supported response shape.\n- `{ \"continue\": false, \"stopReason\": \"...\" }` is parsed but **not\n  supported** — Codex marks the hook as failed and continues anyway.\n  Verified on learn.chatgpt.com\u002Fdocs\u002Fhooks.md, 2026-07-17.\n- Always exit 0 with `{ \"continue\": true }` on success. Exit non-zero\n  is treated as a failure; the tool \u002F turn continues.\n\n### 3.3 Cursor `stop`\n\n- `StopHookOutput = { followup_message?: string }`.\n- Empty `{}` is treated as \"no followup\"; the agent stays stopped.\n- Returning a `followup_message` re-prompts the agent with that text\n  appended to its context.\n\n### 3.4 Antigravity `AfterAgent`\n\n- `decision: \"allow\" | \"deny\" | \"block\"` controls the next turn.\n- `reason: \"...\"` is surfaced to the UI when blocked.\n- There is no documented \"followup_message\" or \"additionalContext\"\n  field; the only meaningful output is the decision.\n\n## 4. The live-payload capture protocol (mandatory)\n\n**Rule: never trust fixture tests against docs alone. Always run real\nCLI sessions before the \u002Fer PASS verdict.**\n\nThree concrete steps:\n\n### 4.1 Capture the actual payload\n\nFor each CLI you support:\n\n```bash\n# Claude\ntimeout 60 claude --print --dangerously-skip-permissions \\\n  'Reply with the single word: ping' >\u002Fdev\u002Fnull\njq '.' \"$HOME\u002F.claude\u002Fvar\u002Fcross_cli_status\u002Flast.json\"\n\n# Codex\ntimeout 60 codex exec --dangerously-bypass-approvals-and-sandbox \\\n  'Reply with the single word: pong' >\u002Fdev\u002Fnull\njq '.' \"$HOME\u002F.claude\u002Fvar\u002Fcross_cli_status\u002Flast.json\"\n```\n\nIf the JSON file is missing or empty, the hook did not fire — go back\nto §1 and re-verify discovery indirection before debugging anything\nelse.\n\n### 4.2 Bake the captured payloads into unit-test fixtures\n\nThe fixtures in `tests\u002Ftest_cross_cli_status.py::CLAUDE_LIVE_PAYLOAD`\nand `tests\u002Ftest_cross_cli_status.py::CODEX_LIVE_PAYLOAD` are the\n**regression-test ground truth** — they assert \"this is what the hook\nactually receives from a real CLI session.\" If a future vendor update\nchanges the payload shape, the unit tests fail FIRST and the agent\nupdates both the extractor and the fixture in lockstep.\n\n### 4.3 Add a regression test for every schema drift you find\n\nEvery bug class found in §3 (Codex `continue:false` ignored, Claude\nStop missing `model`\u002F`context_window`, Cursor no `rate_limit_pct`\nfield, Antigravity no public Stop event) is now a regression test:\n\n```python\ndef test_claude_stop_payload_lacks_model(self) -> None:\n    \"\"\"Claude v2.1.220 Stop payload does NOT carry `model` or\n    `context_window` (those only appear in the statusline payload).\"\"\"\n    rec = parse(json.dumps(CLAUDE_LIVE_PAYLOAD))\n    self.assertIsNone(rec[\"model\"])\n    self.assertIsNone(rec[\"context_pct\"])\n\ndef test_codex_stop_payload_model_is_string(self) -> None:\n    \"\"\"Codex 0.144.5 Stop payload has `model` as a top-level STRING,\n    not a dict.\"\"\"\n    rec = parse(json.dumps(CODEX_LIVE_PAYLOAD))\n    self.assertIsInstance(rec[\"model\"], str)\n```\n\n## 5. Recipe — shipping a new cross-CLI hook\n\n1. **Pick the event** — Stop is the lowest-risk (purely informational,\n   never blocks the turn). PreToolUse is the highest-stakes (controls\n   tool execution; needs the full response-schema discipline in §3).\n\n2. **Audit the existing hook** — read the current `codex_hooks\u002F*.sh`\n   (or equivalent) to find which fields are read, which are silently\n   dropped, and which assumptions break under a real payload.\n\n3. **Write the cross-CLI hook** as a single Python module that:\n   - reads JSON from stdin (no other CLI),\n   - detects the CLI from `HERMES_HOOK_CLI` env + payload shape\n     (per §2.3),\n   - normalizes fields into a single schema,\n   - is fail-soft by default (writes an `unknown_cli` record rather\n     than blocking the turn),\n   - emits the **lowest-common-denominator response** — for Stop,\n     that's `{ \"continue\": true }` (Codex's only supported shape).\n\n4. **Wire it into Claude** — add to `~\u002F.claude\u002Fsettings.json` `Stop`\n   array as the first entry. Copy the script to `~\u002F.claude\u002Fhooks\u002F`\n   (or `\u003Crepo>\u002F.claude\u002Fhooks\u002F` for project-local).\n\n5. **Wire it into Codex** — replace `~\u002F.codex\u002Fstop-hook-dispatch.sh`\n   with one that explicitly invokes your hook (per §1.2). Do NOT\n   rely on `\u003Crepo>\u002Fcodex_hooks.json` or even `\u003Crepo>\u002F.codex\u002Fhooks.json`\n   Stop entries being executed.\n\n6. **Wire it into Cursor + Antigravity + agy** — see §1.3-1.5.\n\n7. **Run live capture** — §4.1.\n\n8. **Bake fixtures + regression tests** — §4.2 + §4.3.\n\n9. **Document the schema drift** — append to the SKILL.md's\n   `references\u002Flive-payload-capture-\u003Cdate>.md` so future agents know\n   which fields are documented-but-absent in each CLI's payload.\n\n10. **Verify in `\u002Fer` + `\u002Fadvice`** — load `advice` skill; use the\n    cross-CLI schema verification recipe (now codified in\n    `references\u002Fcross-cli-hook-schema-verification.md` of the advice\n    skill). The 3-reviewer fan-out catches: schema-deviation bugs the\n    unit tests miss (Reviewer B), implementation bugs the docs didn't\n    cover (Reviewer A), bypass \u002F loop-storm edge cases (Reviewer C).\n\n## 6. Known limitations (don't promise more than the hooks deliver)\n\n| Limitation | Why | Mitigation |\n|---|---|---|\n| Claude v2.1.220 Stop has no `model` \u002F `context_window` \u002F `cost` | Those are statusline-only | Subscribe to the statusline event for those fields; record `null` in the Stop record |\n| Codex 0.144.5 Stop has no `usage` (tokens\u002Fcost) | Codex renders \"tokens used\" outside the hook channel | Parse the Codex CLI stdout separately if you need tokens\u002Fcost; don't expect them in the hook payload |\n| Cursor `stop` exposes no rate-limit % fields | Cursor app surfaces RL% in the UI badge, not the hook payload | Heuristic: `status=\"error\" + loop_count >= 4` → `rate_limit_pct=100, window=\"loop_storm\"` (signals a Cursor loop storm) |\n| Antigravity `AfterAgent` schema is undocumented | Gemini CLI variant has no published Stop payload | Surface whatever Gemini-shape fields are present; `decision` is the only reliable signal |\n| Codex's `unified_exec` skips PreToolUse | Codex 0.144+ has a second shell-call path that bypasses the hook chain (verified 2026-07-17) | Hook is a guardrail not a boundary; pair with sandbox + approval policy + audit log |\n\n## 7. References\n\n- Companion skill: `~\u002F.claude\u002Fskills\u002Fcross-cli-status-hook\u002FSKILL.md` —\n  the worked example: a single Python Stop hook that handles all five\n  CLIs, with 20 unit tests + a live-tmux integration suite.\n- Cross-reference: `~\u002F.hermes\u002Fskills\u002Fadvice\u002FSKILL.md` →\n  \"Cross-CLI hook schema verification recipe (added 2026-07-15)\" —\n  the `\u002Fadvice` recipe for verifying vendor-docs claims before\n  shipping a cross-CLI hook.\n- Cross-reference: `~\u002F.hermes\u002Fskills\u002Fcodex-path-deletion-guard\u002FSKILL.md`\n  → \"Pitfall #0\" — Codex 0.144+ has a `unified_exec` shell path that\n  skips PreToolUse hooks entirely. Verified regression on 2026-07-17.\n",{"name":5,"context":25,"version":53,"triggers":54,"description":60,"allowed-tools":61},"1.0.0",[55,56,57,58,59],"cross cli hook","hook for claude codex cursor antigravity agy","port hook across CLIs","normalize hook payload","stop hook all CLIs","Ship a CLI lifecycle hook (Stop, PreToolUse, PostToolUse, SessionStart,\nUserPromptSubmit) that runs correctly across Claude Code, Codex, Cursor\nAgent, Antigravity (Gemini CLI's antigravity branding), and agy. The four\nCLIs disagree on (a) where they discover hook scripts, (b) what payload\nshape they send on stdin, (c) which JSON fields they honor in the\nresponse, and (d) which event names they emit. Vendor docs are load-bearing\nfor shape but silently omit the discovery indirection; only running real\nCLI sessions reveals the ground truth. Verified 2026-07-30 against Claude\nv2.1.220, Codex 0.144.5, Cursor 3.11.13, Antigravity, agy 1.1.8.\n",[62,63,64,39],"Read","Write","Edit","main","42ccd02cbf5e8e47839dc3eab6fc754dc6b339cf","hermes\u002Fskills\u002Fcross-cli-hook-integration",0,"https:\u002F\u002Fgithub.com\u002Fjleechanorg\u002Fjleechan-skills","https:\u002F\u002Fgithub.com\u002Fjleechanorg","2026-11-14 14:55:35",{"source":8,"skillName":5,"commands":73,"prompt":83,"zipAvailable":84},[74,77,80],{"tool":75,"command":76},"npx","npx skills add jleechanorg\u002Fjleechan-skills --skill cross-cli-hook-integration",{"tool":78,"command":79},"bunx","bunx skills add jleechanorg\u002Fjleechan-skills --skill cross-cli-hook-integration",{"tool":81,"command":82},"pnpm","pnpm dlx skills add jleechanorg\u002Fjleechan-skills --skill cross-cli-hook-integration","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fjleechanorg\u002Fjleechan-skills\u002Fblob\u002Fmain\u002Fhermes\u002Fskills\u002Fcross-cli-hook-integration\u002FSKILL.md",true,[86],{"path":87,"resourceType":88,"resourceTypeDesc":89,"sizeBytes":90,"sourceHtmlUrl":91},"references\u002Flive-payload-capture-2026-07-30.md","REFERENCE","参考文档",5253,"https:\u002F\u002Fgithub.com\u002Fjleechanorg\u002Fjleechan-skills\u002Fblob\u002Fmain\u002Fhermes\u002Fskills\u002Fcross-cli-hook-integration\u002Freferences\u002Flive-payload-capture-2026-07-30.md",[93,101,108,116,124,133],{"skillNo":94,"name":95,"nameZh":6,"description":96,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":97,"categories":98,"keywords":99,"publishedAt":100},"01M7DRVZXXMGY4G81K5GVF4V20","disk-reclaim-playbook","Use Disk Magician to diagnose disk growth or qualify cleanup on macOS or Linux.","https:\u002F\u002Fgithub.com\u002Fjleechanorg\u002Fjleechan-skills\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fdisk-reclaim-playbook\u002FSKILL.md",[],[],"2026-11-15 14:19:17",{"skillNo":102,"name":103,"nameZh":6,"description":104,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":105,"categories":106,"keywords":107,"publishedAt":100},"01M7B63PNTT2TY78RFKHD8SP3X","claudea-bench","Compare `claudea` and normal `claude` on a fair split of comparable work by default; use `--strict` for duplicate runs of the exact same task.","https:\u002F\u002Fgithub.com\u002Fjleechanorg\u002Fjleechan-skills\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fclaudea-bench\u002FSKILL.md",[],[],{"skillNo":109,"name":110,"nameZh":6,"description":111,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":112,"categories":113,"keywords":114,"publishedAt":115},"01M7622KQJ32AV4K5BXEMVSSEB","pr","Alias for the canonical pr-lifecycle PR workflow skill (\u002Fpr-workflow, \u002Fprw).","https:\u002F\u002Fgithub.com\u002Fjleechanorg\u002Fjleechan-skills\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fpr\u002FSKILL.md",[],[],"2026-11-12 13:55:43",{"skillNo":117,"name":118,"nameZh":6,"description":119,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":120,"categories":121,"keywords":122,"publishedAt":123},"01M7432W92AKC4D1TKJ00VCMMT","whisper","OpenAI's general-purpose speech recognition model. Supports 99 languages, transcription, translation to English, and language identification. Six model sizes from tiny (39M params) to large (1550M params). Use for speech-to-text, podcast transcription, or multilingual audio processing. Best for robust, multilingual ASR.","https:\u002F\u002Fgithub.com\u002Fjleechanorg\u002Fjleechan-skills\u002Fblob\u002Fmain\u002F.claude\u002Fskills_archive\u002F2026-11-09-no-usage-evidence\u002Fwhisper\u002FSKILL.md",[],[],"2026-11-11 15:11:14",{"skillNo":125,"name":126,"nameZh":6,"description":127,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":128,"licenseFileUrl":129,"sourceHtmlUrl":130,"categories":131,"keywords":132,"publishedAt":123},"01M7432T6BN1A9SHB8RBQR5EMP","webapp-testing","Toolkit for interacting with and testing local web applications using Playwright. Supports verifying frontend functionality, debugging UI behavior, capturing browser screenshots, and viewing browser logs.","Apache-2.0","https:\u002F\u002Fgithub.com\u002Fjleechanorg\u002Fjleechan-skills\u002Fblob\u002Fmain\u002F.claude\u002Fskills_archive\u002F2026-11-09-no-usage-evidence\u002Fwebapp-testing\u002FLICENSE.txt","https:\u002F\u002Fgithub.com\u002Fjleechanorg\u002Fjleechan-skills\u002Fblob\u002Fmain\u002F.claude\u002Fskills_archive\u002F2026-11-09-no-usage-evidence\u002Fwebapp-testing\u002FSKILL.md",[],[],{"skillNo":134,"name":135,"nameZh":6,"description":136,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":137,"categories":138,"keywords":139,"publishedAt":123},"01M7432NDC7S6C6MX7M6RW8CTT","pr-report","This skill should be used when the user asks for a PR report, PR audit, PR delta analysis, \u002Fpr-report, or wants per-PR summary with delta files\u002Flines. Generates a structured report for one or more open PRs covering purpose, files changed, +\u002F− line counts, \u002Fcode-standards + \u002Fthermo review findings, \u002Fponytail simplification opportunities, file-overlap combination candidates, and \u002Fgreen status per pr-green-definition. Output: machine-readable JSONL + human-readable markdown. Read-only by default; can apply simplifications if user opts in.","https:\u002F\u002Fgithub.com\u002Fjleechanorg\u002Fjleechan-skills\u002Fblob\u002Fmain\u002F.claude\u002Fskills_archive\u002F2026-11-09-no-usage-evidence\u002Fpr-report\u002FSKILL.md",[],[]]