Setup snip Hooks
Scaffolds snip preToolUse hook into a projectβs .github/hooks/ directory. The hook automatically rewrites supported CLI commands through snip to reduce output tokens.
Why per-project hooks?
Copilot/VS Code hooks require a hardcoded cwd in hooks.json β there is no environment variable (like ${CLAUDE_PLUGIN_ROOT}) to resolve the hook script path dynamically. The hook must live inside the project so the relative path works.
When to Use
- New project needs snip token reduction
- Project has no
.github/hooks/snip-rewrite.sh yet
snip and jq are available on the machine
Prerequisites
command -v snip # must exist
command -v jq # must exist
If either is missing, STOP β install before proceeding.
Setup Steps
- Create
.github/hooks/ in project root if it doesnβt exist
- Copy the 2 template files from this skillβs
templates/ directory:
mkdir -p .github/hooks
cp templates/snip-rewrite.sh .github/hooks/snip-rewrite.sh
cp templates/hooks.json .github/hooks/hooks.json
- Make the hook script executable:
chmod +x .github/hooks/snip-rewrite.sh
- If
.github/hooks/hooks.json already exists, merge the preToolUse entry instead of overwriting.
What Gets Created
| File | Purpose |
|---|
snip-rewrite.sh | preToolUse hook β rewrites commands through snip (Claude Code + Copilot formats) |
hooks.json | Hook registration for Claude Code plugin system |
Supported Commands
git, go, cargo, dotnet, npm, npx, yarn, pnpm, docker, kubectl, make, pip, pytest, jest, tsc, eslint, rustc
.NET Filters (dotnet build / dotnet test)
Custom snip filters for dotnet build and dotnet test are available in filters/:
mkdir -p ~/.config/snip/filters
cp <skill-dir>/filters/dotnet-build.yaml ~/.config/snip/filters/dotnet-build.yaml
cp <skill-dir>/filters/dotnet-test.yaml ~/.config/snip/filters/dotnet-test.yaml
Replace <skill-dir> with the path to this skill folder (e.g. plugins/minimal-context-tools/skills/setup-snip-hooks).
dotnet-build keeps: compiler errors/warnings + Build succeeded. / Build FAILED. summary.
dotnet-test keeps: test failure details (name, error message, stack trace) + Passed! / Failed! summary.
Verify
echo '{"tool_input":{"command":"git status"}}' | .github/hooks/snip-rewrite.sh
# Should output JSON with "snip git status" in updatedInput
Commit
git add .github/hooks/
git commit -m "chore: add snip preToolUse hooks for token reduction"