Skip to content

fix: register gateway hook in Codex's native hooks.json so it fires#84

Merged
guyb1 merged 2 commits into
mainfrom
fix/codex-hooks-json
Jul 4, 2026
Merged

fix: register gateway hook in Codex's native hooks.json so it fires#84
guyb1 merged 2 commits into
mainfrom
fix/codex-hooks-json

Conversation

@johnnyfish

@johnnyfish johnnyfish commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

What

onecli run codex installs a gateway-detection hook (UserPromptSubmit) so Codex knows the OneCLI proxy is active. It was registered in ~/.agents/settings.json — a location Codex never reads — so the hook never fired. This PR:

  • registers the hook in Codex's native ~/.codex/hooks.json (user config layer), using the exact schema from the Codex hooks docs; entries there omit matcher, which Codex doesn't use for UserPromptSubmit
  • switches the hook script's output to the JSON hookSpecificOutput envelope documented for both Codex and Claude Code (both also accept plain text, so Claude Code / Cursor / OpenCode behavior is unchanged)
  • surfaces Codex's one-time trust step: newly registered non-managed hooks are skipped until approved via /hooks, so the Codex install notice now says exactly that
  • converges the embedded fallback skill (skill_gateway_fallback.md) with the canonical copy the API serves: keeps the new plain-requests + date-bounded-query guidance, backfills the missing claim_required section, "MCP Servers Through Gateway" section, and bare-connect_url presentation rule, and bumps the skill to 0.8.0

Server-side counterpart: onecli/onecli-cloud#624 adds the two new paragraphs to the served copy — after both merge, the served and fallback bodies are byte-identical (verified by rendering the served skill and diffing it against this file). No merge-order constraint.

Why

Codex sessions launched via onecli run were never told the gateway is active — the skill variant served to hook-based agents stays dormant until the hook fires, so a dead hook could leave agents falling back to the manual auth flows the gateway replaces.

Verification

  • go build ./... · go vet ./... · golangci-lint run (0 issues) · go test -race ./... — all green (CI green too)
  • New tests cover: registration into a fresh hooks.json, preservation of third-party hooks, idempotency, matcher omission in dedicated hooks files, invalid-JSON error, a bash execution test of the hook script (valid envelope when the proxy is active, silence otherwise), and the full Codex install path including the trust notice
  • Registration file location, schema, matcher rules, trust model, and output envelope verified against the current Codex and Claude Code hooks documentation

Review

Reviewed with /review-change across the full PR diff vs main (plus the cloud counterpart): hunk-by-hunk self-review plus a no-skill-left-behind walk — 6 of 50 skills applied (golang-patterns — Go idioms; golang-pro — error handling / tests; agent-first-cli — stderr-only, actionable notices; ai-artifact-review — prose; cloud-development — cross-repo boundary; verify-gates — both repos), each: no issues. Adversarial sweep: gofmt, stale-reference greps, notice idempotency, trust wording vs docs. Findings → fixes: reviewing the original PR surfaced 3 gaps (unsurfaced trust gate, two-way skill drift vs the served copy, empty PR body) — all fixed by this revision.

Follow-up (not this PR): Cursor may have the same dead-registration issue — its entries go to ~/.cursor/settings.json; worth checking Cursor's current hooks docs for a dedicated hooks file.

🤖 Generated with Claude Code

@johnnyfish
johnnyfish force-pushed the fix/codex-hooks-json branch from adf869b to e84d2ee Compare July 3, 2026 22:06
@johnnyfish johnnyfish changed the title Fix/codex hooks json fix: register gateway hook in Codex's native hooks.json so it fires Jul 3, 2026
The gateway detection hook for Codex was registered in
~/.agents/settings.json, a file Codex never reads, so the hook-gated
onecli-gateway skill could never trigger: its description defers to the
hook ("the hook handles detection"), and no hook ever fired.

Codex supports Claude Code-style hooks natively, but reads them from
~/.codex/hooks.json. Add a hooksFile field to agentSpec so agents with a
dedicated hook registration file get the entry merged there (preserving
existing third-party hooks), and switch the hook script to the JSON
hookSpecificOutput envelope that both Claude Code and Codex accept for
context injection. Entries written to a dedicated hooks file omit the
matcher field, matching the entries Codex tools write natively.

Verified live: Codex now receives the gateway context on every prompt
and loads the onecli-gateway skill, matching Claude Code behavior.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@guyb1
guyb1 force-pushed the fix/codex-hooks-json branch from e84d2ee to 0a23847 Compare July 3, 2026 23:54
Codex skips newly registered non-managed hooks until the user trusts
them via /hooks, so the install notice for dedicated-hooks-file agents
now says so. Also converge the embedded fallback skill with the copy
served by the API: add the claim_required section, the MCP-through-
gateway section, and the bare connect_url presentation rule, and bump
the skill to 0.8.0 (the server-side counterpart adds the new
plain-request guidance so both bodies end up byte-identical).

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@guyb1
guyb1 merged commit e097d12 into main Jul 4, 2026
2 checks passed
@guyb1
guyb1 deleted the fix/codex-hooks-json branch July 4, 2026 16:28
@guyb1 guyb1 mentioned this pull request Jul 4, 2026
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.

2 participants