Sandbox
@abhisekjha/pith

Claude Code plugin for token compression hooks

Pith attaches to Claude Code’s lifecycle with post-tool, prompt-submit, session-start, and stop hooks. It compresses file reads and command output, restores session settings, and records token usage so you can keep working with less context bloat.

98 stars11 forksPythonUpdated 4mo ago
Who it's for

Builders who run Claude Code and want reusable session compression across projects.

What it delivers

You can keep Claude Code sessions useful for longer by shrinking the context that gets added from tools and outputs.

What it does

Auto compression

Compresses file reads, bash output, grep results, and large payloads before they enter context.

Output modes

Adds `/pith`, `/pith ultra`, `/pith precise`, and `/pith off` for controlling how Claude writes back.

Token status and reports

Provides `/pith status` for an ASCII token flow chart and `/pith report` for an HTML dashboard.

Smart file focus

Uses `/focus <file>` to return only the most relevant sections of a file instead of rereading the whole thing.

Symbol extraction

Uses `/pith symbol` to pull exact function or class definitions and list symbols with line numbers.

Wiki and graph tools

Supports ingestion, wiki search, synthesis, linting, and a knowledge graph for project knowledge.

Token ceiling

Lets you set a hard prompt budget with `/budget <number>` and enforce it on every prompt.

How to get it

  1. 1Run
    # One-liner
    bash <(curl -s https://raw.githubusercontent.com/abhisekjha/pith/main/install.sh)
    
    # From source
    git clone https://github.com/abhisekjha/pith
    bash pith/install.sh
  2. 2Update
    /pith update    → git pull + re-sync hooks, commands, settings
  3. 3Uninstall
    /pith uninstall

README

Pith

GitHub Stars

Status: stable — not actively adding features. Bug fixes welcome via issues.

Token compression hooks for Claude Code. Install once, works in every session, zero config.

bash <(curl -s https://raw.githubusercontent.com/abhisekjha/pith/main/install.sh)

How it works

Four hooks attach to Claude Code's lifecycle. Every session, every project, automatically.

  • PostToolUse — compresses file reads, bash output, and grep results before they hit context
  • UserPromptSubmit — runs /pith commands, enforces token ceiling if set
  • SessionStart — restores compression mode, injects cache-locked rules
  • Stop — records token usage for status and report

The PostToolUse hook is where most savings happen — file reads alone account for 30–50% of context in a typical coding session.

Tool outputWhat happensTypical saving
File readsskeleton only — imports, signatures, types−88% per read
Bash / builderrors + summary, verbose logs discarded−91% per run
Grep resultscapped at 25 matchesprevents runaway searches
Large payloadsoffloaded to ~/.pith/tmp/, pointer left in contextprevents bloat

Core features

1 — Auto compression (zero config)

Runs automatically. No commands needed. Every file read, bash run, and grep gets compressed on the way back to Claude.

Real session numbers:

Read large-service.ts  →  1,800 tokens baseline  →  210 tokens compressed  (−88%)
npm install output     →    940 tokens baseline  →   80 tokens compressed  (−91%)

2 — Output modes

Control how Claude writes back to you.

/pith           → lean: drop filler, short synonyms, fragments OK
/pith ultra     → maximum: abbreviate, arrows, tables
/pith precise   → tight but full sentences
/pith off       → disable output compression

Auto-escalation kicks in as context fills — no manual switching needed:

50% fill → LEAN
70% fill → ULTRA
85% fill → dynamic token ceiling

3 — Token status

/pith status    → ASCII flow chart — baseline vs compressed vs output + plain-English savings
/pith report    → interactive HTML dashboard (auto-refreshes every 30s)

/pith status — token flow chart, compression ratio, cost breakdown

4 — Smart file focus

Load only the sections of a file relevant to your current question. Saves re-reading large files.

/focus src/services/auth.ts

Returns the 5 most relevant sections with a structure overview. Works on any file type.

5 — Symbol extraction

Pull exact function or class definitions without reading the whole file.

/pith symbol src/auth.ts handleLogin      → exact 30–50 lines (~95% vs full file)
/pith symbol --list src/auth.ts           → all symbols with line numbers

Install

# One-liner
bash <(curl -s https://raw.githubusercontent.com/abhisekjha/pith/main/install.sh)

# From source
git clone https://github.com/abhisekjha/pith
bash pith/install.sh

Hooks install globally into ~/.claude/hooks/. Active in every session from that point on.

Update:

/pith update    → git pull + re-sync hooks, commands, settings

Uninstall:

/pith uninstall

Advanced features

All present and functional. Not the daily workflow, but there when you need them.

FeatureCommandWhat it does
Project wiki/pith ingest <file>Extract entities, claims, decisions into wiki/
URL ingestion/pith ingest --url <url>Fetch and ingest a web page
Wiki query/pith wiki "question"Search wiki with citations
Wiki synthesis/pith compileRe-synthesize all sources into wiki pages
Wiki lint/pith lintFind contradictions, gaps, missing pages
Knowledge graph/pith-graphVisual graph of wiki entities in browser
jCodeMunchauto on code filesStructure-aware ingest — skeleton not full source
Token ceiling/budget 150Hard token cap, enforced every prompt
Structured formats/pith debug / review / arch / plan / commitOutput templates
Tour/pith tour7-step interactive walkthrough
Health check/pith healthDiagnose hook and config issues
Evalspython evals/harness.pyRun compression benchmark (needs API key)

Honest numbers

Estimates against real usage — not against "no system prompt."

Before Pith:  Read large-service.ts → 1,800 tokens
After Pith:   Read large-service.ts →   210 tokens   (−88%)

Before Pith:  npm install output    →   940 tokens
After Pith:   errors + summary      →    80 tokens   (−91%)

Session from real use:

  • 19.9k input tokens (237.9k baseline without Pith)
  • 218k tokens saved — 92% compression ratio
  • $0.07 actual vs $3.33 without Pith — 47× cost ROI

See BENCHMARKS.md for methodology and raw numbers.


Multi-model pricing

Pith detects the model automatically and applies correct rates. No config needed.

ModelInput ($/MTok)Output ($/MTok)
Claude Opus 4.7 / 4.6 / 4.5$5.00$25.00
Claude Sonnet 4.6 / 4.5 / 4$3.00$15.00
Claude Haiku 4.5$1.00$5.00
Claude Haiku 3.5$0.80$4.00

Falls back to Sonnet 4.6 rates if model can't be determined.


Star History

Star History Chart


License

MIT

Files in the repo

Repository payload25 top-level entries
  • .claude-plugin
  • .github
  • assets
  • benchmarks
  • commands
  • evals
  • hooks
  • schemas
  • skills
  • test
  • tests
  • tools
  • wiki-pages
  • .gitignore
  • BENCHMARKS.md
  • CHANGELOG.md
  • COMMANDS.md
  • index.html
  • install.sh
  • LICENSE
  • NOTES.md
  • ONBOARDING.md
  • README.md
  • SECURITY_FIXES.md
  • uninstall.sh

Discussion (0)

Ask about usage, or say what you built with it

Sign in to join the discussion.

No comments yet. Be the first to say what this is good for.

More plugins

Makes your AI agent think like the laziest senior dev in the room. The best code is the code you never wrote.

138k
1 add

Graphs that teach > graphs that impress. Turn any code into an interactive knowledge graph you can explore, search, and ask questions about. Works with Claude Code, Codex, Cursor, Copilot, Gemini CLI, and more.

82k
code-yeongyu/
oh-my-openagent

OmO: Just type "mass ulw" keyword with your prompt. Now you are the master of graph engineering.

69k

Persistent Context Across Sessions for Every Agent – Captures everything your agent does during sessions, compresses it with AI, and injects relevant context back into future sessions. Works with Claude Code, OpenClaw, Codex, Gemini, Hermes, Copilot, OpenCode + More

94k

Opinionated Oxlint rules for rejecting low-evidence TypeScript and JavaScript patterns

4.3k