Skip to content

feat(hooks): add Codex deny-retry hook - #1550

Closed
BjornMelin wants to merge 4 commits into
rtk-ai:developfrom
BjornMelin:feat/codex-hooks
Closed

BjornMelin wants to merge 4 commits into
rtk-ai:developfrom
BjornMelin:feat/codex-hooks

Conversation

@BjornMelin

Copy link
Copy Markdown

Summary

Adds official Codex CLI hook support for RTK.

  • adds rtk hook codex for Codex PreToolUse JSON
  • updates rtk init --codex to write hooks.json and enable [features].codex_hooks = true
  • keeps AGENTS.md + RTK.md awareness guidance
  • adds uninstall/show support for Codex hooks/config state
  • documents why Codex uses deny-with-suggestion instead of transparent updatedInput

Closes #1003.

Codex hook behavior

Codex currently parses updatedInput in PreToolUse hook output but does not apply it in practice. This PR uses the working path instead:

git status --short
=> denied with: Rerun that as: rtk git status --short
=> Codex retries: rtk git status --short

The installed hooks.json command is portable:

{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Bash",
        "hooks": [
          {
            "type": "command",
            "command": "rtk hook codex",
            "statusMessage": "Checking RTK rewrite"
          }
        ]
      }
    ]
  }
}

Validation

  • cargo fmt --all
  • cargo test codex -- --nocapture
  • cargo test --all
  • cargo clippy --all-targets
  • temp-home smoke test: HOME=$(mktemp -d) ./target/debug/rtk init -g --codex
  • direct hook smoke: raw git status returns Codex deny payload with Rerun that as: rtk git status
  • direct hook smoke: already-RTK command emits no output
  • live Codex smoke: nested Codex blocked git status --short, surfaced Rerun that as: rtk git status --short, then reran the RTK command

Notes

cargo clippy --all-targets -- -D warnings is not the current CI command and fails on existing baseline warnings unrelated to this change. The repository CI command, cargo clippy --all-targets, passes.

Copilot AI review requested due to automatic review settings April 26, 2026 23:44
@pszymkowiak pszymkowiak added effort-medium 1-2 jours, quelques fichiers enhancement New feature or request labels Apr 26, 2026
@pszymkowiak

Copy link
Copy Markdown
Collaborator

[w] wshm · Automated triage by AI

📊 Automated PR Analysis

✨ Type feature
🟡 Risk medium

Summary

Adds programmatic Codex CLI hook support using a deny-with-suggestion pattern, since Codex's PreToolUse hooks cannot apply updatedInput in-place. Includes rtk hook codex command, rtk init --codex updates to write hooks.json and config.toml, uninstall/show support, and extensive documentation updates across README, TECHNICAL.md, and hook-specific docs.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #1003


Analyzed automatically by wshm · This is an automated analysis, not a human review.

@BjornMelin
BjornMelin changed the base branch from master to develop April 26, 2026 23:45
@CLAassistant

CLAassistant commented Apr 26, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ BjornMelin
❌ github-actions[bot]
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds first-class OpenAI Codex CLI integration to RTK’s hooks layer, aligning Codex with existing agent hook support while documenting why Codex currently requires a deny-with-suggestion workflow instead of in-place rewrites.

Changes:

  • Add rtk hook codex handler and wire it into the CLI subcommands.
  • Extend rtk init --codex to install/manage Codex hooks.json + enable features.codex_hooks = true in Codex config.toml, plus show/uninstall enhancements.
  • Update hook documentation across repo to reflect Codex’s deny-with-suggestion behavior.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
src/main.rs Adds the hook codex subcommand and routes execution to the Codex hook handler.
src/hooks/init.rs Implements Codex hooks.json + config.toml install/state display/uninstall logic; adds related tests.
src/hooks/hook_cmd.rs Implements Codex PreToolUse hook processing and deny-with-suggestion response shape; adds tests.
src/hooks/constants.rs Adds CONFIG_TOML constant for Codex config handling.
src/hooks/README.md Updates hooks matrix and implementation notes to include Codex behavior.
hooks/codex/README.md Documents Codex hook wiring and deny-with-suggestion behavior.
hooks/README.md Updates global hook docs to describe Codex’s non-transparent rewrite approach.
docs/contributing/TECHNICAL.md Updates contributor docs to reflect Codex hook support.
README.md Updates user-facing overview and supported tools table for Codex hook behavior.

Comment thread src/hooks/hook_cmd.rs
Comment thread src/hooks/init.rs Outdated
Comment thread src/hooks/init.rs
Comment thread src/hooks/init.rs Outdated
Comment thread src/hooks/init.rs Outdated
Comment thread hooks/codex/README.md Outdated
@JulienMaille

Copy link
Copy Markdown

Wouldn't his also work on the codex app, ie not codex CLI?

ikchifo added a commit to ikchifo/rtk that referenced this pull request May 13, 2026
Adds `rtk hook codex` subcommand for Codex CLI PreToolUse hooks.
Since Codex doesn't yet apply updatedInput, uses deny-with-suggestion
to prompt the agent to rerun with the rtk-rewritten command.

Based on rtk-ai#1550.
ikchifo added a commit to ikchifo/rtk that referenced this pull request May 14, 2026
Adds `rtk hook codex` subcommand for Codex CLI PreToolUse hooks.
Since Codex doesn't yet apply updatedInput, uses deny-with-suggestion
to prompt the agent to rerun with the rtk-rewritten command.

Based on rtk-ai#1550.
@tjx666

tjx666 commented May 18, 2026

Copy link
Copy Markdown

@BjornMelin @aeppling waiting for this

ikchifo added a commit to ikchifo/rtk that referenced this pull request May 19, 2026
Adds `rtk hook codex` subcommand for Codex CLI PreToolUse hooks.
Since Codex doesn't yet apply updatedInput, uses deny-with-suggestion
to prompt the agent to rerun with the rtk-rewritten command.

Based on rtk-ai#1550.
@aeppling aeppling self-assigned this May 22, 2026
@aeppling

aeppling commented May 22, 2026 •

Copy link
Copy Markdown
Contributor

Hey @BjornMelin

Thanks for addressing this. I'm aware of the codex CLI gap for the updatedInput that is not honored, thus being said the deny retry approach can be costly :

  • It costs extra API tokens ; each time a raw rewritable command is blocked, the model has to run an extra inference turn to re-issue it as rtk …. Transparent rewrite (and prompt-level guidance) avoid this; deny-retry is the only approach that structurally adds turns.

  • Most importantly, it's not transparent , by RTK principles we want to be as transparent as possible, so commands should be rewritten without LLM having to prefix any commands itself, as well as not causing retries.

RTK want to be a LLM proxy, transparent and efficient, and for this we want to detach from context based actions for LLMs, to avoid polluting context + more precision and reliable because deterministic. This is not possible yet because not all CLI support hooks, but for Codex we seems close to be able to do this.

Your PR is clean and thanks for this, it has a lot of clean part that could be favorized, the approach is what i want to discuss.
Did you reproduce the bug with Codex CLI ? With which version?

You can refer to my review on #2033 about the codex CLI updatedInput problem.
Open to discuss

ikchifo added a commit to ikchifo/rtk that referenced this pull request May 25, 2026
Adds `rtk hook codex` subcommand for Codex CLI PreToolUse hooks.
Since Codex doesn't yet apply updatedInput, uses deny-with-suggestion
to prompt the agent to rerun with the rtk-rewritten command.

Based on rtk-ai#1550.
@pszymkowiak pszymkowiak mentioned this pull request May 28, 2026
ikchifo added a commit to ikchifo/rtk that referenced this pull request Jun 8, 2026
Adds `rtk hook codex` subcommand for Codex CLI PreToolUse hooks.
Since Codex doesn't yet apply updatedInput, uses deny-with-suggestion
to prompt the agent to rerun with the rtk-rewritten command.

Based on rtk-ai#1550.
@hzexe

hzexe commented Jun 12, 2026

Copy link
Copy Markdown

期待,非常期待,不用为此转cloude code上

@aeppling

Copy link
Copy Markdown
Contributor

Hey @BjornMelin , sorry for the wait, since #2033 is not responding, you're welcome to take it from here if reviews taken into account, deny retry is not a logic we want in RTK since it can really cost more than it saves, if you want to continue this, refer to the #2033 and my reviews here and here :)

Thanks again for contributing, sadly other PR look stale since last review

ikchifo added a commit to ikchifo/rtk that referenced this pull request Jun 17, 2026
Adds `rtk hook codex` subcommand for Codex CLI PreToolUse hooks.
Since Codex doesn't yet apply updatedInput, uses deny-with-suggestion
to prompt the agent to rerun with the rtk-rewritten command.

Based on rtk-ai#1550.
@kazimsayed954

Copy link
Copy Markdown
image

how to use it here in vscode-codex?

@maxdestors maxdestors mentioned this pull request Jul 12, 2026
2 tasks done
@KuSh

KuSh commented Sep 19, 2026

Copy link
Copy Markdown
Collaborator

Thanks for this, and for the careful writeup of why deny-with-suggestion was the only working path when you opened it. Codex support landed in #3552 on 2026-09-13: it adds rtk hook codex, wires it into rtk init --codex with backup, status and uninstall while preserving existing user hooks, and it rewrites transparently through updatedInput, which Codex now applies, so the deny-and-retry round trip this PR is built on is no longer needed. The awareness and documentation updates here are covered by that same merge. If you think a case was missed, please comment and this can be reopened.

@KuSh KuSh closed this Sep 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort-medium 1-2 jours, quelques fichiers enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add hook to Codex

10 participants