Pre-commit hooks that run fast checks for humans and thorough checks for AI agents.
Human commit: ~3s Agent commit: ~5min
├─ pre-commit (staged) ├─ pre-commit (all files)
└─ done ├─ tests, build, security
└─ merge conflict check
AI agents commit once when done. If that commit fails CI, you waste a round-trip fixing it. agent-precommit runs CI-level checks locally before the commit, so agent commits are merge-ready.
cargo install agent-precommit
cd your-project
apc init # Creates agent-precommit.toml
apc install # Installs git hookIf you have an existing .pre-commit-config.yaml, apc init detects it and wraps it automatically.
Set AGENT_MODE=1 when committing from an agent. Add this to your agent's instructions (CLAUDE.md, .cursor/rules, etc.):
When committing, use: AGENT_MODE=1 git commit -m "message"
Or create a git alias:
git config alias.acommit '!AGENT_MODE=1 git commit'If AGENT_MODE isn't set, the tool checks (in order):
APC_MODEenvironment variable (explicit override)AGENT_MODE=1environment variable- Known agent env vars (
CLAUDE_CODE,CURSOR_SESSION,AIDER_MODEL, etc.) - Custom agent env vars from config (
detection.agent_env_vars) - CI environment (
GITHUB_ACTIONS,GITLAB_CI,CI, etc.) - No TTY (non-interactive terminal)
- Default: human
agent-precommit.toml:
[detection]
agent_env_vars = ["MY_AGENT"] # Custom env vars that trigger agent mode
[integration]
pre_commit = true # Wrap existing .pre-commit-config.yaml
[human]
checks = ["pre-commit"]
timeout = "30s"
[agent]
checks = [
"pre-commit-all",
"no-merge-conflicts",
"test-unit",
"build-verify",
]
timeout = "15m"
[checks.test-unit]
run = "cargo test"
[checks.build-verify]
run = "cargo build --release"apc init --preset=python # ruff, pytest, mypy
apc init --preset=node # eslint, jest, tsc
apc init --preset=rust # cargo fmt, clippy, test
apc init --preset=go # gofmt, golangci-lint, go testagent-precommit is designed to work alongside the pre-commit framework, not replace it. Here's how they interact:
-
apc installreplaces the git hook - When you runapc install, it installs its own.git/hooks/pre-commitscript that callsapc run. If a pre-commit framework hook already exists, it backs it up topre-commit.bak. -
apcwraps pre-commit as a check - The built-inpre-commitandpre-commit-allchecks call thepre-commitCLI tool:pre-commit→ Runspre-commit run(staged files only, for humans)pre-commit-all→ Runspre-commit run --all-files(for agents)
-
Your
.pre-commit-config.yamlstays unchanged - All your existing pre-commit hooks continue to work exactly as before.
# If you already have .pre-commit-config.yaml
apc init # Auto-detects and enables integration
apc install # Replaces pre-commit's hook with apc's hook
# Your flow stays the same
git add .
git commit # apc runs, which runs pre-commit + other checks| Mode | What Happens |
|---|---|
| Human | apc → pre-commit run (staged files only) |
| Agent | apc → pre-commit run --all-files + tests + build + merge check |
apc uninstall # Removes apc hook
mv .git/hooks/pre-commit.bak .git/hooks/pre-commit # Restore backup
# Or: pre-commit install # Reinstall pre-commit's hookapc init # Create config
apc install # Install git hook
apc uninstall # Remove hook
apc run # Run checks (auto-detect mode)
apc run --mode=agent # Force agent mode
apc run --check=test-unit # Run single check
apc detect # Show detected mode
apc list # List checks
apc validate # Validate config
apc config # Show config file location
apc completions bash # Generate shell completions (bash/zsh/fish)| Variable | Description |
|---|---|
APC_MODE |
Force mode: human, agent, or ci |
AGENT_MODE |
Set to 1 for agent mode |
APC_SKIP |
Set to 1 to skip all checks |
git commit --no-verify -m "skip checks"
APC_SKIP=1 git commit -m "skip checks"MIT