Pipe-aware variants of grep/git-show/git-log plus shell for-loop and echo-banner rules. Targets the top patterns from `tokenjuice discover` that defeat built-in classification because piped commands have an empty argv0. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> |
||
|---|---|---|
| rules | ||
| README.md | ||
claude-juice
Custom tokenjuice rules tuned for my Claude Code sessions.
These extend the built-in rules to catch patterns the defaults miss — primarily commands chained through pipes (| head, | tail, | sort), which the built-in classifier can't see because pipes blank out argv0.
Install
tokenjuice loads user rules from ~/.config/tokenjuice/rules/. It does not follow symlinks and rejects files whose realpath is outside that directory, so the rules have to be copied (not linked) in.
On a new machine:
git clone https://git.brads.house/brad/claude-juice.git
mkdir -p ~/.config/tokenjuice/rules
cp -r claude-juice/rules/. ~/.config/tokenjuice/rules/
tokenjuice verify
To update after git pull, re-run the cp -r line.
(Or, if you don't want a separate working copy, clone directly into ~/.config/tokenjuice/rules/ — tokenjuice ignores README.md and .git/ since it only loads *.json files.)
Rules
All five rules use failure.preserveOnFailure: true with head: 999, tail: 999, which preserves full output on non-zero exits — tracebacks and error messages pass through untouched.
search/grep-piped
Catches grep ... | head/tail/sort/.... The built-in search/grep rule requires argv0=grep, which is empty for piped commands. This is the biggest single win — over 100 leaked grep invocations in my recent sessions, ~170k chars of raw output.
git/show-piped
Catches git show <ref> -- <file> | head -50 and similar. Same reason: pipes defeat the built-in git/show. Keeps commit header, hunks, and --- / +++ markers.
git/log-piped
Catches git log ... | head patterns. Keeps commit lines (full hash or short hash + subject) and author/date.
shell/for-loop
Compacts output from for ... do ... done loops, common when dumping multiple files (for f in *.md; do echo "=== $f ==="; cat "$f"; done). Matches when the command contains both for and done as words. Keeps banner lines (=== ... ===, ==> ... <==, --- ... ---, # ...) so file boundaries survive.
shell/echo-banner
Compacts ad-hoc inspection scripts that string commands together with echo "=== ... ===" headers between them. Matches when the command contains both echo and ===. Keeps banners and any line containing error|warn|exception|traceback|fatal|fail.
How tokenjuice scoring interacts with these
The classifier scores rules by specificity: argv0 matches are worth 100 points each, commandIncludes only 25. So when a built-in rule like search/grep (using argv0) and one of mine (using commandIncludes) both match, the built-in wins — which is what we want for non-piped invocations. My rules only fire when the built-ins can't.
Why these rules and not others
I picked the top 5 by raw chars saved per tokenjuice discover. Smaller patterns (wc, pio test, fj help, rm) were under 5k chars each and not worth the rule overhead. If a new pattern shows up regularly in tokenjuice discover output, add a rule for it.