Claude Code
Claude Code supports PostToolUse hooks that fire after every tool call. vibecop uses this to scan files after each Edit, Write, or MultiEdit operation.
Auto Setup
npx vibecop initIf a .claude/ directory is detected, vibecop init generates the settings file automatically.
Manual Setup
Create .claude/settings.json in your project root:
{ "hooks": { "PostToolUse": [ { "matcher": "Edit|Write|MultiEdit", "hooks": [ { "type": "command", "command": "npx vibecop scan --diff HEAD --format agent" } ] } ] }}How It Works
- The agent calls
Edit,Write, orMultiEditto modify a file - The
PostToolUsehook fires and runsnpx vibecop scan --diff HEAD --format agent - vibecop scans only the changed files (via
--diff HEAD) - If findings are detected, vibecop exits with code 1 and prints findings to stdout
- Claude Code reads the findings and the agent auto-corrects the code
- The hook runs again — if clean (exit 0), the agent continues
The matcher Field
The matcher uses a regex pattern to match tool names. Edit|Write|MultiEdit catches all file-editing tools. You can narrow this if needed:
Edit— only on file editsWrite— only on new file creationEdit|Write|MultiEdit— all file modifications (recommended)
The --format agent Flag
This produces token-efficient output (one finding per line, ~30 tokens each), minimizing context window usage:
src/api.ts:42:1 error unsafe-shell-exec: execSync() with template literal. Use execFile() with argument array instead.The --diff HEAD Flag
This scans only files with uncommitted changes, making the hook fast even in large repositories. Without this flag, vibecop would scan the entire project on every edit.
Existing Settings
If .claude/settings.json already exists, vibecop init will skip it to avoid overwriting your configuration. In that case, add the PostToolUse hook manually by merging the JSON above into your existing settings.
Troubleshooting
vibecop not found
If npx vibecop fails, install it as a dev dependency:
npm install --save-dev vibecopOr install globally:
npm install -g vibecopHook not firing
Verify the hook is configured correctly:
- Check that
.claude/settings.jsonexists in your project root - Confirm the
hooks.PostToolUsearray contains the vibecop entry - Test the command manually:
npx vibecop scan --diff HEAD --format agent
Slow scans
If the hook takes too long, scope the scan to a specific directory:
npx vibecop scan --diff HEAD --format agent --path src/