You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
rtk rewrite "rtk <builtin>" returns unchanged (exit 3) instead of stripping prefix — cd and other builtins silently no-op #2508
rtk rewrite treats a command that already starts with rtk as a valid rewrite target and returns it unchanged with exit 3 ("handled"). When the inner command is a shell builtin (cd, export, source, etc.) this silently breaks the builtin's effect, because the model's manually-prefixed rtk cd /path executes rtk as a subprocess — the directory change is lost when that subprocess exits.
Reproduction
$ rtk rewrite "rtk cd /tmp"rtk cd /tmp # ← same as input, exit 3 ("handled")
$ rtk rewrite "cd /tmp" # exit 1 (passthrough — correct)
$ rtk cd /tmp;pwd/original/dir # ← directory unchanged despite exit 0
Expected behaviour
rtk rewrite "rtk <builtin> ..." should either:
Return passthrough (exit 1) so the shell runs the bare builtin, or
Strip the redundant prefix and return cd /tmp (exit 3)
Either way, the shell builtin should execute in the current process rather than a dead-end subprocess.
Context
The opencode plugin calls rtk rewrite on every bash tool call and replaces the command if the output differs from input. When a model manually prefixes rtk cd (following the "always use rtk" instruction in AGENTS.md), rtk rewrite returns the same string with exit 3 — so the plugin leaves the command as rtk cd /path, which executes with no net directory change.
Observed during GLM-4.7-Flash evaluation (2026-06-19): model ran rtk cd /path && rtk npm init -y, npm init ran in the wrong directory, model then invented a non-existent --workdir flag to compensate.
rtk rewrite returns 'rtk ' unchanged (exit 3) instead of stripping the prefix, causing shell builtins like cd to execute in a subprocess with no effect; PR #2534 is in progress.
This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.
📁 Relevant files
src/rewrite/mod.rs
src/rewrite/builtin.rs
Triaged automatically by wshm · This is an automated analysis, not a human review.
This is actually also a security bug for hooks, allowing the LLM to circumvent its own allowlist:
$ rtk rewrite "rm file"# exit code 1, passthrough, the command is checked against the allowlist
$ rtk rewrite "rtk rm file"
rtk rm file #exit code 3, if rtk is allowed 'rm' isn't checked against the allowlist
Hooks can't just test for exit code 3, because the LLM might correctly want to invoke rtk ls -la instead of relying on the hook.
Closing as a duplicate of #3969, which carries the full picture — this report, #3331, the three instruction blocks that generate these invocations, and the wording fix.
The rtk rewrite change proposed here (and implemented in #2534) was rejected: stripping the prefix inverts the direction of every rewrite, and since the permission verdict is computed on the raw input while the rewritten string is what gets emitted, an explicitly denied command comes back stamped "allow". Reproduction in #3969.
@rmsc — your allowlist point is now #3970, filed as its own issue precisely so it does not close with this one. It has your rtk rm file case as instance 1, plus the second instance found while reviewing #2534, and the reason each of the obvious fixes (gate on exit 3, strip unconditionally) does not work.
Worth noting the symptom is worse than "silently no-op" as written above: rtk execs a binary named cd, so the ENOENT takes the rest of the compound with it.
$ rtk cd /tmp &&echo REACHED[rtk: No such file or directory (os error 2)] # exit 127, REACHED never prints
Activity
pszymkowiak commentedon Jun 25, 2026
🔍 Automated Triage
bughighSummary
rtk rewrite returns 'rtk ' unchanged (exit 3) instead of stripping the prefix, causing shell builtins like cd to execute in a subprocess with no effect; PR #2534 is in progress.
📁 Relevant files
src/rewrite/mod.rssrc/rewrite/builtin.rsTriaged automatically by wshm · This is an automated analysis, not a human review.
rmsc commentedon Jun 27, 2026
This is actually also a security bug for hooks, allowing the LLM to circumvent its own allowlist:
Hooks can't just test for exit code 3, because the LLM might correctly want to invoke
rtk ls -lainstead of relying on the hook.fix(rtk): fix OpenCode plugin, Maven support, loop/builtin warnings
fix(rewrite): strip ctxcrl/rtk prefix on shell builtins, incl. compou…
KuSh commentedon Sep 9, 2026
Closing as a duplicate of #3969, which carries the full picture — this report, #3331, the three instruction blocks that generate these invocations, and the wording fix.
The
rtk rewritechange proposed here (and implemented in #2534) was rejected: stripping the prefix inverts the direction of every rewrite, and since the permission verdict is computed on the raw input while the rewritten string is what gets emitted, an explicitly denied command comes back stamped"allow". Reproduction in #3969.@rmsc — your allowlist point is now #3970, filed as its own issue precisely so it does not close with this one. It has your
rtk rm filecase as instance 1, plus the second instance found while reviewing #2534, and the reason each of the obvious fixes (gate on exit 3, strip unconditionally) does not work.Worth noting the symptom is worse than "silently no-op" as written above:
rtkexecs a binary namedcd, so the ENOENT takes the rest of the compound with it.