Agentic pre-commit setup - automatically configures pre-commit hooks for any repository using AI
npm install configure-precommitAutomatically configure pre-commit hooks for any repository using AI-powered analysis.
This tool scans your repository, analyzes its structure and tech stack, and generates an optimal .pre-commit-config.yaml tailored to your project.
Supported stacks:
- Python (ruff, mypy, bandit)
- JavaScript/TypeScript (eslint, prettier)
- Go (golangci-lint, go-fmt)
- Java (pretty-format-java)
- Terraform (terraform_fmt, tflint, checkov)
- Docker (hadolint)
- Shell (shellcheck)
- Plus security scanning (gitleaks) and general hygiene hooks
``bashUsing npx (no install required)
npx configure-precommit
Quick Start
`bash
1. Set your API key
export ANTHROPIC_API_KEY="sk-ant-..."
OR
export OPENAI_API_KEY="sk-..."2. Run in your repository
cd /path/to/your/repo
configure-precommitOr specify a path
configure-precommit /path/to/your/repo
`Requirements
- macOS or Linux (Windows via WSL)
- Node.js >= 14 (for npx/npm)
- Git repository (initialized with
git init)
- API key - Anthropic (preferred) or OpenAI
- System tools: git, jq, curl, python3The script automatically installs
pre-commit if not present.How It Works
`
┌─────────────────────────────────────────────────────────────────┐
│ Phase 1: SENSOR │
│ └── Scan repo structure, detect languages/frameworks │
│ │
│ Phase 2: AUDITOR (LLM) │
│ └── AI analyzes repo, generates optimal pre-commit config │
│ │
│ Phase 3: BUILDER │
│ ├── Write .pre-commit-config.yaml │
│ ├── Run pre-commit autoupdate (get latest versions) │
│ └── Install git hooks │
│ │
│ Phase 4: VERIFICATION & SELF-HEALING │
│ ├── Run pre-commit on all files │
│ └── If config errors → AI debugger fixes → retry (max 3x) │
│ │
│ Phase 5: SUMMARY │
│ └── Report installed hooks and any code issues found │
└─────────────────────────────────────────────────────────────────┘
`CLI Options
`
configure-precommit [OPTIONS] [REPO_PATH]Options:
-h, --help Show help message
-v, --version Show version
--dry-run Generate config without installing hooks
--skip-autoupdate Skip running pre-commit autoupdate
--debug Enable debug output
`Supported Hooks
| Category | Tools | Trigger |
|----------|-------|---------|
| Python | ruff, ruff-format, mypy, bandit |
.py files |
| JavaScript/TypeScript | eslint, prettier | .js, .ts, .jsx, .tsx |
| Go | golangci-lint, go-fmt, go-imports | .go files |
| Java | pretty-format-java | .java files |
| Shell | shellcheck | .sh, .bash files |
| Terraform | terraform_fmt, tflint, checkov | .tf files |
| Docker | hadolint | Dockerfile |
| YAML | yamllint, check-yaml | .yaml, .yml |
| JSON | check-json | .json |
| Security | gitleaks, detect-private-key | All files |
| General | trailing-whitespace, end-of-file-fixer, check-merge-conflict, no-commit-to-branch | All files |Environment Variables
| Variable | Description |
|----------|-------------|
|
ANTHROPIC_API_KEY | Anthropic API key (preferred) |
| OPENAI_API_KEY | OpenAI API key (fallback) |
| PRECOMMIT_MAX_RETRIES | Max self-heal attempts (default: 3) |
| PRECOMMIT_DRY_RUN | Generate config without installing |
| PRECOMMIT_SKIP_AUTOUPDATE | Skip version auto-update |
| DEBUG | Enable debug output |Logging
All operations are logged to
/tmp/precommit-setup/:`bash
View recent logs
ls -lt /tmp/precommit-setup/*.log | head -5Tail a running log
tail -f /tmp/precommit-setup/myrepo_*.log
`Example Output
`
╔═══════════════════════════════════════════════════════════════╗
║ AGENTIC PRE-COMMIT SETUP ║
╚═══════════════════════════════════════════════════════════════╝━━━━━━ PHASE 1: CONTEXTUAL SENSOR ━━━━━━
[INFO] Scanning repository structure...
[INFO] Found 47 files and 3 manifest files
━━━━━━ PHASE 2: AUDITOR (LLM Analysis) ━━━━━━
[INFO] Analyzing repository and generating configuration...
[INFO] Configuration generated successfully
━━━━━━ PHASE 3: BUILDER ━━━━━━
[INFO] Wrote configuration to .pre-commit-config.yaml
[INFO] Updating hook versions to latest...
[INFO] Git hooks installed successfully
━━━━━━ PHASE 4: VERIFICATION ━━━━━━
[INFO] All hooks passed successfully!
━━━━━━ PHASE 5: SUMMARY ━━━━━━
INSTALLED HOOKS:
- gitleaks
- ruff
- ruff-format
- shellcheck
- check-yaml
...
[INFO] Setup complete!
`Troubleshooting
$3
Initialize git first: git init$3
Remove it first: rm .pre-commit-config.yaml$3
Set one of:
`bash
export ANTHROPIC_API_KEY="sk-ant-..."
export OPENAI_API_KEY="sk-..."
`$3
The debugger will automatically move those hooks to stages: [manual]. Install the tools later and run manually with pre-commit run .File Structure
`
configure-precommit/
├── package.json # npm package config
├── bin/
│ └── configure-precommit # CLI entry point
├── setup-precommit.sh # Main orchestration script
├── lib/
│ ├── logging.sh # Logging utilities
│ ├── sensor.sh # Repository scanning
│ ├── builder.sh # Pre-commit installation
│ └── verifier.sh # Verification loop
├── tests/
│ └── run_tests.sh # Test suite
└── README.md
`Development
`bash
Clone the repo
git clone https://github.com/avivkaplan/configure-precommit.git
cd configure-precommitRun tests (requires API key)
./tests/run_tests.shLint shell scripts
shellcheck lib/*.sh bin/configure-precommit setup-precommit.sh
``MIT