Skip to content

feat(rewrite): honour RTK_DISABLED=1 from the environment - #3917

Open
zerone0x wants to merge 2 commits into
rtk-ai:developfrom
zerone0x:feat/rewrite-rtk-disabled-env
Open

zerone0x wants to merge 2 commits into
rtk-ai:developfrom
zerone0x:feat/rewrite-rtk-disabled-env

Conversation

@zerone0x

@zerone0x zerone0x commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

Summary

  • rtk rewrite now honours RTK_DISABLED=1 exported in its environment: the outcome is a passthrough (exit 1, nothing on stdout), decided before the permission settings, the lexer and the registry are consulted. Until now only the RTK_DISABLED=1 <cmd> prefix inside the command text was recognised: RTK_DISABLED=1 rtk rewrite "git status" still printed rtk git status and exited 3.
  • Why this entry point: rtk rewrite is the single source of truth that every shipped hook and plugin (the Claude and Cursor shell hooks, OpenCode, Pi/OMP, Hermes) and every embedding host calls, so one switch covers all of them. Today only the Pi extension checks process.env.RTK_DISABLED on its own (hooks/pi/rtk.ts); that check keeps working and becomes redundant rather than required, and a host that spawns rtk rewrite directly no longer has to reimplement it before every spawn.
  • How it composes: the in-command prefix keeps its per-segment registry handling and stderr warning (Bug: RTK_DISABLED=1 is ignored by rtk rewrite #345); the exported form applies to the whole invocation and prints nothing. Only the exact value 1 counts, as with RTK_TELEMETRY_DISABLED and RTK_HOOK_AUDIT, so a parent that exported it can hand one child RTK_DISABLED=0 to re-enable it. Every other exit code is unchanged, no file I/O is added to the rewrite path, and the shipped hook scripts are untouched.
  • Not covered here: the native rtk hook <agent> entry points in hook_cmd.rs call the registry directly rather than going through rewrite_cmd, so they still ignore the variable. That is the exact case reported in Feature request: disable rtk hook for one process tree #3791 and is left for a follow-up.
  • Tests: the flag is threaded into evaluate as a parameter (the evaluate_with_verdict pattern from Rewrite tests fail when local permission settings allow git commands #3146), so the unit tests never touch the process environment. A small integration test spawns the binary to pin the exit-code/stdout contract and the "only 1 counts" rule. The existing registry subprocess test now clears RTK_DISABLED for its child, so a developer's own export cannot mask the prefix warning it asserts on.

Refs #1153 #3791

#1167 is the earlier attempt at the same feature; it calls process::exit(1) at the top of run() and has been conflicting since April. This PR keeps the decision in the testable path instead.

Test plan

  • cargo fmt --all -- --check; cargo clippy --all-targets (clean); soft lints -W clippy::unwrap_used -W clippy::panic -W clippy::expect_used (no new warnings)
  • cargo test --all with an isolated HOME/RTK_DB_PATH/RTK_TEE_DIR: the full suite passes (3124 in the main crate plus the integration suites), including the 4 new unit tests and the 2 new end-to-end tests
  • Manual: RTK_DISABLED=1 ./target/debug/rtk rewrite "git status"; echo $? prints nothing and 1; without the variable, or with RTK_DISABLED=0, it prints rtk git status and 3; rtk rewrite "RTK_DISABLED=1 git status" still exits 1 with the existing stderr warning
  • Through the Claude shell hook: a git status PreToolUse payload piped into RTK_DISABLED=1 bash hooks/claude/rtk-rewrite.sh emits nothing and exits 0; without the variable the rewrite is emitted
  • hooks/claude/test-rtk-rewrite.sh against this build: 57/66 pass and the RTK_DISABLED prefix section passes; the same 9 cases (unrelated rg/pipeline expectations and the audit-log cases the v3 script does not implement) fail identically against the 0.48.0 release binary

`rtk rewrite` only recognised the `RTK_DISABLED=1 <cmd>` prefix inside the
command text and ignored the variable in its own environment, so every hook
and embedding host had to check it before spawning rtk. The exported form is
now a passthrough (exit 1, no output) decided before the permission settings,
the lexer and the registry are consulted. The prefix form and every other
exit code are unchanged, and only the exact value `1` counts.

Refs rtk-ai#1153
Refs rtk-ai#3791
Earlier hook-level attempt: rtk-ai#1167

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FDTLBQWy4T7E9vE7ozX7r4
zerone0x added a commit to zerone0x/rtk that referenced this pull request Sep 7, 2026
…tk-ai#3917

Tell the host to check RTK_DISABLED itself before spawning `rtk rewrite`,
state that releases up to 0.48.0 honor it only as an in-command prefix,
and link rtk-ai#3917, which makes `rtk rewrite` honor the exported
variable too. The note stays true before and after that PR lands.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FDTLBQWy4T7E9vE7ozX7r4
Review follow-up: with the variable exported the exclusions and transparent
prefixes are never consulted, so `run` no longer loads them and a disabled
invocation costs one environment lookup and no file I/O. The parameterised
`evaluate` path and its tests are unchanged.

Refs rtk-ai#1153

Co-Authored-By: Claude Fable 5.1 <[email protected]>
Claude-Session: https://claude.ai/code/session_01FDTLBQWy4T7E9vE7ozX7r4
zerone0x added a commit to zerone0x/rtk that referenced this pull request Nov 2, 2026
…tk-ai#3917

Tell the host to check RTK_DISABLED itself before spawning `rtk rewrite`,
state that releases up to 0.48.0 honor it only as an in-command prefix,
and link rtk-ai#3917, which makes `rtk rewrite` honor the exported
variable too. The note stays true before and after that PR lands.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant