This directory contains two types of hooks for Freenet development:
Files:
hooks.json- Hook configurationclaude-pre-commit-hook.sh- Hook script
These hooks run automatically during Claude Code sessions when the freenet plugin is installed.
Runs cargo fmt and cargo clippy automatically before Claude runs git commit commands.
- Event:
PreToolUse(before Bash tool execution) - Trigger: Detects
git commitcommands - Scope: Only in Cargo projects (checks for
Cargo.toml) - Action: Blocks commit if formatting or linting fails
Automatically activated when you install the plugin:
/plugin install freenetThe hooks.json configuration tells Claude Code to run claude-pre-commit-hook.sh before any Bash tool execution.
When Claude attempts to run git commit:
- Claude Code invokes
claude-pre-commit-hook.shwith tool input via STDIN - Script checks if already running (via
FREENET_HOOK_RUNNINGenv var) to prevent recursion - Script extracts the command from STDIN JSON and checks if it's a
git commit - If in a Cargo project, runs
cargo fmt --checkto verify formatting - Runs
cargo clippy --all-targets --all-features -- -D warnings - If checks pass → commit proceeds
- If checks fail → commit is blocked with error message
The hook uses the FREENET_HOOK_RUNNING environment variable to prevent infinite recursion:
- When the hook runs
cargo fmtandcargo clippy, those are also Bash commands - Without protection, the hook would intercept its own subcommands
- The
FREENET_HOOK_RUNNING=1guard ensures the hook only runs once per commit attempt - Any Bash commands executed while the hook is running will see this variable and immediately exit
File: pre-commit (bash script)
A git hook that runs before commits to catch formatting and lint issues.
Blocks commits if code doesn't pass:
cargo fmt --check- Code formattingcargo clippy --all-targets --all-features -- -D warnings- Lints
Copy to your freenet-core repository:
# From freenet-core repository root
curl -fsSL https://raw.githubusercontent.com/freenet/freenet-agent-skills/main/hooks/pre-commit > .git/hooks/pre-commit
chmod +x .git/hooks/pre-commitOr copy locally:
cp /path/to/freenet-agent-skills/hooks/pre-commit /path/to/freenet-core/.git/hooks/pre-commit
chmod +x /path/to/freenet-core/.git/hooks/pre-commitEach git worktree needs the hook installed separately:
cd ~/code/freenet/freenet-core/fix-123
curl -fsSL https://raw.githubusercontent.com/freenet/freenet-agent-skills/main/hooks/pre-commit > .git/hooks/pre-commit
chmod +x .git/hooks/pre-commitgit commit --no-verify -m "message"| Feature | Claude Code Hook | Git Pre-Commit Hook |
|---|---|---|
| When runs | Before Claude's git commit |
On git commit (native git) |
| Installation | Automatic with plugin | Manual copy |
| Scope | All staged files | All staged files |
| Action | Block commit if issues | Block commit if issues |
| Checks | cargo fmt + clippy | cargo fmt + clippy |
| Best for | AI-assisted commits | All commits |
Use the Claude Code hook (automatic with plugin) for AI-assisted development. It catches issues before Claude commits.
Optionally add the git hook for:
- Commits made outside Claude Code sessions
- Team members not using the plugin
- Extra safety net
Both hooks run the same checks (cargo fmt + clippy), so the git hook mainly serves as a fallback for non-Claude commits.
The freenet-core repository officially uses the pre-commit framework with .pre-commit-config.yaml. This bash script hook is provided as a lightweight alternative for:
- Environments where pre-commit framework isn't available
- Quick setup without dependencies
- Personal preference for simple bash scripts
To use freenet-core's official setup instead:
pip install pre-commit
cd /path/to/freenet-core
pre-commit install