feat: add basic Codex hook provider (presence + turn-end + Bash events)#335
Open
arc-web wants to merge 1 commit into
Open
feat: add basic Codex hook provider (presence + turn-end + Bash events)#335arc-web wants to merge 1 commit into
arc-web wants to merge 1 commit into
Conversation
Codex's experimental hooks system (SessionStart, PreToolUse/PostToolUse restricted to Bash, UserPromptSubmit, Stop) shares field names with Claude Code's, so this adds a minimal HookProvider following the pattern documented in CLAUDE.md: a self-contained subdirectory under server/src/providers/hook/codex/ (provider, installer, hook script). Scope is intentionally small given Codex's current hook coverage: no subagent events, no file-write hooks, no heuristic/transcript fallback (Codex exposes none pixel-agents could poll). Codex sessions show up as office characters that go active on Bash calls and idle on Stop -- not full parity with Claude, just presence + turn-end pulses. Runtime change: HookEventHandler previously hardwired a single provider per instance (the `providerId` param was received but unused). Added an optional `secondaryProviders` list so AgentRuntime can normalize events from a second provider (Codex) without disturbing the primary Claude provider's team/tool-display logic, which secondary providers don't use. cli.ts wires codexProvider only when ~/.codex exists, so machines without Codex never get a ~/.codex/ directory created. The installer is additive: it merges into any existing ~/.codex/hooks.json entries rather than overwriting, and only flips config.toml's `codex_hooks` feature flag via a targeted single-line edit (no TOML parser dependency). Verified: full server test suite passes (227/227, 14 new), build clean, and a manual hook POST end-to-end created a live agent in a running standalone server instance. Known pre-existing gap (not introduced here, also affects the Claude hook script): the standalone CLI's copyHookScript(distRoot) call passes dist/ as extensionPath, but copyHookScript joins extensionPath + 'dist' + 'hooks', producing a dist/dist/hooks/... miss. Both providers log "hook script not found" on first standalone-CLI start until something copies the file into place. Flagging for a follow-up fix.
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.
Summary
Adds a minimal
HookProviderfor OpenAI Codex CLI, following the single-subdirectory pattern documented in CLAUDE.md (server/src/providers/hook/codex/).Codex's hooks system is experimental (feature-flagged off by default) and only fires 5 events today:
SessionStart,PreToolUse/PostToolUse(Bash only),UserPromptSubmit,Stop. The payload shareshook_event_name/session_id/cwdfield names with Claude Code's, so this is a straightforward normalization boundary, not a new event taxonomy.Given Codex's current coverage, scope is intentionally small: no subagent events, no file-write hooks, no heuristic/transcript-polling fallback (Codex exposes no transcript file pixel-agents could poll). A Codex session shows up as an office character that goes active on Bash calls and idle on Stop — presence + turn-end, not full Claude-level tool-by-tool detail.
What changed
server/src/providers/hook/codex/— provider (codex.ts), installer (codexHookInstaller.ts), hook script (hooks/codex-hook.ts). Mirrors the Claude provider's structure.~/.codex/hooks.jsonadditively (merges into existing hook entries, doesn't overwrite) and flips thecodex_hooksfeature flag inconfig.tomlvia a targeted single-line edit — no new TOML dependency, deliberately limited to the common single top-level[features]table case.HookEventHandlerpreviously hardwired a singleHookProviderper instance — theproviderIdparam onhandleEventwas received but unused (_providerId). Added an optionalsecondaryProviders: HookProvider[]list soAgentRuntime/HookEventHandlercan normalize events from a second provider without touching the primary provider's team/tool-display logic (which Codex doesn't use).cli.tspasses[codexProvider]only when~/.codexexists, so machines without Codex never get a~/.codex/directory created.esbuild.js: bundles the new hook script todist/hooks/codex-hook.jsalongside the existing Claude one (switched from a single multi-entryoutdirbuild, which nested output underclaude/hooks//codex/hooks/, to per-entryoutfilebuilds so both stay flat).server/__tests__/codex.test.ts— unit coverage fornormalizeHookEvent(all 5 events + unknown/malformed input) andformatToolStatusreuse.Testing
npm run buildclean (typecheck, lint, asyncapi drift check, e2e inventory drift check all pass).SessionStartthenStopevent through the builtcodex-hook.jsscript and confirmed a live agent was created in the running instance's state.~/.codex/hooks.json, which already had several unrelated hooks configured (a Bash-deny guard, a Gmail notifier, a response-quality gate, somesupacode-managed entries) — confirmed it merged in additively and left every existing entry untouched.Known gap (pre-existing, not introduced here)
While testing, I found the standalone CLI's
copyHookScript(distRoot)call passesdist/asextensionPath, butcopyHookScriptjoinsextensionPath + 'dist' + 'hooks', producing adist/dist/hooks/...miss on first run ("Hook script not found at .../dist/dist/hooks/claude-hook.js"). This affects the existing Claude provider too, not just Codex — happy to send a separate small fix if useful, kept out of this PR to stay scoped to Codex support.Not attempted
Codex offers no equivalent to Claude's Agent Teams, subagent lifecycle, or file-write hooks today, so no
TeamProvider, nogetSessionDirs/heuristic fallback, and no subagent visualization for Codex sessions. Happy to extend if/when Codex's hooks API grows that coverage.