Skip to content

Agent guidance tells agents to prefix shell builtins with rtk, and promises it is safe — rtk cd exits 127 and aborts the compound #3969

Closed

Description

@KuSh

Summary

Three instruction blocks tell agents to prefix every shell command with rtk and
promise the prefix is always safe. It is not: for a shell builtin, rtk execs a binary
by that name, gets ENOENT, and exits 127 — taking 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

Reported twice from real sessions, and each time the agent drew the wrong conclusion:

The three places that say it

source wording
hooks/rtk-awareness-full.md:3-6 "Prefix every shell command with rtk… Commands RTK has no filter for run as-is, so the prefix is always safe."
RTK_INSTRUCTIONS (src/hooks/init.rs:241), live via rtk init --claude-md "Always prefix commands with rtk. If RTK has a dedicated filter, it uses it. If not, it passes through unchanged. This means RTK is always safe to use."
COPILOT_INSTRUCTIONS (src/hooks/init.rs:5925), written to .github/copilot-instructions.md "Always prefix shell commands with rtk"

Also docs/guide/getting-started/configuration.md:69, which describes the full level as
"prefix every command with rtk".

"If not, it passes through unchanged" is the precise falsehood — there is no passthrough
for a builtin, because there is no binary to pass through to.

Hook-based agents at the default awareness.level are not affected: hooks/rtk-awareness.md
carries no prefixing rule at all. The exposure is the full level — which per
hooks/README.md:18 the hookless agents (cline, kilocode, windsurf) get unconditionally,
having no hook to rewrite for them — plus the two legacy blocks above.

Fix: scope the rule to external programs

For hooks/rtk-awareness-full.md:3-6:

-Prefix every shell command with `rtk`: `rtk git status`, `rtk cargo test`,
+Prefix external programs with `rtk`: `rtk git status`, `rtk cargo test`,
 `rtk npm run build`, `rtk ls src/`. Keep the prefix inside chains:
-`rtk git add . && rtk git commit -m "msg"`. Commands RTK has no filter for
-run as-is, so the prefix is always safe.
+`rtk git add . && rtk git commit -m "msg"`. Programs RTK has no filter for
+run as-is, so the prefix is safe for anything you would run from `PATH`.
+
+Do not prefix shell builtins or keywords — `test`, `[`, `read`, `cd`, `echo`,
+`export`, `eval`, `source`, `printf`. RTK defines subcommands named for some of
+them that do not mean what the builtin means.

The same wording change applies to RTK_INSTRUCTIONS and COPILOT_INSTRUCTIONS. A fix to
rtk-awareness-full.md alone leaves Copilot and --claude-md installs broken, and
test_awareness_activation_rule_only_in_full pins only the awareness files, so nothing
catches the omission.

Naming the builtins is what makes it work for the cases removal cannot reach: read and
help have no binary to fall through to, so no amount of routing fixes them.

While the file is open: high and full also advertise rtk gain, and
RTK_INSTRUCTIONS:275 advertises rtk test <cmd>. Meta commands are for humans, not
agents — worth dropping against the asserted line budget, but that is a simplification,
not part of this fix.

Why not fix it in the rewrite engine

#2534 proposed stripping the redundant prefix during rewrite (rtk cd /tmp → cd /tmp).
It works for its twelve names, but it opens a permission bypass and was rejected.

Every hook computes the permission verdict on the raw input and emits the rewritten
string — decide_from_verdict(cmd, permissions::check_command_for(cmd, host))
(src/hooks/hook_cmd.rs:274). That is safe only while a rewrite goes foo … → rtk foo …,
so both strings share a prefix. Stripping inverts the direction, and
command_matches_pattern is a word-boundary prefix match, so Bash(source:*) never matches
rtk source x.

With permissions: {"allow": ["Bash(rtk:*)"], "deny": ["Bash(source:*)"]}:

$ echo '{"tool_name":"Bash","tool_input":{"command":"rtk source /tmp/evil.sh"}}' | rtk hook claude
# develop:  (no output — Defer; the host applies its own rules)
# with #2534: {"updatedInput":{"command":"source /tmp/evil.sh"},"permissionDecision":"allow"}

An explicitly denied command, emitted with an explicit auto-allow. Bash(rtk:*) is the
obvious workaround for prefixed-command prompt spam, so this is not a contrived config.

It also would not have helped the reporters: hookless agents are exactly the ones getting
rtk-awareness-full.md, and they never call rtk rewrite at all.

For anyone who revives the idea: test, read and env are shell builtins and real
RTK subcommands. Stripping any of them silently changes which program runs.

Optional: a better error than ENOENT

#3331's misdiagnosis came from the bare [rtk: No such file or directory (os error 2)].
When rtk is handed a known builtin name, saying so — "cd is a shell builtin; drop the
rtk prefix"
— costs no permission surface and stops the "rtk isn't available" conclusion.

Related

Activity

  1. rtk-wshm-sync-bot commented on Sep 9, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 94%

    Summary

    Agent guidance in three instruction blocks tells agents to unconditionally prefix all shell commands (including builtins like cd, read, eval) with rtk, which exits 127 for builtins and breaks compound commands — scope the rule to external/PATH programs and explicitly exclude builtins in rtk-awareness-full.md, RTK_INSTRUCTIONS, and COPILOT_INSTRUCTIONS.

    This looks like a simple fix that could be auto-resolved. Repo maintainers can use /wshm fix to attempt it.

    📁 Relevant files
    • hooks/rtk-awareness-full.md
    • src/hooks/init.rs
    • docs/guide/getting-started/configuration.md

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

  2. KuSh commented on Sep 27, 2026

    @KuSh
    CollaboratorAuthor

    Two more places carry the unconditional "always prefix with rtk" wording and give no guidance for a command that starts with an environment assignment or env: the Copilot instructions at src/hooks/init/copilot.rs:41 ("Always prefix shell commands with rtk") and the legacy --claude-md Golden Rule at src/hooks/init/mod.rs:178. #3372 replaced the per-agent rule files with the shorter awareness text, but these two were not part of it. #1606 has the runtime side (env VAR=val cmd); the wording side belongs here. Seen while reviewing #3706.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:cliarea:docsbugpriority:high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions