semantic-diff
AI-powered semantic analysis of git commits. Goes beyond git diff to show intent, impact, risk, and review questions.
What it does
Regular git diff shows what changed. semantic-diff shows:
| git diff | semantic-diff | |
|---|---|---|
| What | Lines added/removed | Same |
| Why | - | Intent behind the change |
| Risk | - | What could break, edge cases |
| Impact | - | Direct and indirect effects |
| Review | - | Questions to ask the author |
Installation
pip install semantic-diff
Quick Start
# Set your API key
export ANTHROPIC_API_KEY=sk-ant-...
# Analyze a commit
semantic-diff HEAD
# Enable automatic analysis before every push
semantic-diff init
That's it! Now every git push will automatically analyze your commits and save reports.
How It Works
Manual Analysis
# Analyze HEAD commit
semantic-diff
# Analyze specific commit
semantic-diff abc123
# Save report to file
semantic-diff HEAD --save
# Output as JSON
semantic-diff HEAD --json
Automatic Analysis (Pre-Push Hook)
# Install the hook (once per project)
semantic-diff init
# Now every push triggers analysis automatically
git push # → runs semantic-diff, saves report, then pushes
Reports
Reports are saved to semantic_diff_reports/ in your project root:
my-project/
├── semantic_diff_reports/
│ ├── abc12345_20240115_143022.md
│ ├── def67890_20240115_152341.md
│ └── ...
├── src/
└── ...
Each report includes:
- Commit metadata
- Intent analysis with confidence score
- Impact map (direct and indirect effects)
- Risk assessment with mitigations
- Review questions prioritized by importance
GitHub Action
Add to your workflow to analyze PRs automatically:
# .github/workflows/semantic-diff.yml
name: Semantic Diff
on: [pull_request]
jobs:
analyze:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: tkenaz/semantic_diff@v0.3.0
with:
anthropic_api_key: ${{ secrets.ANTHROPIC_API_KEY }}
comment_on_pr: true
fail_on_risk: high # optional: block merge on high risk
Example Output
Analysis Overview
Intent analysis with 98% confidence, risk assessment, and review questions
What It Finds
Real example: semantic-diff analyzing itself found XSS vulnerabilities, CI issues, and security misconfigurations
Configuration
Create a .env file in your project or set environment variables:
# Required
ANTHROPIC_API_KEY=sk-ant-...
# Optional
SEMANTIC_DIFF_MODEL=claude-sonnet-5-5 # or claude-opus-5-5
OpenAI-compatible gateways
Any gateway that speaks the OpenAI Chat Completions protocol (LiteLLM, vLLM,
corporate LLM hubs, OpenAI itself) works through the openai provider:
pip install 'semantic-diff[openai]'
SEMANTIC_DIFF_PROVIDER=openai
SEMANTIC_DIFF_BASE_URL=https://your-gateway.example/v1
SEMANTIC_DIFF_API_KEY=...
SEMANTIC_DIFF_MODEL=claude-sonnet-4.6 # required: model ids differ per gateway
Retries (rate limits honour Retry-After, timeouts, 5xx) are handled once for
all providers: SEMANTIC_DIFF_MAX_RETRIES (attempts, default 3) and
SEMANTIC_DIFF_MAX_WAIT (seconds, default 30).
Diff budget
Large changes are not cut blindly. Diffs are packed into a token budget
(--max-diff-tokens / SEMANTIC_DIFF_MAX_DIFF_TOKENS, default 60,000):
code first, then migrations, CI/infra, tests, docs. A file that does not fit
whole is trimmed at hunk boundaries, never mid-line. Lock files, generated
output and binaries are listed but never shown. The model is told which files
it did not see, and every report states the coverage, e.g.
Diff coverage: 87% of changed lines plus the trimmed/not-shown files.
Agentic review
semantic-diff review goes further than mr: instead of one call over the
diff, an agent reads around the change - whole functions, callers, the file
before the change, history - with read-only tools, and submits findings tied
to lines.
semantic-diff review --base origin/dev --save
semantic-diff review --gitlab-env --json # inside a GitLab MR pipeline
- Tools read git objects at the merge request's head and base, never the working tree: uncommitted files are invisible to the model.
- Every review is bounded:
--max-turns(SEMANTIC_DIFF_MAX_TURNS, default 25),--max-input-tokens(SEMANTIC_DIFF_MAX_INPUT_TOKENS, default 1,000,000, cached tokens included) and the diff shown up front (--max-diff-tokens/SEMANTIC_DIFF_REVIEW_DIFF_TOKENS, default 30,000). When a limit is reached the model gets one last turn to submit what it has, and the report says which limit cut the review short. - Each finding is checked in code: does the cited line exist (after the change, or only before it), and did the model actually see the file. The report flags findings that fail either check.
- Needs a provider with tool calling:
SEMANTIC_DIFF_PROVIDER=openai(any OpenAI-compatible gateway). Prompt caching is used where the gateway supports it, so each turn re-reads the conversation from cache.
Commands
| Command | Description |
|---|---|
semantic-diff |
Analyze HEAD commit |
semantic-diff <hash> |
Analyze specific commit |
semantic-diff --save |
Save report to semantic_diff_reports/ |
semantic-diff --json |
Output as JSON |
semantic-diff mr --base origin/main |
Analyze a whole merge request (merge-base..HEAD) |
semantic-diff mr --gitlab-env |
Same, inside a GitLab MR pipeline (reads CI_MERGE_REQUEST_*) |
--max-diff-tokens N |
Diff budget for the prompt (default 60000) |
--max-output-tokens N |
Room for the model's answer (default 32000; env SEMANTIC_DIFF_MAX_OUTPUT_TOKENS) |
semantic-diff review --base origin/main |
Agentic review of a merge request (see above) |
semantic-diff init |
Install pre-push hook |
semantic-diff uninstall |
Remove pre-push hook |
Development
git clone https://github.com/tkenaz/semantic_diff.git
cd semantic_diff
pip install -e ".[dev]"
pytest
Support
- Bug reports & features: GitHub Issues
- Custom integrations or enterprise: hello@kenaz.ai
License
MIT — Kenaz GmbH
Built with 🖤 by Kenaz GmbH — AI tools for developers
Metadata
Release files for semantic-diff 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| semantic_diff-0.3.0.tar.gz | 92.2 kB | Without provenance | Details for semantic_diff-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| semantic_diff-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for semantic_diff-0.3.0-py3-none-any.whl |
Total release size: 141.0 kB
Release files / semantic_diff-0.3.0.tar.gz
| Download URL | semantic_diff-0.3.0.tar.gz |
|---|---|
| Size | 92.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
46610acbc92ce4704ecf93e3fe81a630762074dfdc02e62c6e10419d97dca7f5
|
|
BLAKE2b-256 checksum How to use checksums |
6e7dc6c9e374ada5e4b646fb9bbcd4e876fc4140f167fa38e54b4c6e1c45692b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.17
|
Release files / semantic_diff-0.3.0-py3-none-any.whl
| Download URL | semantic_diff-0.3.0-py3-none-any.whl |
|---|---|
| Size | 48.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0c015a9a426f2723e6fd295bfcc44370ec174f34631f148555959182d18632de
|
|
BLAKE2b-256 checksum How to use checksums |
caf31601f67f3e6d27fcb86d6e954ef5eec3b356a113288abe488174edece1b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.11.17
|
Security for semantic-diff 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.