A deterministic, auditable, local-first AI policy engine for Claude Code.
CCH provides a robust hook system that replaces fragile JSON configurations with readable YAML, enabling developers to enforce coding standards, inject context dynamically, and block dangerous operations with sub-10ms latency,,.
- Overview
- Why Use CCH?
- Architecture
- Installation
- Quick Start
- Configuration Guide
- The CCH Skill
- Governance & Policy
- Development
- CLI User Guide
- Agent Skill User Guide
Claude Code's native hook system relies on raw JSON configuration and shell commands, which can be opaque, hard to maintain, and lack conditional logic.
Claude Context Hooks (CCH) solves this by introducing a two-part system:
- The CCH Binary: A high-performance Rust executable that acts as the runtime hook handler.
- The CCH Skill: An intelligent assistant that analyzes your project and generates configurations automatically.
Core Philosophy: LLMs do not enforce policy; they are subject to policy. CCH is the policy authority.
| Problem with Native Hooks | CCH Solution |
|---|---|
| Poor Readability | Human-friendly YAML configuration with comments. |
| No Conditionals | Match rules by file extension, directory, tool, or regex. |
| Safety Risks | Block operations like force push or edits to production,. |
| Manual Setup | Intelligent "Skill" that scans CLAUDE.md to auto-generate rules. |
| Opaque Decisions | Deterministic logging and "explainable" policy modes. |
- Role: Deterministic runtime engine.
- Language: Rust.
- Performance: <10ms execution time (cold start <5ms),.
- Function: Intercepts Claude Code events (e.g.,
PreToolUse,PermissionRequest), evaluates YAML rules, and returns actions (inject context, block, or run scripts).
- Role: Configuration assistant.
- Function: Bridges the gap between the binary and the user. It discovers project skills, parses
CLAUDE.mdfor rules (MUST/MUST NOT), and generates thehooks.yamlfile,.
Download the appropriate artifact for your platform (macOS, Linux, Windows) from the releases page.
cargo install --git https://github.com/your-org/cchIf you have the CCH Skill enabled, simply ask Claude:
"Install CCH" The skill will detect your OS and handle the installation and verification,.
-
Initialize Configuration Scaffold a new configuration with example templates:
cch init
This creates
.claude/hooks.yaml,. -
Install to Claude Code Register CCH as the handler in Claude Code's settings:
cch install --project
Note: Use
--userfor global installation. -
Verify Ensure your configuration is valid:
cch validate
Configuration is stored in .claude/hooks.yaml. It supports event-based triggers and additive matching,.
version: "1"
# Event: Before a tool is executed
PreToolUse:
# Rule: Enforce CDK guidelines
- match:
tools: ["Edit", "Write"]
directories: ["infra/**", "cdk/**"]
action:
inject: "docs/cdk-guidelines.md"
# Rule: Prevent committing "WIP" code
- match:
tools: ["Bash"]
command_match: "git commit.*WIP"
action:
block: true
message: "Commits with 'WIP' are forbidden on this branch."
# Rule: Run custom Python validator
- match:
extensions: [".py"]
action:
run: ".claude/validators/security-check.py"SessionStart/SessionEndPreToolUse/PostToolUsePermissionRequest(Force Claude to explain commands)UserPromptSubmit- [See full list in PRD].
inject: Add Markdown context to the conversation.block: Stop the operation immediately.run: Execute a script (Python, Bun, Bash) for custom logic.
The CCH Skill allows you to configure hooks using natural language.
Triggers:
- "Set up hooks for this project"
- "Enforce the 'no console.log' rule with a hook"
- "Why isn't my hook blocking WIP commits?".
Capabilities:
- Project Analysis: Scans
.claude/skillsandCLAUDE.mdto suggest relevant hooks. - Conflict Detection: Identifies contradicting rules.
- Audit Trail: Keeps a record of installations in
.claude/cch/install.json.
CCH acts as a policy engine with advanced governance features.
Rules can be set to different enforcement levels:
enforce(Default): Blocks operations if conditions are met.warn: Injects a warning context but allows the operation.audit: Logs the event without blocking or injecting (useful for silent monitoring).
Every rule can track its origin for auditability:
metadata:
author: "cch-skill"
reason: "Enforce infrastructure coding standards"
ticket: "PLAT-3421"
confidence: "high"Logs are stored in ~/.claude/logs/cch.log in JSON Lines format, supporting "Explainable Policy" auditing,.
- Rust (Cargo)
- Python 3 (for testing validators)
- Bun (for testing TypeScript validators).
cargo build --releaseCCH includes unit, integration, and end-to-end tests.
cargo testSee cch_cli_prd.md for the detailed testing strategy covering cold starts, script timeouts, and error handling,.
MIT License.