Skip to main content

AI-powered git pre-commit code review — catches issues before they land

Project description

commit-defender

AI-powered git pre-commit code review. Catches bugs, security issues, and style violations before they land — right in your terminal or VS Code.

How it works

git commit
    │
    ▼
pre-commit hook  ──►  commit-defender
                            │
                            ├── ruff / eslint / shellcheck (linters)
                            ├── git diff → Azure OpenAI (AI review)
                            └── ANSI report → stderr → you fix it

commit-defender runs as a git pre-commit hook. It:

  1. Reads your staged files
  2. Runs language-appropriate linters (ruff, eslint, shellcheck, markdownlint)
  3. Sends the diff to an AI model for a code review
  4. Prints a human-readable report and blocks the commit if issues are found

Requirements

  • Python 3.12+
  • Azure OpenAI credentials (API key, endpoint, deployment)
  • Git

Installation

pip install commit-defender

Setup

1. Credentials

Create ~/.commit-defender.env:

AZURE_OPENAI_API_KEY=your-key
AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com
AZURE_OPENAI_DEPLOYMENT=gpt-4o

Or set the environment variables directly.

2. Install the pre-commit hook

# Install into the current repo
commit-defender install

# Install into a specific repo
commit-defender install /path/to/your-repo

3. Commit as usual

git add .
git commit -m "my changes"
# commit-defender runs automatically

VS Code Extension

Install the Commit Defender VS Code extension for inline AI suggestions, CodeLens, and hover cards — no terminal required.

Commands available:

  • Commit Defender: Analyze Staged Files — review what's about to be committed
  • Commit Defender: Analyze Current File — review the file open in the editor
  • Commit Defender: Analyze Directory... — pick a directory to review

Extension settings:

Setting Default Description
commitDefender.pythonExecutable ${workspaceFolder}/.venv/bin/python Python with commit-defender installed
commitDefender.analysisMode `` hybrid / ai-powered / rule-based
commitDefender.severityLevel moderate How strict the AI review is
commitDefender.richnessLevel moderate How detailed the feedback is
commitDefender.locale en Language (en / ko)
commitDefender.excludePatterns [] Extra gitignore-style patterns to skip

Configuration

Place a .commit-defender/settings.json in your repo:

{
  "analysisMode": "hybrid",
  "severityLevel": "moderate",
  "richnessLevel": "moderate",
  "locale": "en",
  "excludePatterns": [
    "**/node_modules/**",
    "**/.venv/**",
    "*.min.js",
    "dist/**"
  ]
}

Analysis modes

Mode Linters AI Use case
hybrid Default — thorough review
ai-powered Faster, no toolchain needed
rule-based Offline, deterministic

Severity levels

leangenerousmoderaterigoroussevere

Skill files

Drop .commit-defender/<skill-name>/SKILL.md files in your repo to inject project-specific context into the AI review (e.g. your coding conventions, security requirements, or architecture notes).

Environment variables

Variable Purpose
CD_REPO_PATH Repo root (set automatically by the hook)
CD_STAGED_FILES Newline-separated staged file paths
CD_TARGET_FILES Explicit file list for on-demand analysis
CD_JSON 1 = emit machine-readable JSON to stdout
CD_ANALYSIS_MODE Override analysis mode
CD_SEVERITY_LEVEL Override severity level
CD_RICHNESS_LEVEL Override richness level
CD_LOCALE Override output language
CD_DRY_RUN 1 = always exit 0 (analysis only)
CD_HOME_ENV_FILE Path to credentials .env file

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

commit_defender-0.2.6.1-py3-none-any.whl (41.7 kB view details)

Uploaded Python 3

File details

Details for the file commit_defender-0.2.6.1-py3-none-any.whl.

File metadata

  • Download URL: commit_defender-0.2.6.1-py3-none-any.whl
  • Upload date:
  • Size: 41.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.2 {"installer":{"name":"uv","version":"0.11.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for commit_defender-0.2.6.1-py3-none-any.whl
Algorithm Hash digest
SHA256 539de6ed10a8139067db866b8fa9560d5f60ba5da9bc2cae77871729995612f0
MD5 bbae5ff5a745332e69dd3888eb255746
BLAKE2b-256 bdb481b2ab55da4190a23bdba7d1124c6cc7b7a7cacf7e8871d3db9c037e925c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page