configure-precommit
v1.0.4
Published
Agentic pre-commit setup - automatically configures pre-commit hooks for any repository using AI
Maintainers
Readme
configure-precommit
Automatically configure pre-commit hooks for any repository using AI-powered analysis.
Overview
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
Installation
# Using npx (no install required)
npx configure-precommit
# Or install globally
npm install -g configure-precommitQuick Start
# 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-precommit
# Or specify a path
configure-precommit /path/to/your/repoRequirements
- 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, python3
The 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 outputSupported 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/:
# View recent logs
ls -lt /tmp/precommit-setup/*.log | head -5
# Tail a running log
tail -f /tmp/precommit-setup/myrepo_*.logExample 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
"Not a git repository"
Initialize git first: git init
".pre-commit-config.yaml already exists"
Remove it first: rm .pre-commit-config.yaml
"No API key found"
Set one of:
export ANTHROPIC_API_KEY="sk-ant-..."
export OPENAI_API_KEY="sk-..."Hooks fail due to missing tools
The debugger will automatically move those hooks to stages: [manual]. Install the tools later and run manually with pre-commit run <hook-id> --all-files.
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.mdDevelopment
# Clone the repo
git clone https://github.com/avivkaplan/configure-precommit.git
cd configure-precommit
# Run tests (requires API key)
./tests/run_tests.sh
# Lint shell scripts
shellcheck lib/*.sh bin/configure-precommit setup-precommit.shLicense
MIT
