Skip to content

feat: add BeforeTool hook to intercept bash commands before execution #531

@ousamabenyounes

Description

@ousamabenyounes

Summary

Vibe currently has no mechanism to intercept or transform bash commands before they are executed. Adding a BeforeTool hook (similar to Gemini CLI's BeforeTool hook) would allow external tools to transparently rewrite commands before execution.

Use Case: RTK (Rust Token Killer)

RTK is a CLI proxy that saves 60-90% of LLM tokens by filtering and compressing command output before it reaches the model context. It works by rewriting commands:

git status     → rtk git status      # ~70% fewer tokens
ls src/        → rtk ls src/         # ~60% fewer tokens
cargo test     → rtk cargo test      # ~90% fewer tokens
gh pr list     → rtk gh pr list      # ~87% fewer tokens

RTK already has transparent hook support for:

  • Claude Code — via PreToolUse hook in settings.json
  • Gemini CLI — via BeforeTool hook in settings.json

For Vibe, the current workaround is a system prompt instructing the model to use rtk commands. This is unreliable — the model sometimes ignores it.

Proposed API

In ~/.vibe/config.toml or a new hooks section:

[hooks]
before_tool = "~/.vibe/hooks/before-tool.sh"

The hook receives tool call info via stdin (JSON) and can return a rewritten command or allow/block execution:

{
  "tool": "bash",
  "input": { "command": "git status" }
}

Output (stdout):

{ "action": "rewrite", "input": { "command": "rtk git status" } }

or

{ "action": "allow" }

Reference Implementations

Impact

This would make Vibe a first-class citizen in token-optimized AI workflows, and would enable the RTK integration to work transparently without relying on model instruction-following.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions