Repository navigation
Description
What problem are you trying to solve?
Every shell command the agent runs lands in the model's context in full, and most of that output is noise: full git log bodies, passing test scaffolding, ls -R trees, build logs. Tools like RTK exist to compress that output before the model sees it (README claims 60-90% smaller output on common dev commands), and its Claude Code integration works by rewriting the command itself to rtk <cmd> via a PreToolUse hook.
In Freebuff this does not work automatically. I installed RTK, ran rtk init -g, and confirmed the hook is registered and functional in ~/.claude/settings.json, but the agent's Bash tool never consults it:
rtk init --showreports the hook as OK.- Piping the hook payload manually returns a valid rewrite:
{"hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecisionReason":"RTK auto-rewrite","updatedInput":{"command":"rtk git status"}}} - But commands issued through the agent's Bash tool still execute verbatim (
git status, notrtk git status), andrtk gain --historyshows no entries for them, while other agents on the same machine do show entries.
So a user can do all the setup the tool documents and still get none of the benefit. The only workarounds today are prefixing every command by hand (error-prone, and only as good as the model's discipline) or a BASH_ENV shim that shadows git/grep/ls with shell functions (fragile: misses absolute paths, subshells, and builtins).
What would you like to happen?
Add an opt-in pre-execution hook stage to the Bash tool, modeled on Claude Code's PreToolUse contract:
- Before spawning
bash -c <command>, if a hook is configured, send a JSON payload on stdin:{"tool_name":"Bash","tool_input":{"command":"git status"},"cwd":"/path/to/project"} - If the process exits 0 and stdout contains
hookSpecificOutput.updatedInput.command, execute that command instead of the original. - Otherwise execute the original command unchanged. A non-zero exit, malformed JSON, or a timeout must degrade to "run the original" — never block or fail the tool.
- Record the rewritten command somewhere inspectable (the tool call display or an audit log) so the transcript shows what actually ran.
Configuration could mirror existing conventions: a hooks key in the user/project config file, with the command path, a small timeout (e.g. 2s), and an enable/disable switch. Load only from trusted, explicit config — not from a hook discovered automatically in the repo.
Security considerations (this is the part worth designing carefully)
A hook is arbitrary code execution on every tool call, so I'd suggest:
- Off by default; enabling requires an explicit config edit and, for project-level hooks, an approval prompt.
- A hard timeout and no stdin beyond the payload.
- Hook stderr captured for diagnostics but not injected into the model's context.
- A documented way to bypass per call (
RTK_DISABLED=1 <cmd>, or a tool argument) and to inspect what was rewritten.
RTK is a good test case because its hook is rewrite-only: it never executes the command itself, just emits JSON. That keeps the blast radius small and makes the feature useful beyond RTK (any command-normalizing tool).
Why this is not just "tell the agent to prefix"
CLAUDE.md-style instructions already work and are the documented fallback for instruction-based agents (Codex, Cursor). But they are advisory only: the model can forget, and it cannot know which commands have filters. An execution-layer hook applies uniformly and survives long sessions.
Area
CLI (terminal client)
Contribution
I would be willing to open a PR for this.
Activity