Skip to content

Filter the command behind an exec boundary in one place #5051

Open

Description

@BSD-Yassin

Problem

RTK filters a command by the program at the start of the argv. A second shell — docker exec, kubectl exec, ssh, aws ssm, nix develop -c — hides that program, so the bytes that actually reach the model are the inner command's output and they are not filtered.

[hooks] transparent_prefixes is the only general mechanism, and it is an exact string. docker exec mycontainer can be configured; docker exec -it web bash -lc "…", kubectl exec -n prod pod -- …, and sshpass -p … ssh host … cannot. It also injects rtk into the remote argv, which changes the command that runs and fails when rtk is not on the far side.

Per-tool tickets already cover pieces of this (#275, #927, #2057, #2268, #4190). A filter inside each module will not cover the next wrapper (podman, nix, SSM, wsl).

What 1.1.0 does

rtk rewrite on 1.1.0:

Command Rewrite Inner output
docker exec web ls -la /var rtk docker exec … Passthrough. exec is not a filtered docker subcommand.
docker exec -it web bash -lc "ls -la && git status" same, script untouched The local bash -c rewriter does not see a script behind docker exec.
kubectl exec -n prod pod -- ls -la none The kubectl rule is only get|logs|describe|apply.
ssh host "ls -la && df -h" rtk ssh … src/filters/ssh.toml strips banners and caps lines. The ls filter is not applied.
aws ssm send-command … --parameters commands=ls rtk aws … The AWS JSON filter runs on the API response. send-command does not print the remote stdout.
nix develop -c cargo test none No rule.

The local cases that do recurse are a different problem: quoted sh/bash/zsh/fish -c (one level), and the process wrappers timeout, time, nice, nohup. Those still run rtk on this machine.

Proposal

One exec-boundary parser, used by the rewriter and the runner, next to PROCESS_WRAPPERS and parse_shell_wrapper in src/discover/registry.rs.

It recognizes the inner argv and stops when it cannot parse it:

  • docker / podman exec, and docker compose exec, including flags and --
  • kubectl / oc exec … -- <cmd>
  • ssh [flags] host <cmd> and ssh [flags] host -- <cmd>, when the remote command is argv rather than an interactive shell
  • nix develop / nix shell / nix run with -c or --command
  • aws ssm only for an argv-shaped --parameters commands=…

The hook rewrites the outer command to rtk <tool> …. The runner parses the inner argv, selects the filter that rtk git or rtk ls would have used, and applies it to the captured stdout. The remote command is unchanged, so this works when rtk is not installed in the container or on the host.

Fail closed. An unparsed flag, a command buried in a JSON file, start-session, or an interactive SSH session stays on today's path. send-command stdout is an invocation id, so filtering it does not truncate the remote output. nix build is a build log, not an exec boundary.

Injecting rtk after the boundary stays the opt-in transparent_prefixes behavior. It changes the command that runs.

Non-goals

  • A new filter module per tool.
  • Rewriting the inner script of docker exec container bash -lc "…". That is the existing shell-wrapper parser, and it should keep refusing anything it cannot attest.
  • Guessing a filter from output shape when the inner argv is not recognizable. Generic truncation already exists; this is about applying the inner command's own filter.

Next step

Happy to open the PR against develop as soon as this shape suits you. I would keep the first PR to the shared parser and one consumer (so review stays on the boundary, not on every tool at once), with tests for the fail-closed cases above.

Activity

  1. added
    enhancement
    help wanted
    on Nov 9, 2026
  2. rtk-wshm-sync-bot commented on Nov 9, 2026

    @rtk-wshm-sync-bot

    wshm · Automated triage by AI

    🔍 Automated Triage

    ✨ Category feature
    🟡 Priority medium
    🎯 Confidence 78%

    Summary

    Well-researched proposal for a unified exec-boundary parser (docker/kubectl/ssh/nix/aws ssm exec) so inner command output gets filtered consistently instead of per-tool patches; author offers to PR.

    📁 Relevant files
    • src/discover/registry.rs
    • src/filters/ssh.toml

    Suggested Actions

    1. Respond to the author's offer to open a PR against develop for the shared parser
    2. Reference related per-tool tickets Feature request: add rtk rewrite for docker exec #275, kubectl rewrite misses --context flag, exec subcommand, and variable assignments #927, kubectl exec support — truncate output before reaching LLM context #2057, Built-in filters for ssh / dig / lsof / scp (custom TOML filters don't reach the PreToolUse hook) #2268, Hook rewrite coverage: openssl and awk unmapped; sshpass unusable as a transparent prefix #4190 when scoping the first PR
    3. Confirm design: single parse_exec_boundary fn beside PROCESS_WRAPPERS/parse_shell_wrapper in src/discover/registry.rs
    4. Clarify fail-closed test cases (send-command, interactive ssh, nix build) before implementation starts

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

  3. BSD-Yassin commented on Nov 9, 2026

    @BSD-Yassin
    ContributorAuthor

    I tried this against RTK 1.1.0. Same inner commands, stdout only. The last column is the size of this feature's output as a percentage of what RTK 1.1.0 prints.

    nix shell -c is not rewritten in 1.1.0, so that column is the command's own stdout. docker exec and kubectl exec are rewritten, and the inner stdout is passed through. ssh already goes through the banner filter and the line cap.

    Command RTK 1.1.0 This feature % of RTK 1.1.0
    nix shell -c git log -n 120 61,564 chars, 1,463 lines 192 chars, 5 lines 0.3%
    docker exec git log -n 120 61,564 chars, 1,463 lines 192 chars, 5 lines 0.3%
    kubectl exec -- git log -n 120 61,564 chars, 1,463 lines 192 chars, 5 lines 0.3%
    ssh git log -n 120 1,187 chars, 22 lines 225 chars, 5 lines 19.0%
    nix shell -c find (tree, skip .git) 1,788,548 chars, 16,193 lines 2,173 chars, 77 lines 0.1%
    docker exec find 1,383,723 chars, 16,193 lines 1,673 chars, 77 lines 0.1%
    kubectl exec -- find 7,908 chars, 256 lines 1,999 chars, 134 lines 25.3%
    ssh find 16,353 chars, 202 lines 2,384 chars, 74 lines 14.6%
    nix shell -c grep -R 13,089 chars, 112 lines 3,671 chars, 68 lines 28.0%
    docker exec grep -R 9,617 chars, 112 lines 3,485 chars, 68 lines 36.2%
    kubectl exec -- grep -R 10,289 chars, 112 lines 3,521 chars, 68 lines 34.2%
    ssh grep -R 4,291 chars, 41 lines 3,667 chars, 73 lines 85.5%
    nix shell -c journalctl -n 400 59,893 chars, 400 lines 103 chars, 4 lines 0.2%
    ssh journalctl -n 400 21,669 chars, 202 lines 1,044 chars, 18 lines 4.8%

    Rows are not the same corpus, so the percentage is only meaningful inside a row. git log, find, and journalctl are where the cut shows up. A small grep stays close to today's output: over ssh it is 85.5% of the already capped text, and the grouped form uses more lines.

    The same comparison for several commands at once. RTK 1.1.0 leaves the whole stream unfiltered.

    Command RTK 1.1.0 This feature % of RTK 1.1.0
    three kubectl exec -- find 4,934 chars, 414 lines 269 chars, 25 lines 5.5%
    kubectl exec -c -- find in three containers 4,934 chars, 414 lines 304 chars, 25 lines 6.2%
    xargs of kubectl exec -- find 14,469 chars, 1,218 lines 399 chars, 45 lines 2.8%
    ansible ad-hoc find 98,643 chars, 2,687 lines 574 chars, 36 lines 0.6%
    ansible ad-hoc journalctl -n 80 30,395 chars, 164 lines 264 chars, 10 lines 0.9%

    The remote argv is unchanged. The branch is here if you want to try it: https://github.com/BSD-Yassin/rtk/tree/feat/exec-boundary

  4. BSD-Yassin commented on Nov 24, 2026

    @BSD-Yassin
    ContributorAuthor

    Is nobody interested on that one ? I'll gladly take it on my own. As you can see, I'm proposing :

    • rtk into nested commands to clean those too.
    • create a central exec pipe where the parsing happens we can loop on it -> Major change proposal
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:clienhancementhelp wantedpriority:medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions