claude-enforce
v1.0.0
Published
Transform CLAUDE.md natural language rules into deterministic Claude Code hooks automatically
Maintainers
Readme
claude-enforce
Transform CLAUDE.md rules into deterministic Claude Code hooks. Automatically.
ClaudeEnforce — Init
Parsing CLAUDE.md...
Found 8 rules in 3 sections
Classification Results:
Enforceable (hook-ready): 5
Advisory (CLAUDE.md only): 3
✓ [CRITICAL] NEVER edit .env files
✓ [CRITICAL] NEVER commit secrets or API keys
✓ [HIGH] ALWAYS run tests before committing
✓ [HIGH] NEVER use git push --force
✓ [HIGH] Do not skip git hooks with --no-verify
· [NORMAL] Keep functions under 50 lines
· [NORMAL] Use TypeScript strict mode
· [NORMAL] Prefer composition over inheritance
Generated 5 hooks → .claude/settings.jsonCLAUDE.md is advisory. Hooks are deterministic. Claude can ignore your CLAUDE.md under pressure. It cannot bypass a hook that exits with code 1. This tool bridges the gap.
Try it
npx claude-enforce init # parse CLAUDE.md → generate hooks
npx claude-enforce install --list # browse pre-built presets
npx claude-enforce audit # compliance report from transcriptsCommands
init — Parse rules, generate hooks
claude-enforce init # reads ./CLAUDE.md
claude-enforce init --file path.md # custom CLAUDE.md path
claude-enforce init --dry-run # preview without writingReads your CLAUDE.md, classifies each rule as enforceable (can be a hook) or advisory (stays in CLAUDE.md), and generates .claude/settings.json hooks for enforceable rules.
Set ANTHROPIC_API_KEY for AI-powered classification. Without it, pattern-based classification works fine.
install — Pre-built presets
claude-enforce install --list
claude-enforce install block-destructive-bash no-env-edit| Preset | Hooks | What it blocks |
|--------|-------|---------------|
| block-destructive-bash | 3 | rm -rf, git reset --hard, force push, DROP TABLE |
| no-env-edit | 2 | Any Edit/Write to .env files |
| no-commit-without-tests | 1 | git commit unless tests were run |
| no-migration-without-confirm | 1 | Database migrations without approval |
| typecheck-on-save | 2 | Runs tsc --noEmit after editing .ts files |
audit — Compliance report
claude-enforce audit # scan .claude/logs/
claude-enforce audit --json # machine-readable
claude-enforce audit --since 2025-01-01 Compliance Report
──────────────────────────────────────────
Tool calls analyzed: 247
Total violations: 12
Compliance rate: 95.1%
Most Broken Rules:
4x no-destructive-bash
3x no-force-push
2x no-env-editwatch — Real-time monitoring
claude-enforce watch # live monitor
claude-enforce watch --interval 5000Polls .claude/logs/ for new transcript entries and alerts instantly on violations.
How hooks work
CLAUDE.md = instructions Claude reads. Hooks = shell commands that intercept tool calls.
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"type": "command",
"command": "if echo \"$CLAUDE_TOOL_INPUT\" | grep -qE \"rm -rf\"; then echo \"BLOCKED\" >&2; exit 1; fi"
}
]
}
}- PreToolUse: runs before a tool. Exit 1 = tool blocked.
- PostToolUse: runs after. Used for checks (lint, typecheck).
- $CLAUDE_TOOL_INPUT: JSON of what Claude is trying to do.
Part of the Claude Code Toolkit
| Tool | What it does | |------|-------------| | claude-score | Score your setup A-F, see what's missing | | claude-gen | Generate CLAUDE.md from your codebase | | claude-enforce | Convert rules into deterministic hooks |
npx claude-score # diagnose
npx claude-gen # fix
npx claude-enforce init # protectLicense
MIT
