# r/ClaudeAI Post

**Title:** I built a pip package that adds safety gates to Claude Code — stops it from reading node_modules, grepping instead of using rg, and committing .env files

---

If you use Claude Code heavily you've probably hit these:

- It reads all of `node_modules` looking for something and burns 40k tokens
- It uses `grep` when `rg` is faster and you told it not to
- It tries to force-push to main
- You hit 85% context and it just... keeps going until everything degrades

I extracted the safety layer from GRIP (an internal AI agent management system we use at ENTER Konsult) into a standalone open-source package called TokenGuard.

It hooks into Claude Code's PreToolUse system and enforces 11 gates before any tool call executes:

- Blocks reads into `node_modules`, `.next`, `dist`, `venv`, `__pycache__`, etc.
- Requires `rg` instead of `grep`, `fd` instead of `find`
- Blocks `.env`, credential files, and API key patterns from being committed
- Warns at 70% context usage, hard-blocks at 85%
- Blocks force-push to `main`/`master` without explicit approval
- Prevents `rm -rf` on paths outside the project directory

Setup is two commands:

```
pip install tokenguard
tokenguard init
```

It auto-detects your project type (Python, JS, Rust, Go) and generates a tailored `.claude/` directory with the hook, safety rules, and a memory scaffold for cross-session context.

MIT licensed, stdlib-only (no dependencies beyond Jinja2 for the init step), and works on macOS, Linux, and Windows.

Happy to answer questions about how the hooks work or what gates are configurable.
