Skip to content

rewrite: declines env-wrapped (env -u) and sudo-prefixed commands #4099

Open

Description

@anchapin

Summary

rtk rewrite correctly handles most wrapper prefixes (assignment prefixes, nohup, time, compound && chains), but declines to rewrite (returns empty output) for two common forms:

  1. env -u VAR <heavy-cmd> — environment-scrubbed invocations
  2. sudo <heavy-cmd>

Repro (rtk 0.49.0)

$ rtk rewrite 'env -u GH_TOKEN gh pr list'
(empty output — declined)

$ rtk rewrite 'env GH_TOKEN=x gh pr list'
env GH_TOKEN=x rtk gh pr list        # works

$ rtk rewrite 'sudo git status'
(empty output — declined)

$ rtk rewrite 'nohup cargo test &'
nohup rtk cargo test &               # works

$ rtk rewrite 'time git status'
time rtk git status                  # works

Impact

In a 14-day audit of one opencode install (49.5k bash calls), env -u <cmd> appeared 587 times — each declined call runs completely uncompressed (~1KB+ raw output per call, multiplied by LLM context replay).

Expected

Rewrite through the wrapper: env -u GH_TOKEN rtk gh pr list and sudo rtk git status (assuming rtk is on the secured PATH for sudo, or documenting why it is skipped).

Activity

  1. added
    bug
    good first issue
    on Sep 17, 2026
  2. rtk-wshm-sync-bot commented on Sep 17, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟡 Priority medium
    🎯 Confidence 87%

    Summary

    rtk rewrite fails to descend through env -u and sudo wrapper prefixes, leaving high-frequency wrapped invocations (587 occurrences of env -u in a 14-day audit) uncompressed; extend the wrapper-prefix parser to handle these two forms like it already does for nohup/time/env VAR=x.

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

    📁 Relevant files
    • src/rewrite.rs

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

  3. taljeon commented on Sep 18, 2026

    @taljeon

    I can take the env -u portion of this.

    I’ll add red-first coverage for env -u VAR <supported-command> and make classification and rewriting use the same wrapper boundary so the prefix is preserved. I’ll also pin the existing sudo behavior rather than changing it: #2810 deliberately stopped emitting sudo rtk … because that can fail under secure_path or run RTK’s own side effects as root, while #146 tracks the safe rtk sudo … design. I’ll reference this PR as a partial fix instead of claiming the separate sudo feature is complete.

    AI disclosure: I’m using OpenAI Codex (gpt-5.6-sol) to assist with source inspection, implementation, and verification. I’ll review the exact diff, use my DCO-signed GitHub noreply identity, and report the checks actually run.

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:clibuggood first issuepriority:medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions