Skip to content

rewrite re-spells zsh's &! as & !, so under zsh the command after it no longer runs #4918

Closed

Description

@KuSh

What happens

At top level the rewrite splits zsh's background-and-disown operator &! into & and !, then re-joins it spaced:

$ rtk rewrite "git status &!git log"
rtk git status & !git log          (exit 0; same on rtk 1.1.0 and develop 4b4bc40d9)

In zsh the two spellings do different things. &! is one operator, so what follows it runs; spaced, !git is a command name:

$ zsh -c 'echo a &!echo HIT'
a
HIT
$ zsh -c 'echo a & !echo HIT'
a
zsh:1: command not found: !echo

So when the agent's shell is zsh, the rewritten command silently drops the second command. In bash and dash both spellings fail the same way (!echo: command not found), so nothing changes there.

Scope

Inside a zsh -c or fish -c script the rewrite already refuses these pairs (disown_pair / opens_disown_pair, #4126; #4517 tracks cleanups there). The top-level line is read as POSIX, so the same check is not applied there. &| is kept as written (rtk git status &|git log).

Fix direction

Either keep the pair glued when re-emitting a segment boundary that a ! follows, or have the top-level rewrite refuse a line that opens a disown pair, as the wrapped-script path does.

The permission check has to move with it. With deny: ["Bash(rm:*)"] and allow: ["Bash(*)"], develop answers git status &!rm -rf /tmp/example with an allow and the rewrite rtk git status & !rm -rf /tmp/example. Only the re-spelling keeps zsh from running rm there. Once the pair stays glued, the deny scan must read the command after &! as its own segment at top level too. The shell is not known at top level, and bash and sh never run a glued !rm, so a boundary that ignores the dialect costs nothing there.

zsh 5.9.2 (Docker), rtk built from develop 4b4bc40 and rtk 1.1.0.

Activity

  1. rtk-wshm-sync-bot commented on Nov 1, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    🐛 Category bug
    🟠 Priority high
    🎯 Confidence 90%

    Summary

    Top-level rewrite re-spells zsh's &! disown operator as & !, silently dropping the following command under zsh and also weakening the deny-scan security boundary.

    📁 Relevant files
    • src/rewrite.rs

    Suggested Actions

    1. Reuse the existing disown_pair/opens_disown_pair check (feat(rewrite): rewrite inner commands of a quoted fish -c wrapper #4126, disown_pair: unreachable Arg arm, a redundant second call, and the &! rule applied to fish where both spellings agree #4517) for the top-level POSIX rewrite path
    2. Ensure the deny-command scan treats the segment after a glued &! as its own command at top level
    3. Add a regression test: git status &!rm -rf /tmp/example with deny:["Bash(rm:*)"] must be denied, not rewritten with a…
    4. Cross-check against docs(openclaw): "What's NOT rewritten" says |, && and ; commands are left alone; rtk rewrite rewrites them #4900 (docs on what's not rewritten) since operator-splitting behavior overlaps

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

  2. KuSh commented on Nov 8, 2026

    @KuSh
    CollaboratorAuthor

    The re-spelling is fixed in v1.2.0. Since #4132 the rewrite copies the text between commands byte for byte instead of rebuilding each operator with spaces, so rtk rewrite "git status &!git log" now returns rtk git status &!git log, and zsh runs both commands as typed (checked with zsh 5.9.2). &| is kept as written too.

    A correction to the report above: develop at 4b4bc40 already kept the pair glued (rebuilt and checked); only v1.1.0 re-spelled it.

    The permission-scan point in "Fix direction" is being picked up separately with the lexer work, so closing this one.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions