context-hogs — Claude Code plugin: what it does, how to install
context-hogs tracks per-file context usage and highlights which repo files drive up token spend.
MIT ★ 586 updated 2026-10-26
/plugin marketplace add karanb192/claude-code-hooks
/plugin install context-hogs@claude-code-hooksWhat context-hogs does
The plugin hooks into Read, Grep, Glob, and Bash operations. Its asynchronous PostToolUse handler measures response byte sizes, maps them back to project paths, and appends rows to a file ledger. Because hooks receive raw payloads rather than exact model counts, token volume is estimated at roughly 4 bytes per token.
At SessionEnd, or via command, it renders a summary card with read frequencies, cumulative tokens, and dollar estimates. It also drafts an ignore block for CLAUDE.md targeting lockfiles and bulky source files. All ledger data stays local under ~/.claude/context-hogs/<repo-key>/ledger.jsonl without external network activity.
What it helps with
- identify files consuming the largest share of context tokens
- calculate estimated input costs per repository asset
- generate targeted file ignore rules for CLAUDE.md
Example prompts for the agent
- /context-hogs:leaderboard
- Check which repository files consumed the most context this session
- Review context spending estimates before updating CLAUDE.md
How to install context-hogs
Plugin marketplace
/plugin marketplace add karanb192/claude-code-hooks/plugin install context-hogs@claude-code-hooksStep by step, with commands for each platform: Claude Code plugins: marketplaces, installing, and building your own
Questions about context-hogs
How to install context-hogs in Claude Code?
Run /plugin marketplace add karanb192/claude-code-hooks followed by /plugin install context-hogs@claude-code-hooks, then restart Claude Code.
What does context-hogs do?
It intercepts tool outputs from file inspection tools, maps output sizes to file paths, and renders a cost leaderboard.
How does context-hogs estimate costs?
It divides result bytes by CONTEXT_HOGS_BYTES_PER_TOKEN (default 4) and applies the rate set in CONTEXT_HOGS_USD_PER_MTOK (default 3.0 per million tokens).
Source text
context-hogs · MIT
# context-hogs > Per-file context-cost leaderboard: attributes every tool result's tokens to the files it loaded, so you know which files cost you the most. A `PostToolUse` hook fires after every `Read`, `Grep`, `Glob`, and `Bash` call, measures the tool result's bytes, resolves the file path(s) that result belongs to, and appends a ledger row. Tokens are estimated from bytes (~4 bytes/token) and dollars from a configurable input-token rate (hooks don't receive real token counts, so nothing is fabricated). At `SessionEnd`, or on demand via the skill, it aggregates the ledger into your repo's most token-expensive files (read count, cumulative tokens, estimated cost, plus repeat-offender flags for lockfiles, generated code, and giant utils) and renders that leaderboard. ## Install ``` /plugin marketplace add karanb192/claude-code-hooks # once per machine /plugin install context-hogs@claude-code-hooks ``` Restart Claude Code, done. (Or from a shell: `claude plugin install context-hogs@claude-code-hooks`.) ## What it does | Event | Runs | What happens | |-------|------|--------------| | PostToolUse (`Read\|Grep\|Glob\|Bash`) | async (zero added latency) | Measures the tool result's bytes, resolves the file path(s) it belongs to, appends a ledger row. | | SessionEnd | sync | Aggregates the whole ledger, renders the leaderboard card via `systemMessage`, and writes a suggested CLAUDE.md ignore block for the top offenders. | `/context-hogs:leaderboard` renders this repo's context-cost leaderboard on demand. ## Configuration All optional, set via environment variables: | Variable | Default | Purpose | |----------|---------|---------| | `CONTEXT_HOGS_BYTES_PER_TOKEN` | `4` | Bytes-per-token ratio used to estimate tokens. | | `CONTEXT_HOGS_USD_PER_MTOK` | `3.0` | Input $/1M tokens used to estimate cost. Set to your model's current input rate. | | `CONTEXT_HOGS_TOP_N` | `10` | Number of files shown on the leaderboard. | | `CONTEXT_HOGS_LEDGER_CAP` | `50000` | Max ledger rows kept; older rows are compacted at SessionEnd. | State is stored under `~/.claude/context-hogs/<repo-key>/ledger.jsonl`. ## Data & privacy Records file paths, read counts, and byte/token estimates per repo. It makes no network calls (the script only uses `fs`, `path`, and `os`), so everything stays on your local machine. ## Uninstall ``` /plugin uninstall context-hogs@claude-code-hooks ```
© Karan Bansal · MIT · karanb192/claude-code-hooks