fix: register gateway hook in Codex's native hooks.json so it fires#84
Merged
Conversation
johnnyfish
force-pushed
the
fix/codex-hooks-json
branch
from
July 3, 2026 22:06
adf869b to
e84d2ee
Compare
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
force-pushed
the
fix/codex-hooks-json
branch
from
July 3, 2026 23:54
e84d2ee to
0a23847
Compare
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
onecli run codexinstalls 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:~/.codex/hooks.json(user config layer), using the exact schema from the Codex hooks docs; entries there omitmatcher, which Codex doesn't use forUserPromptSubmithookSpecificOutputenvelope documented for both Codex and Claude Code (both also accept plain text, so Claude Code / Cursor / OpenCode behavior is unchanged)/hooks, so the Codex install notice now says exactly thatskill_gateway_fallback.md) with the canonical copy the API serves: keeps the new plain-requests + date-bounded-query guidance, backfills the missingclaim_requiredsection, "MCP Servers Through Gateway" section, and bare-connect_urlpresentation rule, and bumps the skill to0.8.0Server-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 runwere 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)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 noticeReview
Reviewed with
/review-changeacross the full PR diff vsmain(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