Three Ways AGENTS.md Hooks Silently Fail in Codex 0.172.0
Three Ways AGENTS.md Hooks Silently Fail in Codex 0.172.0
If you have invested time wiring up AGENTS.md hooks — for audit logging, context injection, or permission enforcement — Codex 0.172.0 contains three distinct bugs that can cause those hooks to silently do nothing, receive the wrong environment, or be ignored at exactly the moment they matter most. None of them produce an error message.
This article documents each failure mode with reproduction steps and the workaround available today.
Background: What AGENTS.md Hooks Are For
Codex’s hook system lets you attach shell scripts or executables to lifecycle events: SessionStart, SessionStop, PermissionRequest, and others. A hook receives context via environment variables and can return structured JSON to inject additional context or influence Codex’s behaviour.
The common use cases are:
- Audit logging — record every permission grant to a file or remote service
- Context injection — inject a codebase map or project rules into every session via
additionalContext - Permission enforcement — gate sensitive approvals behind a secondary check
- Terminal routing — identify which terminal pane a session belongs to
All three bugs described below affect these use cases directly.
Failure 1: request_permissions Bypasses the PermissionRequest Hook
Reported: GitHub issue #64284, Codex CLI 0.172.0 (unchanged on main as of 27 November 2026)
What happens
When a tool call uses request_permissions to request a directory or network grant, Codex emits the approval directly to the client as EventMsg::RequestPermissions without first running any registered PermissionRequest hook.
Every other approval path — command execution, patch, MCP-tool, and network-access approvals — calls run_permission_request_hooks before proceeding. The request_permissions path skips this call entirely.
What breaks
If you have a PermissionRequest hook that:
- Logs grants to an audit trail
- Sends a notification to a secondary approver
- Blocks certain path patterns
…then every request_permissions-initiated grant goes through without triggering it. The user sees the approval dialogue; the hook never runs.
The bug is in the source at:
codex-rs/core/src/tools/approvals.rs:602— callsrun_permission_request_hooksbefore askingcodex-rs/core/src/session/mod.rs:3521—request_permissions_for_environmentfollows therequest_guardian_approvalpath (line 3585) or emitsEventMsg::RequestPermissions(line 3662) without the hook call
Workaround
There is no clean workaround at the hook level. If audit completeness is a hard requirement, you can approximate it with a SessionStop hook that inspects the session’s permission log after the fact, but this is not equivalent to a synchronous gate.
A fix has been proposed in the issue thread: add a run_permission_request_hooks call inside request_permissions_for_environment before the EventMsg::RequestPermissions branch. No PR has been merged as of this writing.
Failure 2: SessionStart additionalContext Fuses onto the First User Prompt
Reported: GitHub issue #64288, Codex CLI 0.172.0, macOS arm64
What happens
When a SessionStart hook returns additionalContext, the text is concatenated directly onto the first user prompt with no separator. If the injected context does not end with a newline, the last token of the context and the first token of the user’s instruction are fused into a single unreadable token.
The model receives something like:
<your injected codebase map ending in ...src/main.rsPlease refactor the auth module
It treats this as a single continuation of the context block and ignores the instruction entirely, behaving as if no task was given.
What breaks
Any SessionStart hook that injects structured context — a codebase map, a rules block, a project summary — without a guaranteed trailing newline will silently swallow the user’s first instruction. The session starts, the context is injected, and then nothing happens.
This was reported with the ponytail plugin 5.3.3, whose additionalContext ends without a trailing newline when the codebase map is non-empty. The issue also affects any custom hook with the same property.
Reproduction
# hook script: returns additionalContext without a trailing newline
echo '{"additionalContext": "RULES: always use TypeScript."}'
With this hook registered as SessionStart, send the first message Add a logger. The model receives RULES: always use TypeScript.Add a logger and ignores the instruction.
Workaround
Add a trailing newline to your hook’s additionalContext output:
echo '{"additionalContext": "RULES: always use TypeScript.\n"}'
Or in a JSON-generating script, ensure the last character of the context string is \n. This is a reliable workaround until a fix ships that inserts the separator automatically.
Failure 3: Shared Daemon Passes the First CLI’s Environment to All Sessions
Reported: GitHub issue #64518, Codex CLI 0.172.0, macOS
What happens
With daemon_auto_start enabled (the default), the first codex invocation starts a shared app-server daemon. All subsequent CLI invocations in other terminals connect to that daemon rather than starting their own server.
The daemon runs every session’s hooks and stdio MCP servers as its own child processes — and inherits its environment from the first CLI that started it. A second CLI opened in a different terminal sends hooks into the daemon’s environment, which is the first terminal’s environment.
Terminal A: env MARK=A codex ← starts daemon with MARK=A
Terminal B: env MARK=B codex ← connects to existing daemon
B's hook: echo $MARK ← prints A, not B
B's shell: echo $MARK ← prints A, not B
What breaks
This affects any hook or MCP server that reads terminal-specific environment variables:
| Variable | Tool |
|---|---|
TERM_SESSION_ID |
macOS Terminal.app session routing |
TMUX_PANE |
tmux pane identification |
WEZTERM_PANE, KITTY_WINDOW_ID |
WezTerm, Kitty terminal routing |
| Custom variables | Project-specific secrets, AWS_PROFILE, VAULT_TOKEN, etc. |
The second session’s hooks receive the first session’s credentials. If AWS_PROFILE=production is set in Terminal A and AWS_PROFILE=sandbox in Terminal B, Terminal B’s hooks run against the production account.
There is no mechanism inside the hook for the hook to discover which client started the thread, so it cannot self-correct.
Workaround
Pass --no-daemon when starting Codex in environments where hooks rely on terminal-specific variables:
codex --no-daemon
This starts an independent server per CLI invocation, restoring correct environment isolation. The trade-off is that each session starts its own process and cannot share state with other sessions through the daemon.
Alternatively, set daemon_auto_start = false in your config.toml:
[cli]
daemon_auto_start = false
Impact Summary
| Issue | Hook affected | Failure mode | Workaround |
|---|---|---|---|
| #64284 | PermissionRequest |
Never called for request_permissions grants |
None (use SessionStop audit as approximation) |
| #64288 | SessionStart |
additionalContext fuses onto first user message |
Add trailing \n to hook output |
| #64518 | All hooks + MCP servers | Daemon passes first CLI’s environment to all sessions | Use --no-daemon or daemon_auto_start = false |
What to Watch For
All three issues were filed against 0.172.0 and have not yet been closed by a fix PR. The active v0.174.0 alpha sprint (currently at rust-v0.174.0-alpha.9) is focused on TUI improvements; none of the hook-related PRs have appeared in the alpha changelog as of 29 November 2026.
If you are using hooks for anything security-relevant — permission auditing, credential scoping, project rule injection — the most reliable stance today is:
- Add
\nto alladditionalContextreturns. - Run with
--no-daemonin any multi-terminal workflow. - Treat
PermissionRequesthooks as informational rather than enforcing until #64284 is fixed.
Watch the linked issues for fix PRs. When a stable release closes all three, the workarounds can be removed.