Skip to main content
plugin

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

Install into Claude Code · Plugin marketplace All methods and platforms ↓
/plugin marketplace add karanb192/claude-code-hooks
/plugin install context-hogs@claude-code-hooks
Open on GitHub

What 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-hooks

Step 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

Similar plugins

All plugins for Agent setup: memory, context, orchestration →

From the same set28

The whole set →
protect-secrets protect-secrets — a PreToolUse hook that checks every Read, Edit, Write, Bash and Grep call and blocks .env, SSH keys or cloud credentials — or asks you first. ★ 586repo stars bounty-board bounty-board turns TODO and FIXME comments into bounties that grow in XP value as they age. Scans your repo, prices each debt marker by git-blame age, and feeds the top 3 into your session as side quests. ★ 586repo stars dead-end-registry dead-end-registry stores reverted code changes and alerts you before retrying failed ideas. Keeps track of discarded approaches and detour token costs per repository. ★ 586repo stars standup-autopilot The standup-autopilot plugin turns agent session transcripts into a daily standup card with tasks, tests, PRs, and blockers. Open blockers carry into the next session. ★ 586repo stars pr-provenance-stamp pr-provenance-stamp appends a provenance receipt to your pull request body: prompts, estimated spend, test exit codes and an agent-versus-human line split. ★ 586repo stars dead-rules-audit dead-rules-audit tracks how Claude Code adheres to CLAUDE.md rules during edits and flags chronically violated items. ★ 586repo stars nerf-receipts The nerf-receipts plugin tracks tool failures, repeated edits to the same file, and tokens per task. Use it to see whether those signals shift when the model changes. ★ 586repo stars cache-tax cache-tax prices a cold return to a session before you send the next message, so a lapsed 1-hour prompt cache does not quietly re-write the whole context. ★ 586repo stars

Project sponsors

Companies that keep this analytics open