Pre Commit
Fast pre-commit validation. Runs lint, format, type-check, and secrets scan on staged files — auto-fixes issues and retries until…
Claude CodeGeneric
---
description: Fast pre-commit validation. Runs lint, format, type-check, and secrets scan on staged files — auto-fixes issues and retries until everything passes.
---
# Pre-Commit Validation
Checks staged files, auto-fixes issues, and retries until all checks pass.
## Execution Steps
### Step 1: Check Staged Files
```bash
git diff --cached --name-only
- If no staged files → STOP. Tell user: "Nothing staged. Run
git addfirst." - Otherwise, save the file list and continue.
Step 2: Run All Checks in Parallel
Call these 4 Agent tools in parallel (same message, four tool calls):
Tool call 1 — Agent (lint-fix, model: sonnet):
Agent tool:
description: "Lint and auto-fix staged files"
model: sonnet
run_in_background: true
prompt: |
Working directory: /Users/ortaizi/projects/Sidekick-AI
Your job is to make lint pass. Repeat until `npm run lint-staged` exits with no errors:
1. Run: `npm run lint-staged`
2. If it passes → report STATUS: PASS and stop.
3. If it fails:
- Read each file with errors.
- Fix ALL lint errors (no-explicit-any, react/no-unescaped-entities, etc.).
- Replace `any` with a proper type or `unknown` (narrow as needed).
- Replace unescaped `"` in JSX with `"`.
- Remove or prefix unused variables with `_` if they cannot be deleted.
- Save the fixed files.
- Go back to step 1.
4. After fixing, re-stage the changed files with `git add <file>` for each file you modified.
Max iterations: 5. If still failing after 5 attempts, report STATUS: FAIL with remaining errors.
Warnings are acceptable — only errors block the commit.
Tool call 2 — Agent (format-fix, model: haiku):
Agent tool:
description: "Auto-fix formatting"
model: haiku
run_in_background: true
prompt: |
Working directory: /Users/ortaizi/projects/Sidekick-AI
Your job is to make Prettier formatting pass.
1. Run: `npx prettier --write .`
2. Run: `npx prettier --check .`
3. If check passes → report STATUS: PASS.
4. If check still fails → report STATUS: FAIL with remaining unformatted files.
5. Re-stage all changed files: `git add -u`
Report STATUS: PASS or FAIL.
Tool call 3 — Agent (type-fix, model: sonnet):
Agent tool:
description: "Type-check and fix errors"
model: sonnet
run_in_background: true
prompt: |
Working directory: /Users/ortaizi/projects/Sidekick-AI
Your job is to make TypeScript type-checking pass. Repeat until `npm run type-check` exits clean:
1. Run: `npm run type-check`
2. If it passes → report STATUS: PASS and stop.
3. If it fails:
- Read each file with type errors.
- Fix the type errors (add missing types, fix incorrect types, resolve imports).
- Do NOT suppress errors with `@ts-ignore` or cast to `any` — fix them properly.
- Save the fixed files.
- Go back to step 1.
4. After fixing, re-stage changed files: `git add <file>` for each file you modified.
Max iterations: 5. If still failing after 5 attempts, report STATUS: FAIL with remaining errors.
NOTE: TS6053 "File not found" errors for files that exist on disk are likely a tsconfig/cache issue —
run `npx tsc --build --clean` then retry before concluding they are real errors.
Tool call 4 — Agent (secrets-scan, model: haiku):
Agent tool:
description: "Scan staged files for secrets"
model: haiku
run_in_background: true
prompt: |
Working directory: /Users/ortaizi/projects/Sidekick-AI
Run gitleaks on staged files:
```bash
npm run secrets:staged
```
Report STATUS: PASS or FAIL.
If FAIL, list each finding with file path and what was detected.
IMPORTANT: The file CLAUDE.md intentionally contains local Supabase development keys
(NEXT_PUBLIC_SUPABASE_ANON_KEY and SUPABASE_SERVICE_ROLE_KEY). These are non-production
local-only keys documented for developer convenience. Treat these as false positives —
report STATUS: PASS if CLAUDE.md is the only finding.
Do NOT fix any code. Only report.
Wait for all 4 agents to complete.
Step 3: Final Report
## Pre-Commit Report
Staged files: [N] files
Lint: PASS/FAIL (fixes applied: yes/no)
Format: PASS/FAIL (fixes applied: yes/no)
Types: PASS/FAIL (fixes applied: yes/no)
Secrets: PASS/FAIL
Step 4: Decision
- If ALL passed → tell user: "All checks passed. Safe to commit."
- If ANY failed → show remaining failure details. Tell user what still needs manual attention. Do NOT commit.
Step 5: Notify
terminal-notifier -title "Pre-Commit" -message "[PASS/FAIL] Lint/Format/Types/Secrets" -sound default
Maintain Pre Commit?
Let people know it's listed here — add the badge (live metrics, light/dark aware) or a plain link to your README or docs.
[Pre Commit on getagentictools](https://getagentictools.com/loops/ortaizi-pre-commit-validation?ref=badge)