CLI proxy that reduces LLM token usage by 60-90%. Declarative YAML filters for Claude Code, Cursor, Copilot, Gemini. rtk alternative in Go.
CLI proxy that reduces LLM token usage by 60-90%. Declarative YAML filters for Claude Code, Cursor, Copilot, Gemini. rtk alternative in Go.
CLI proxy that filters shell output before it reaches your AI coding assistant's context window. Works with Claude Code, Cursor, Copilot, Gemini CLI, Windsurf, Cline, Codex, Pi, Grok Build, Kilo Code, Antigravity, OpenCode, OpenClaw, Aider, and any tool that runs shell commands.
AI coding agents burn tokens on verbose shell output that adds zero signal. A passing go test produces hundreds of lines the LLM will never use. git log dumps full commit metadata when a one-liner per commit suffices.
snip sits between your AI tool and the shell, filtering output through declarative YAML pipelines. Write a YAML file, drop it in a folder, done. The extensible LLM token optimizer: filters are YAML data files, not compiled code.
…Measured on a real Claude Code session — 128 commands, 2.3M tokens saved.
# Quick install (macOS/Linux)
curl -fsSL https://raw.githubusercontent.com/edouard-claude/snip/master/install.sh | sh
# Or via Homebrew
brew install edouard-claude/tap/snip
# Or with Go
go install github.com/edouard-claude/snip/cmd/snip@latest
# Then hook into Claude Code
snip init
# That's it. Every shell command Claude runs now goes through snip.Before — Claude Code sees this (275 tokens):
…After — snip returns this (8 tokens):
1125 passed, 0 failedThat's 97% fewer tokens, measured on this very repository. The filter injects -json and counts individual test results, so the LLM gets more signal — 1125 tests passed, not just 18 packages — in a fraction of the space.
…bash snip init --agent grok --mode prompt # creates AGENTS.md snip init --agent grok --uninstall # remove the hook
`AGENTS.md` is shared with Codex, so `--uninstall` never deletes it; it prints a reminder instead.
### Codex
```bash
snip init --agent codexThis patches ~/.codex/hooks.json with a native PreToolUse hook. Supported shell commands are transparently rewritten through snip with Codex's updatedInput contract, so the model runs commands normally and sees only the filtered output.
For safety, mixed commands containing unsupported segments, pipelines with uninspected tails, and command substitutions pass through unchanged so Codex keeps its native permission flow.
Use snip proxy -- when full unfiltered output is required.
snip init --agent codex --uninstallCodex CLI 0.131.0 or later is required for PreToolUse input rewriting. For older releases, use the legacy project-scoped prompt integration:
snip init --agent codex --mode promptsnip init --agent copilotThis patches ~/.copilot/hooks/snip.json with a native preToolUse hook that rewrites supported commands transparently, like Claude Code.
Prefer prompt injection instead? Use the legacy project-scoped mode:
snip init --agent copilot --mode prompt # creates .github/copilot-instructions.md
snip init --agent copilot --uninstall # remove the hookPreToolUse is supported. This patches ~/.gemini/config/hooks.json.
snip init --agent antigravitysnip init --agent gemini # creates GEMINI.md
snip init --agent windsurf # creates .windsurfrules
snip init --agent cline # creates .clinerules
snip init --agent kilocode # creates .kilocode/rules/snip-rules.mdThese agents use prompt injection: a markdown file instructs the LLM to prefix shell commands with snip. Project-scoped (created in the current directory).
Install the opencode-snip plugin by adding it to your OpenCode config (~/.config/opencode/opencode.json):
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-snip@latest"]
}The plugin uses the tool.execute.before hook to automatically prefix all commands with snip. Commands not supported by snip pass through unchanged.
openclaw plugins install openclaw-snipUse shell aliases to route commands through snip:
# Add to ~/.bashrc or ~/.zshrc
alias git="snip git"
alias go="snip go"
alias cargo="snip cargo"Or instruct the LLM via system prompt to prefix commands with snip.
snip works without any AI tool:
snip git log -10
snip go test ./...
snip gain # token savings reportsnip [args] # filter a command (implicit)
snip run -- # same, with explicit separator
snip check -- # check if a command would be filtered
snip proxy # force passthrough (no filtering)
snip proxy -- # same, with explicit separator
snip gain # full dashboard (summary + sparkline + top commands)
snip gain --daily # daily breakdown
snip gain --weekly # weekly breakdown
snip gain --monthly # monthly breakdown
snip gain --top 10 # top N commands by tokens saved
snip gain --history 20 # last 20 commands
snip gain --quota # savings against plan quotas
snip gain --unfiltered # opt-in report on unfiltered commands
snip gain --no-truncate # disable command truncation
snip gain --json # machine-readable output
snip gain --csv # CSV export
snip cc-economics # financial impact by pricing tier (configurable)
snip discover # find missed savings in Claude Code history
snip discover --since 30 # scan last 30 days
snip discover --all # scan all projects
snip learn # detect CLI error-correction patterns in sessions
snip learn --since 7 # scan last 7 days (default 30)
snip learn --all # scan all projects
snip learn --generate # write .claude/rules/cli-corrections.md
snip verify # run the filters' inline tests
snip config # show config
snip trust [path] # trust project-local filter file(s) by SHA-256
snip untrust [path] # remove file(s) from the trust store
snip hook # agent PreToolUse handler (used by the hooks)
snip hook-audit # show recent hook activity (SNIP_HOOK_AUDIT=1)
snip init # install Claude Code hook
snip init --agent cursor # install Cursor hook
snip init --agent pi # install Pi (pi.dev) hook
snip init --agent copilot # install Copilot hook
snip init --agent gemini # install Gemini CLI integration
snip init --agent kilocode # install Kilo Code integration
snip init --agent antigravity # install Antigravity integration
snip init --uninstall # remove hookGlobal flags: -v/-vv (verbose, stackable), -u (ultra-compact), --skip-env, --version, --help.
Filters are declarative YAML files. The binary is the engine, filters are data — the two evolve independently.
name: "git-log"
version: 1
description: "Condense git log to hash + message"
match:
command: "git"
subcommand: "log"
exclude_flags: ["--format", "--pretty", "--oneline"]
inject:
args: ["--pretty=format:%h %s (%ar) ", "--no-merges"]
defaults:
"-n": "10"
pipeline:
- action: "keep_lines"
pattern: "\\S"
- action: "truncate_lines"
max: 80
- action: "format_template"
template: "{{.count}} commits:\n{{.lines}}"
on_error: "passthrough"match.subcommand can be a scalar string (as above) or a list of exact subcommands:
match:
command: "npm"
subcommand: ["install", "add", "i"]
…
bash
snip init # creates ~/.config/snip/filters/
vim ~/.config/snip/filters/my-tool.yaml # add your filterUser filters take priority over built-in ones. Later directories in the list override earlier ones.
Filters under ~/.config/snip/ are always loaded. Filters anywhere else (for example a project's .snip/ directory) must be approved once with snip trust, otherwise they are skipped:
snip trust .snip/filters # approve the project's filters (SHA-256 pinned)Editing a trusted file invalidates its hash; run snip trust again after changes.
Optional TOML config at ~/.config/snip/config.toml (override the path with SNIP_CONFIG):
# mode = "user" # "project" in a .snip/config.toml lets that file
# override user settings (see Project Configuration)
[tracking]
db_path = "~/.local/share/snip/tracking.db"
track_unfiltered = false # opt-in: also record commands that had no filter
[display]
color = true
emoji = true
quiet_no_filter = false # suppress "no filter" stderr messages
summary = false # prepend a "[snip: ...]" line showing which filter/args were applied
[filters]
dir = "~/.config/snip/filters"
[filters.enable]
# git-diff = false # disable a specific built-in filter
[filters.global] # safety caps appended to every filter's pipeline (0 = unlimited)
# max_lines = 0 # cap the number of output lines
# max_line_length = 0 # cap each line's length
# max_output_bytes = 0 # hard cap on the bytes any filter emits.
# Applied last, cutting on a UTF-8 rune boundary and
# appending a "... truncated at N bytes" marker that is
# counted inside the cap.
[filters.override.dotnet-test] # tune a single filter without rewriting it
# head = 200 # raise dotnet-test's cap from 40 to 200 lines
# stream_mode = "full" # or skip this filter's pipeline entirely
# Other overridable keys: tail, truncate_lines, keep_lines, remove_lines
[filters.bypass]
# commands = ["dotnet publish"] # always run these unfiltered
[economics.tiers] # pricing for `snip cc-economics`, $ per 1M input tokens
# haiku = 1.00 # free-form names; defaults are current Anthropic list
# negotiated_opus = 3.10 # prices (haiku 1, sonnet 3, opus 5, fable 10) until set
[tee]
enabled = true
mode = "failures" # "failures" | "always" | "never"
max_files = 20
max_file_size = 1048576
# project_marker = ".git" # write tee files to /.snip/tee/ instead
# of the global dir when the marker is found by
# walking up from the working directory; a
# .gitignore is created there so logs are never
# committed, and snip falls back to the global dir
# if the repo root is not writableOverride values must be positive:
head = 0does not remove a filter's truncation, it is ignored. To get unlimited output from one filter, usestream_mode = "full"in its override block.
Full reference for every key, default and merge rule: Configuration wiki page.
Every setting above is reproducible. To prove one is active without touching your real config, point SNIP_CONFIG at a scratch file:
cd "$(mktemp -d)" && touch a.go b.md c.txt
export SNIP_CONFIG=$PWD/test.toml
printf '[filters.override.ls]\nhead = 2\n' > test.toml
snip ls # 2 entries + "... +more entries (truncated by snip)"
printf '[filters.bypass]\ncommands = ["ls"]\n' > test.toml
snip ls # raw ls output, no filtering
unset SNIP_CONFIG
…
bash
SNIP_PLUGIN_CONFIG=${CLAUDE_PLUGIN_ROOT}/snip/config.toml
…
bash
snip trust "$SNIP_PLUGIN_CONFIG" # the config itself
snip trust "${SNIP_PLUGIN_CONFIG%/*}/filters" # the plugin's filtersA plugin typically runs both commands from a session-start hook, so plugin updates re-trust automatically. Anything the user or the repo sets overrides the plugin layer. Full details on the Configuration wiki page.
No open issues yet, or sync has not completed.