Skip to content

[feat] Add shim to make rtk work with Codex - #424

Closed
sunxiaoguang wants to merge 4 commits into
rtk-ai:masterfrom
sunxiaoguang:add_shim_support_for_codex
Closed

sunxiaoguang wants to merge 4 commits into
rtk-ai:masterfrom
sunxiaoguang:add_shim_support_for_codex

Conversation

@sunxiaoguang

@sunxiaoguang sunxiaoguang commented Mar 9, 2026 •

Copy link
Copy Markdown

RTK is really great, I want to use it with Codex as well. Unfortunately, Codex does not have a PreToolUse hook. This PR implements a shim to override supported tools within a customized directory in the PATH to make it work with Codex.

Closes: #425

RTK is great, I really want to use it with Codex as well. Unfortunately, Codex does not have a PreToolUse hook. This commit implements a shim to override supported tools within a customized directory in the PATH to make it work with Codex.

Signed-off-by: Xiaoguang Sun <sunxiaoguang@gmail.com>
@sunxiaoguang sunxiaoguang changed the title Add shim to make rtk work with Codex [feat] Add shim to make rtk work with Codex Mar 9, 2026
Signed-off-by: Xiaoguang Sun <sunxiaoguang@gmail.com>
Signed-off-by: Xiaoguang Sun <sunxiaoguang@gmail.com>
Signed-off-by: Xiaoguang Sun <sunxiaoguang@gmail.com>
@Zacaria

Zacaria commented Mar 10, 2026

Copy link
Copy Markdown
Contributor

Hi ! would you accept including your work in #377 , or vice versa
We just want to see the feature included 😄

@sunxiaoguang

Copy link
Copy Markdown
Author

Hi ! would you accept including your work in #377 , or vice versa We just want to see the feature included 😄

Sure, let's get it pushed to repo so everybody can benefit from this.

@pszymkowiak

Copy link
Copy Markdown
Collaborator

Hi! Thanks for the contribution! Since March 6, all PRs should target the develop branch instead of master (see CONTRIBUTING.md).

Could you update the base branch? Click Edit at the top right of this PR and change it from master to develop.

Thanks!

@pszymkowiak

Copy link
Copy Markdown
Collaborator

Thanks for the contribution! The shim approach is interesting but we're going with a lighter AGENTS.md-based approach in PR #377 for now. The shim system would also need an uninstall command and scoping to Codex sessions only (currently affects all shells). Feel free to iterate on it as a separate proposal if you'd like!

@JuncongHe

Copy link
Copy Markdown

I put together an implementation in #642 to validate the shim-based Codex path end-to-end.

What I implemented:

  • rtk init -g --codex
  • rtk init -g --codex --uninstall
  • rtk init --show --codex
  • rtk init -g --codex --refresh-path

Technical details:

  • Instead of asking users to modify their global shell PATH, the adapter patches ~/.codex/config.toml and injects:
    • shell_environment_policy.set.PATH=<shim_dir>:<path_snapshot>
    • shell_environment_policy.set.RTK_HOST=codex
  • That means the shim is scoped to Codex-launched subprocesses only, rather than affecting all shells.
  • The runtime uses argv[0] dispatch in the RTK binary itself, so the shim entries are symlinks back to rtk.
  • The shim path reuses the shared argv-aware rewrite logic and registry entrypoints instead of maintaining a second shim-specific command map.
  • Passthrough resolution removes the shim dir from PATH and sets RTK_BYPASS=1 to avoid recursion.

This also addresses the two concerns raised on the shim PR:

  • uninstall support is included
  • PATH changes are scoped to Codex sessions only

While I think AGENTS.md would do the work, the fact that AGENTS.md is still prompt would make the integration depend on prompt/instruction behavior rather than execution-layer behavior. Therefore I believe shim might be necessary.

@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 sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@pszymkowiak

Copy link
Copy Markdown
Collaborator

Thanks for the contribution! This feature has already been integrated in the latest version (v0.33.1). Please verify with the latest release that everything works as expected on your side.

Closing as already included — thanks!

@pszymkowiak pszymkowiak added duplicate This issue or pull request already exists resolved-pending-close Answered/resolved — will close if no response labels Mar 26, 2026
@aeppling

Copy link
Copy Markdown
Contributor

Hey

We are cleaning up the codebase and improving the project structure for better onboarding. As part of this effort, PR #826 reorganizes src/ from a flat layout into subfolders.

No logic changes — only file moves and import path updates.

What you need to do

Rebase your branch on develop when receiving this comment:

git fetch origin && git rebase origin/develop

Git detects renames automatically. If you get import conflicts, update the paths:

use crate::git;        // now: use crate::cmds::git::git;
use crate::tracking;   // now: use crate::core::tracking;
use crate::config;     // now: use crate::core::config;
use crate::init;       // now: use crate::hooks::init;
use crate::gain;       // now: use crate::analytics::gain;

Need help rebasing? Tag @aeppling

@pszymkowiak

Copy link
Copy Markdown
Collaborator

Thanks for this @sunxiaoguang! Codex support has since landed in RTK — hooks/codex/ is on develop. This is now superseded, and there's been no activity here for ~8 weeks. Closing — feel free to reopen or open a fresh PR if something's still missing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

duplicate This issue or pull request already exists resolved-pending-close Answered/resolved — will close if no response

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] It would be great to use rtk with Codex(PR included)

6 participants