Zero-config AI code review hook for git commits
npm install husky-aiZero-config AI Code Reviewer for your git commits.
Husky AI automatically reviews your staged changes before you commit, catching bugs, security issues, and sloppy code using your favorite local AI engine (OpenCode, Claude, etc.).
- Zero Config: Auto-detects your installed AI tools.
- Auto-fix loop: Runs eslint/prettier/tsc (configurable), auto-formats on prettier failures, optional eslint --fix, then retries. AI fixes are left unstaged with a summary so you can review them.
- Resilient Reviews: Timeouts on AI fix/review calls, truncated large diffs, clear per-tool errors and reports.
- Detailed Reviews: "GitHub-style" comments with code snippets and line numbers.
- Focused Reviews: Reviews added/modified code only and avoids lint/format noise (those are handled by tools).
- Smart Gatekeeping: Blocks commits only for blocker-level issues; other findings are reported as non-blocking.
- Privacy First: Runs locally using your existing CLI tools. Your code goes only where your AI tool sends it.
husky if you don't have it):``bash`
npx husky-ai init
Follow the prompts to select your AI engine (e.g., OpenCode).
`bash`
git add .
git commit -m "feat: my new feature"
Husky AI will intercept the commit, review the changes, and approve or reject it.
Your configuration is stored in package.json:
`json`
{
"huskyAi": {
"engine": "opencode",
"model": "optional-model-name",
"tools": ["eslint", "prettier", "tsc"],
"autoFix": true,
"autoFixPrettier": true,
"autoFixEslint": true,
"autoApplySafeFixes": true,
"applyRiskyFixes": false,
"fixTimeoutMs": 60000,
"reviewTimeoutMs": 90000,
"skipReviewOnFixFail": false,
"reportDir": "/path/to/reports",
"verbose": false
}
}
Options:
- engine (required): AI engine to use (opencode, claude, codex).model
- (optional): Model name for engines that support it.tools
- (optional): Checks to run (eslint, prettier, tsc). Defaults to npm run lint if empty.autoFix
- (optional): Enables the AI auto-fix loop.autoFixPrettier
- (optional): Runs prettier --write when only prettier fails. Default true.autoFixEslint
- (optional): Runs eslint --fix when only eslint fails. Default false.autoApplySafeFixes
- (optional): Applies AI fixes marked safe. Default true.applyRiskyFixes
- (optional): Applies AI fixes marked risky. Default false.fixTimeoutMs
- (optional): Timeout for AI fix calls.reviewTimeoutMs
- (optional): Timeout for semantic review calls.skipReviewOnFixFail
- (optional): Skip review if fix loop fails.reportDir
- (optional): Directory for reports and debug logs.verbose
- (optional): Writes debug logs to reportDir.
Notes:
- Set verbose: true to write debug logs (e.g., to /Users/).autoFixEslint
- runs eslint --fix when eslint is the only failing tool; prettier auto-fix is on by default.fixTimeoutMs
- AI-applied fixes are left unstaged with a summary so you can review before committing.
- /reviewTimeoutMs guard AI calls; adjust if your model is slow.
Supported engines:
- opencode (Recommended)claude
- (Coming soon)codex` (Coming soon)
-
Pull requests are welcome!
MIT