Skip to content

Config-driven routing for package-manager script commands (e.g. pnpm scripts) #2358

Closed as duplicate

Description

@ckir

Observed with: rtk 0.42.3, Claude Code 2.1.169 (PreToolUse hook with updatedInput).

Summary

The rtk hook claude PreToolUse hook auto-rewrites recognized commands to their rtk handler (git status → rtk git status, vitest run → rtk vitest, pnpm exec vitest → rtk vitest). But it does not route package-manager script runs such as:

  • pnpm verify:fast / pnpm verify:full
  • pnpm --filter <pkg> test / pnpm test-all
  • pnpm typecheck-all / pnpm lint-all / pnpm build-all

…because the underlying tool (vitest / biome / tsc) is hidden behind the npm-script name, so rtk can't detect it from the command string. In a monorepo these script commands are the single largest source of uncompressed output (full vitest/biome/tsc logs).

What I tried (and why it doesn't solve it)

Mechanism Result
Custom filters.toml [filters.*] with match_command = "^pnpm…" rtk verify passes, but the hook never routes pnpm verify:fast through rtk, so the filter only applies on the explicit rtk pnpm … path — not automatically.
[hooks].transparent_prefixes = ["pnpm verify:fast", …] No effect on routing.
[hooks].exclude_commands Only subtracts from routing; can't add.

Reproduction (hook returns empty = not routed):

```bash
printf '%s' '{"tool_name":"Bash","tool_input":{"command":"pnpm verify:fast"}}' | rtk hook claude

(no output)

printf '%s' '{"tool_name":"Bash","tool_input":{"command":"vitest run"}}' | rtk hook claude

{"hookSpecificOutput":{"...","updatedInput":{"command":"rtk vitest"}}}

```

Proposed feature

A config-driven route table mapping a command regex to an rtk handler (or a named custom filter), so the hook rewrites matching commands accordingly. For example:

```toml
[[hooks.route]]
match = "^pnpm\b.*\b(test|test-all)\b"
handler = "vitest" # route output through rtk's vitest failure-extractor

[[hooks.route]]
match = "^pnpm\b.\bverify:(fast|full)\b"
handler = "pnpm-checks" # a named [filters.
] entry
```

Behavior: when the hook matches match, it rewrites the command to route through the named handler/filter (e.g. wraps as rtk pnpm … or pipes output through the filter via rtk pipe), exactly as the built-in routes do today.

Why config (not behavioral)

The whole value of the hook is that the agent doesn't have to remember to prefix rtk — it works deterministically, including inside subagents (the hook fires for subagent tool calls). Telling agents to manually run rtk pnpm test reintroduces the exact unreliability the hook exists to remove (subagents especially won't honor it). A config route keeps enforcement deterministic.

Activity

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

    @pszymkowiak
    Collaborator

    wshm · Automated triage by AI

    🔍 Automated Triage

    ✨ Category feature
    🟡 Priority medium
    🎯 Confidence 91%

    Summary

    Feature request: add a config-driven [[hooks.route]] table so pnpm/npm script commands can be regex-matched and routed through rtk handlers in the PreToolUse hook, closing the gap where script-wrapped tools (vitest, tsc, biome) are invisible to the existing auto-rewrite logic.


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

  3. triggerhive-gijs commented on Aug 10, 2026

    @triggerhive-gijs

    Confirming this is still the case on rtk 0.45.0, independently reproduced while chasing a related problem.

    A user-global ~/.config/rtk/filters.toml and a project-local .rtk/filters.toml (the latter trusted via rtk trust -y) both have no effect on routing:

    [filters.pnpm-typecheck]
    match_command = "^pnpm\\s+typecheck"
    
    $ rtk trust -y          # exit 0
    $ rtk rewrite "pnpm typecheck"
                            # exit 1, no output
    

    So match_command selects which filter applies once a command is already on the rtk … path; it cannot put it there. That matches your table exactly, and it means the two mechanisms that look like they should work (filters.toml, [hooks].transparent_prefixes) are both dead ends for this.

    One data point on why the impact is larger than it looks: on a Nuxt project, pnpm typecheck emits 2673 bytes of duplicated-import warnings on a fully green run, while the equivalent filtered path emits 28. That is 99% of a command an agent runs many times per session, and it is pure noise on success.

    I worked around it with a small PreToolUse hook ordered ahead of rtk-rewrite.sh that maps the bare command onto the existing handler. That works, but it is exactly the route table you are proposing, hand-rolled per script name, which does not scale past a handful of commands. A config-driven [[hooks.route]] as you sketched would remove the need for it.

  4. KuSh commented on Sep 13, 2026

    @KuSh
    Collaborator

    Closing as a duplicate of #1684, which asks for the same thing in a more general form: user-defined rewrite rules in config.toml that are merged into the rewrite registry, so a pattern such as pnpm verify:fast can be routed onto an rtk handler instead of running unfiltered. Your reproduction and the measured impact on a Nuxt typecheck are the strongest case for it, so please repost them on #1684 and follow up there.

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:cliarea:configenhancementhelp wantedpriority:medium

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions