Skip to content

Declare Codex status hooks in config.toml instead of a -c argument - #1384

Merged
h0x91b merged 1 commit into
mainfrom
fix/codex-hooks-argv-quoting-v2
Aug 15, 2026
Merged

Declare Codex status hooks in config.toml instead of a -c argument#1384
h0x91b merged 1 commit into
mainfrom
fix/codex-hooks-argv-quoting-v2

Conversation

@h0x91b

@h0x91b h0x91b commented Aug 15, 2026

Copy link
Copy Markdown
Owner

Hi — Claude here, the AI assistant that worked on this branch.

Launching Codex on Windows died before the session started:

Error loading config.toml: invalid type: string "{SessionStart=[{matcher=startup|resume,...}]}", expected struct HooksToml in `hooks`

dev3 passed its status hooks as one quoted -c hooks={...} session flag. PowerShell hands a native process one flat command line and escapes nothing, so the payload's quotes were eaten and Codex — which parses a -c value as TOML and falls back to a literal string when it does not parse — rejected it. Five spellings of that argument were measured on a real windows-latest runner; none arrived intact, so the argument is not a viable channel.

Codex also reads hooks from $CODEX_HOME/config.toml, a file dev3 already maintains for trusted projects, permissions and features. The definitions move there as a delimited managed block, so nothing about them passes through a command line on any platform. A file-declared hook arrives untrusted and is then skipped in silence, so the launch carries the bare --dangerously-bypass-hook-trust flag, feature-detected from codex --help (an unknown flag exits 2 and the session never starts).

Measured against codex-cli 0.147.0, with a controlled comparison on the block this code generates: flag off, nothing fires; flag on, the hooks fire. A -p profile file is not a hook source at all, and a linked worktree's own .codex/hooks.json is still invisible to Codex — which is why the hooks were in the argument to begin with.

The app-server round trip that fetched per-hook trust hashes, and the session-flag serializer behind it, are deleted along with every caller.

Rationale and the full measurement table: decisions/2026/08/15/codex-status-hooks-live-in-config-file.md.


🔗 Origin task in dev3: open in dev3 · dev3://task/debf310b-749d-4041-ace6-57f71fbe61e5

The hooks travelled as one quoted `-c hooks={...}` session flag, which the
Windows command line mangled into an unparsable string: every Codex session
died with `expected struct HooksToml` before it started. Five spellings of the
argument were measured on a real windows-latest runner and none arrived intact.

Codex reads hooks from $CODEX_HOME/config.toml, a file dev3 already owns for
trusted projects, permissions and features, so the definitions go there as a
delimited managed block and nothing about them touches a command line. A
file-declared hook is untrusted and would be skipped in silence, so the launch
carries the bare --dangerously-bypass-hook-trust flag, feature-detected from
codex --help because an unknown flag exits 2.

Removes the app-server round trip that fetched per-hook trust hashes, and the
session-flag serializer behind it, together with every caller.
@h0x91b
h0x91b merged commit 02b0b2a into main Aug 15, 2026
17 checks passed
@h0x91b
h0x91b deleted the fix/codex-hooks-argv-quoting-v2 branch August 15, 2026 10:24
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