Skip to content

Built-in filters for ssh / dig / lsof / scp (custom TOML filters don't reach the PreToolUse hook) #2268

Open

Description

@Interstellar-code

Summary

Request built-in filters for ssh, dig, lsof, and scp.

Why custom filters don't cover this

The Claude Code auto-rewrite hook (zap hook claude) only auto-prefixes commands that have a built-in filter. Commands handled only by a user-defined filters.toml are not rewritten by the hook:

$ zap hook check "ssh host docker ps"
No rewrite for: ssh host docker ps

So custom TOML filters require explicit rtk ssh ... invocation (+ zap trust) and deliver zero automatic savings through the hook. The only path to automatic interception is a built-in filter.

Evidence these are high-impact

From zap discover on a real workflow (server/infra management, 30 days):

Command Count
ssh 547 (321 + 117 + 87 + 22 across hosts)
dig +short 44
lsof 24
scp 7

ssh is the single most-used command and is entirely unhandled.

Suggested behavior

  • ssh: strip ANSI + login/locale noise (Warning: Permanently added, manpath: can't set the locale, Pseudo-terminal will not be allocated, Connection to X closed), then apply the inner command's filter when recognizable (e.g. ssh host "docker ps" → docker filter), else dedupe/cap. The remote command output is where the tokens are.
  • scp: strip transfer progress bars / ETA lines; success-only on clean transfer.
  • dig: keep answer section, drop ;; comment lines and blanks.
  • lsof: strip blank lines, cap long tabular output.

Alternative ask

If built-ins aren't desired, expose a config knob (e.g. [hooks] include_commands = ["ssh", ...]) so user TOML filters can opt into the auto-rewrite hook. Today only exclude_commands and transparent_prefixes exist.

Thanks — great tool.

Activity

  1. added
    enhancement
    help wanted
    on Jun 4, 2026
  2. pszymkowiak commented on Jun 4, 2026

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    ✨ Category feature
    🟠 Priority high
    🎯 Confidence 87%

    Summary

    Feature request for built-in filters for ssh/dig/lsof/scp; strong usage evidence (ssh is #1 unhandled command at 547 invocations/month) and well-specified behavior; also requests fallback config knob to opt user TOML filters into the auto-rewrite hook


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

  3. axelray-dev commented on Jun 4, 2026

    @axelray-dev
    Contributor

    I looked into this and the built-in filter pattern seems straightforward for dig, lsof, and scp: add discovery rules, a small filter module for each command, dispatch wiring, and focused tests.

    ssh looks like the one design question. A basic filter could strip ANSI/login/connection noise, but the issue also mentions applying the inner command's filter for something like ssh host "docker ps". That seems like it may need recursive command classification/dispatch rather than just output cleanup.

    Would you prefer this to be split into smaller PRs, for example:

    1. dig, lsof, and scp as simple output filters
    2. ssh noise stripping
    3. remote-command filter dispatch as a follow-up if desired

    Or would you rather keep all four commands together in one PR?

  4. JayTheriau commented on Aug 11, 2026

    @JayTheriau

    Confirming this is still the case on rtk 0.43.0 (macOS, native-binary hook rtk hook claude), with two more commands and some measurements.

    Same symptom, different tools

    flyctl and blender are my two heaviest unfiltered commands (227 and 99 invocations in 30 days). I wrote user-global TOML filters for both in ~/Library/Application Support/rtk/filters.toml. rtk verify passes (154/154), and the filters work correctly when invoked explicitly:

    $ rtk blender -b -P render.py     # 63 lines -> 1
    $ rtk flyctl deploy               # 65 lines -> 3
    

    Both keep the diagnostic line and drop only the progress noise (Fra:, layer pulls, MB/MB), so the filters do exactly what a built-in would.

    But the hook never routes to them:

    $ rtk rewrite "flyctl deploy"     # (no output)
    $ rtk rewrite "blender -b -P x.py"  # (no output)
    $ rtk rewrite "ps -Ao pid,time"   # rtk ps -Ao pid,time   <- shipped command, rewritten
    

    So the savings are real but only reachable by typing rtk manually — which an agent won't do reliably, and which is the entire point of the hook.

    Why the config knob doesn't help today

    rtk config currently exposes only:

    [hooks]
    exclude_commands = []
    transparent_prefixes = []

    Both subtract. There is no way to add a command to the rewrite set, so a user TOML filter is unreachable from the hook by construction.

    Suggestion

    Rather than adding built-ins case by case (ssh/dig/lsof/scp here, flyctl/blender for me, and #3490 brew / #3487 make / #3491 sort elsewhere), the general fix is to let the rewriter consult user TOML filters: if a filter's match_command matches, rewrite to rtk <cmd>. That closes this class of issue once, and every future custom filter becomes hook-reachable for free.

    include_commands (#2231) would also solve it and is arguably simpler, but it requires the user to maintain the list in two places — once as a filter, once as an allowlist entry — where match_command already carries that information.

    Happy to test a build against the flyctl/blender filters above if that's useful.

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:high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions