Repository navigation
Conversation
Trirrin
left a comment
There was a problem hiding this comment.
Reviewed the Codex PreToolUse hook implementation. The hook output shape matches Codex requirements: rewrites are only emitted with permissionDecision=allow, deny responses omit updatedInput, and hooks.json install/uninstall preserves foreign entries. Verified locally with cargo test -q codex, cargo fmt --all -- --check, and git diff --check.
|
this would implement #1812 as well afaik |
Register rtk hook codex for Codex Bash events and render protocol-valid PreToolUse responses. Default permission mode emits neutral JSON unless an explicit RTK allow rule matches; bypassPermissions upgrades eligible rewrites to allow plus updatedInput. Deny responses carry a non-empty reason and never include updatedInput, preventing the exact parser failure: PreToolUse hook returned updatedInput without permissionDecision:allow. Files: src/hooks/hook_cmd.rs and src/main.rs. Reuse the existing hook decision renderer and command lexer; cover Bash filtering, compound and environment-prefixed rewrites, substitutions and redirects, malformed payloads, deny shape, default-mode neutrality, and bypassPermissions. Verification: cargo test -q codex (18 passed), cargo fmt --all -- --check, and git diff --check. Signed-off-by: Andrew Hundt <[email protected]>
Codex maps approval_policy=never to permission_mode=bypassPermissions and validates PreToolUse hook output separately from Claude settings. The previous Codex path loaded Claude Bash rules, so a Claude allow rule could cause RTK to emit permissionDecision:allow in Codex default mode and bypass Codex approval handling. Route production Codex checks through Host::Codex with no Claude rule files, allow safe rewrites only when Codex explicitly reports bypassPermissions, and reject payloads whose hook_event_name is not PreToolUse. Keep explicit ask-only redirects out of bypass auto-allow because they still target a file. Document the resulting default/ask no-op behavior and add regression coverage for event filtering, host-rule isolation, and redirect handling. Tests: cargo test -q codex_ (20 passed); cargo test -q (2523 unit passed, 8 ignored, 64 integration passed); cargo check -q; cargo clippy --all-targets -- -D warnings; cargo fmt --all -- --check; git diff --check. Files: src/hooks/hook_cmd.rs, src/hooks/permissions.rs, src/hooks/README.md. Signed-off-by: Andrew Hundt <[email protected]>
Codex bypassPermissions must not turn an explicit RTK Ask verdict into an allow response. That would emit updatedInput with authority the user did not grant, especially for commands whose safety depends on a prompt.\n\nPass PermissionVerdict through the Codex renderer and promote only the Default verdict in bypass mode. Preserve the upstream tuple HookDecision representation, keep explicit Ask and unattestable redirect decisions on the no-opinion path, and retain coverage for both safe commands and file redirects.\n\nFiles: src/hooks/hook_cmd.rs. Verification: cargo test -q codex_ (20 passed), cargo fmt --all -- --check, and git diff --check.
KuSh
left a comment
There was a problem hiding this comment.
Hi @ahundt thanks for your work.
Could you rebase it?
Also reviewing this PR turned up one issue worth fixing before we can merge your work:
Host::Codex rules are hardcoded empty in check_command_for (src/hooks/permissions.rs), so the deny path is dead code in production.
check_command_for(cmd, Host::Codex) always returns empty deny/ask/allow vectors, meaning PermissionVerdict::Deny (and an explicit PermissionVerdict::Allow) can never actually be produced for real Codex traffic, every command resolves to PermissionVerdict::Default. The 20 Codex-focused tests that exercise deny reasons only pass because they go through the test-only run_codex_inner_with_rules helper, which injects rules directly and bypasses check_command_for entirely, so they don't cover the real run_codex → process_codex_payload production path.
Concretely, this means the PR description's "A denied command → RTK returns permissionDecision: "deny" with a non-empty reason" and the README's deny-response row aren't actually reachable today. There's no real Codex-specific rule set wired in yet.
Could you either:
- wire real deny/ask/allow rules for
Host::Codex(mirroring howHost::Claude/other hosts source theirs), and extend the tests to go throughcheck_command_forfor at least one deny case, or - if Codex intentionally has no host-specific rule set yet and rewrites are meant to be governed purely by the rewrite registry +
permission_modecheck, adjust the PR description/README to say so, and consider short-circuitingcheck_command_forforHost::Codex(it currently still runs the full compound-command lexer/split pass just to land on a statically-knownDefaultresult every time).
Three smaller things while I'm here:
dontAskis one of Codex's documented no-promptpermission_modevalues, alongsidebypassPermissions, but onlybypassPermissionspromotes anAskRewritetoAllowRewrite(hook_cmd.rs:552). Worth confirming whetherdontAskshould behave the same way, or whether that's deliberate.- The
PayloadAction::Denyarm added torun_claude()(hook_cmd.rs:615) looks unreachable.process_claude_payloadalways passesDenyHandling::Skip, so only Codex's path can construct that variant. verdict.clone()athook_cmd.rs:551is unnecessary.PermissionVerdicthas no owned data in any variant, so it could just deriveCopyinstead ofCloneand drop the.clone()call.
Why: PR rtk-ai#2557 must be current with develop and its production behavior must match the documented Codex permission contract. What: Merge current upstream/develop, preserve Codex and Vibe command variants, remove the unreachable RTK Codex deny path, bypass static empty-rule parsing, keep dontAsk neutral, and derive Copy for permission verdicts. Codex remains the authority for approval and execpolicy rules. Verification: cargo fmt --all; cargo check --all-targets; 20 Codex-focused tests; 6 Vibe-focused tests; git diff --check. Signed-off-by: Andrew Hundt <[email protected]>
Why: The combined integration proof must include PR rtk-ai#2557 after reproducing and correcting its unreachable production deny path. What: Merge v4/codex-hook so default and dontAsk remain neutral, bypassPermissions can carry a safe updatedInput, and Codex approval and execpolicy remain authoritative. Verification: - git diff --cached --check - inspected staged Codex adapter and CLI scope before commit Signed-off-by: Andrew Hundt <[email protected]>
KuSh
left a comment
There was a problem hiding this comment.
Verified the 4 items from the previous review round (Host::Codex removal, dontAsk neutrality, unreachable Deny arm removal, verdict Copy) — all confirmed fixed in 718a035; cargo test, cargo clippy --all-targets, and cargo fmt --check all pass clean.
Found 2 more issues that aren't part of this diff so they can't be attached as inline comments here, flagging in the review body instead:
src/hooks/init.rs(run_codex_mode_with_paths, ~line 2384):rtk init --codexonly writesAGENTS.md/RTK.md. Unlike Cursor/Droid/Vibe, there's no patch function that registers the newrtk hook codexPreToolUse handler into any Codex hook config. As it stands, the new hook (20 passing tests, fully wired intomain.rs) is unreachable for real users unless they hand-edit their Codex config.hooks/codex/README.md:7(anddocs/guide/getting-started/supported-agents.md:43/231,docs/contributing/TECHNICAL.md:321/339): still states "Prompt-level guidance via awareness document -- no programmatic hook", which is now false given this PR adds a full programmatic PreToolUse hook. Reinforces the install-gap above by hiding the new capability from anyone reading the docs.
Two inline comments below on code actually touched by this diff.
| ask_rewrite_handling: AskRewriteHandling, | ||
| ) -> PayloadAction { | ||
| let (rewritten, allow) = match decision { | ||
| HookDecision::Deny => { |
There was a problem hiding this comment.
The deleted test test_codex_deny_emits_block_without_updated_input was the only test exercising HookDecision::Deny through process_pre_tool_use_payload_with_decision (the renderer shared by Claude and Codex). No replacement asserts this Deny -> Skip mapping at the payload-processing level for either host post-refactor (only the lower-level decide_from_verdict/test_decide_deny unit test remains).
Failure scenario: a future change to this shared renderer that mishandles HookDecision::Deny (e.g. accidentally emits a rewrite instead of Skip) would pass CI green for both Claude and Codex, since nothing exercises Deny at the process_*_payload level any more. Worth adding a payload-level test back for at least one host.
| } | ||
| } | ||
|
|
||
| fn process_codex_payload(v: &Value) -> PayloadAction { |
There was a problem hiding this comment.
process_codex_payload bypasses the shared Host/check_command_for abstraction entirely by hardcoding PermissionVerdict::Default, instead of adding a Host::Codex => (Vec::new(), Vec::new(), Vec::new()) arm the way Host::Vibe (permissions.rs:48) already does for a rule-less host.
Failure scenario: Codex is now the only host routed around the shared per-host rule-loading match arm. If a shared concern is later added there (audit/telemetry keyed on Host, or real Codex-specific rules), Codex's hardcoded bypass has to be updated separately and can silently drift from every other host's handling.
|
Thanks for this. Native Codex PreToolUse support landed in #3552, merged on 2026-09-13, which added |
Keep Codex approval authoritative when RTK rewrites Bash commands
Summary
RTK now provides a native
rtk hook codexhandler for CodexPreToolUseevents. It returns Codex-valid JSON and never claims an approval that Codex has not granted.The change addresses issue #1812 and the failure reported as
PreToolUse hook returned updatedInput without permissionDecision:allow. Codex receivesupdatedInputonly withpermissionDecision: "allow"; a deny response includes a non-empty reason and no replacement command.Before and after
rtk hook codexgit statusupdatedInputwithoutallow, which Codex rejects.{}and leaves approval and execution to Codex.bypassPermissions,git statuspermissionDecision: "allow"withupdatedInput.command: "rtk git status".permissionDecision: "deny"with a non-empty reason and noupdatedInput.PreToolUseinput{}and does nothing.Implementation
Host::Codexuses the shared rewrite and permission helpers without reading Claude settings.process_codex_payloadpreserves ask-only file redirects, renders neutral/allow/deny responses according to Codex's schema, and keeps Codex responsible for approval and execution policy. The other host adapters keep their existing response schemas.Hook-file installation is intentionally separate so the protocol contract and settings-file mutation can be reviewed independently.
Codex can still display one status line for each matching PreToolUse handler; this change does not remove or disable foreign handlers. It ensures RTK's own response is valid when Codex executes it alongside other handlers.
Verification
cargo clippy --all-targets --all-features -- -D warnings,cargo fmt --all -- --check, andgit diff --checkpass.