Skip to content

Instantly share code, notes, and snippets.

@snarktank
Created July 26, 2025 09:31
Show Gist options
  • Save snarktank/a3fcd3015b3e68711d0bd006f8470995 to your computer and use it in GitHub Desktop.
Save snarktank/a3fcd3015b3e68711d0bd006f8470995 to your computer and use it in GitHub Desktop.
Pre-commit Hook with Amp Oracle Review

Pre-commit Hook with Amp Oracle Review

A minimal Husky pre-commit hook with AI-powered code review via Amp's Oracle feature.

Features

  • 🔮 AI Code Review: Optional Oracle review via Amp before committing
  • 🧪 Test Validation: Runs all tests before allowing commit
  • Minimal & Fast: No unnecessary dependencies
  • 🌍 Universal: Works with any Node.js project

Setup Instructions

  1. Install Husky:

    npm install --save-dev husky
  2. Initialize Husky:

    npx husky init
  3. Replace the pre-commit hook:

    # Copy the script content to .husky/pre-commit
    chmod +x .husky/pre-commit

Usage

Normal commit (with Oracle review):

git commit -m "your commit message"

Skip Oracle review:

SKIP_ORACLE_REVIEW=true git commit -m "your commit message"

What it does

  1. Runs Oracle review (if Amp CLI is available and not explicitly skipped)
  2. Executes all tests via npm test
  3. Prevents commit if tests fail
  4. Allows commit if all checks pass

Requirements

  • Node.js project with npm test command configured
  • Optional: Amp CLI for Oracle reviews
  • Husky for git hooks

Customization

Need environment variables? Add them safely:

export MY_VAR="safe_value"

Need different test command? Replace npm test with:

yarn test
pnpm test
npm run test:ci
#!/bin/sh
echo "🔍 Running pre-commit checks..."
# Review changes with Oracle before committing (optional)
if command -v amp >/dev/null 2>&1 && [ "${SKIP_ORACLE_REVIEW:-false}" != "true" ]; then
echo "🔮 Reviewing changes with Oracle..."
amp -x "Review the changes we're about to commit, consult the oracle" || echo "⚠️ Oracle review failed, continuing..."
else
echo "ℹ️ Skipping Oracle review (amp not available or SKIP_ORACLE_REVIEW=true)"
fi
# Run all tests before commit
echo "🧪 Running all tests..."
npm test
echo "✅ Pre-commit checks passed!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment