Token Guard — Development skill for Claude Code
Automatic Claude Code hooks to reduce token waste — block heavy files, context warnings, cost logging.
How to install Token Guard
This entry records only its repository, not the path inside it, so there is no
exact command to give. Open dockplusai-ops/token-guard and copy the folder into
~/.claude/skills/, or the file into ~/.claude/agents/.
What Token Guard does
Automatic Claude Code hooks to reduce token waste — block heavy files, context warnings, cost logging.
Alternatives in Development
- Claude Token Efficient — One CLAUDE.md file 3.8k ★
- Benjamin Plus Skill — Benjamin-Plus: a measured token-efficiency skill for coding agents (−17.9% cost median, quality unchanged) 272 ★
- Xc MCP — XCode CLI MCP: Convenience wrapper for Xcode CLI tools & iOS Simulator 82 ★
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
Context Budget
Analyze context window usage across agents, skills, MCP servers, and rules to find optimization opportunities.
Cc Waste
Scans your local Claude Code session logs and generates a self-contained HTML report of token usage, cost, and
Cc Agents Kit
Claude Code plugin marketplace. guard-hooks: five defensive hooks that block dangerous shell commands and secr
Greenbelt
Greenbelt is Claude Code hooks that track token usage across Claude Code sessions and plants trees to reduce y
Pi Workbench
Native desktop workbench (PySide6) for the pi coding agent — streaming chain-of-thought, per-turn token/cache/
Claude Map Reduce Memory
Global, unlimited persistent memory for Claude Code agents. Context-activated hints injected automatically via
Related Agents
Context Optimizer
Meta utility agent for token and context optimization. Spawn when needing to compress agent prompts, optimize
Context Auditor
Use proactively when the user wants to cut Claude Code token cost or asks "why is this session so expensive /
Lauda
Lauda (Лауда) — performance specialist — finds and explains bottlenecks: N+1 queries, hot-path cost, async mis