# r/ChatGPTCoding Post

**Title:** pip package that prevents AI coding assistants from wasting tokens on junk reads and committing secrets — works with Claude Code hooks

---

Quick background for those not using Claude Code: it has a hooks system where you can run scripts before any tool call (file read, bash command, git operation). This lets you intercept and block actions before they happen, not just log them after the fact.

TokenGuard uses those hooks to enforce 11 safety rules automatically:

**Token waste prevention:**
- Blocks the AI from reading `node_modules`, `dist`, `.next`, `venv`, and similar folders -- these can be hundreds of thousands of tokens and almost never contain what the AI actually needs
- Enforces faster search tools (`rg` over `grep`, `fd` over `find`) -- same results, fraction of the context cost
- Warns when you hit 70% context window, blocks new work at 85% before output quality degrades

**Security gates:**
- Blocks commits that include `.env` files, credential files, and API key patterns
- Blocks force-push to `main` or `master`
- Blocks reading sensitive environment variables (anything matching API_KEY, SECRET, TOKEN patterns)

**How to use it:**

```
pip install tokenguard
tokenguard init
```

That's it. `init` writes the hook configuration into your Claude Code settings and generates a project-aware `.claude/` directory. No config file to maintain, no ongoing setup. It auto-detects your stack (Python, JS, Rust, Go) and tailors the rules.

It's free, MIT licensed, and has zero runtime dependencies (pure Python stdlib). We extracted it from GRIP, a larger system we run at ENTER Konsult (enterkonsult.com) for managing AI agent workflows. TokenGuard is the self-contained safety layer from that system.
