Token Guard
Description
Automatic Claude Code hooks to reduce token waste — block heavy files, context warnings, cost logging
Installation
This entry records only its repository, not the path inside it, so there is no
exact command to give. Open the source below and copy the folder into
~/.claude/skills/, or the file into ~/.claude/agents/.
README
token-guard
Automatic Claude Code hooks to reduce token waste and context bloat — no manual intervention required.
What it does
1. Block heavy files (`PreToolUse`)
Automatically blocks reads of files that waste context tokens:
- Lock files:
package-lock.json,yarn.lock,pnpm-lock.yaml,Gemfile.lock,Cargo.lock,poetry.lock - Build artifacts:
node_modules/,dist/,.next/,build/,vendor/ - Compiled/minified:
*.min.js,*.min.css,*.map,*.pyc,__pycache__/ - Any file larger than 200KB (~50k tokens)
Claude gets a clear message explaining why the file was blocked and what to read instead.
2. Context usage warning (`UserPromptSubmit`)
Injects a warning before every prompt when the context window is filling up:
| Usage | Level | Message |
|---|---|---|
| < 50% | — | Silent |
| 50–69% | 🟡 WARNING | Keep responses concise |
| 70–84% | 🟠 HIGH | Consider starting a new session |
| ≥ 85% | 🔴 CRITICAL | Open a new session now |
3. Context re-injection after compaction (`PostCompact`)
When Claude compacts the session (context limit reached), automatically re-injects project context from:
.claude/context.mdin the project root (if it exists)- First 50 lines of
CLAUDE.mdin the project root (fallback)
4. Token usage logger (`Stop`, async)
Logs every session's token usage to `~/.claude/token-guard/usage.jsonl` for cost tracking.
Installation
git clone https://github.com/dockplusai-ops/token-guard
cd token-guard
bash install.sh
That's it. All hooks are registered automatically in `~/.claude/settings.json`.
Usage
# View usage report (last 7 days)
bash token-guard-report.sh
# View usage report (last 30 days)
bash token-guard-report.sh 30
Example output:
=== Token Guard Report — Last 7 days ===
Sessions: 12
Input tokens: 1,240,000
Output tokens: 310,000
Estimated cost: $5.3650 USD
By project:
Project Input Output Cost
-------
Related Skills
Auto Update
Pull the latest ECC repo changes and reinstall the current managed targets.
Development Ecc Guide
Navigate ECC's current agents, skills, commands, hooks, install profiles, and docs from the live repository su
Development Epic Claim
Claim an epic issue, stamp coordination state, and sync local ownership.
Development Epic Publish
Publish a validated epic update back to the issue and local cache.
Development Epic Review
Mark epic review requested, approved, or changes requested.
Development Epic Unblock
Sweep blocked epic issues and reopen anything whose dependencies are closed.
Development Related Agents
Django Build Resolver
Django/Python build, migration, and dependency error resolution specialist. Fixes pip/Poetry errors, migration
Openai Codex CLI
(55.8k ⭐) - Lightweight coding agent that runs in your terminal.
src/agents/ — 11 Agent Definitions
**Generated:** 2026-04-11