Automated AI-powered code review CLI for Azure DevOps / TFS Pull Requests
Project description
AI Code Review CLI
Automated code review tool with Pull Request integration for Azure DevOps/TFS and support for multiple LLM providers. Documentation where docs/index.md for complete guides on CLI usage, LLM configuration, and architecture.
Features
- AI Pull Request Review — Automated code analysis with configurable LLM providers
- Structured Comments — Inline suggestions + general summary comments
- Dry-run Mode — Validate reviews before posting
- Multiple LLM Providers — OpenAI, Azure OpenAI, Gemini, Claude, Ollama, GitHub Copilot, AWS Bedrock
- Smart Filtering — Filter by file extensions, limit diff size
- Project-aware PR Context — Sends repository and linked work item context while restricting findings to modified PR lines
- RAG Context — Enriches the review with related code snippets found via
git grepin the local repository - Single Reviewer Context — One Markdown context file with local override support
- Usage Tracking — Store per-PR token usage and optional cost estimates
- Interactive CLI — Menu-driven selection and confirmation
Local Repository Requirement
The CLI must be run from inside the local clone of the repository being reviewed.
The PR diff is fetched from Azure DevOps/TFS, but several features depend on the local git state:
| Feature | Local dependency |
|---|---|
| PR diff | git fetch + three-dot diff against origin/<branch> |
| RAG context | git grep on the working tree |
| Branch validation | git branch --show-current |
Branch requirement when RAG is enabled
When review.rag.enabled: true, the local repository must be checked out on the PR target branch (e.g. development). If the local branch differs from the target, the review is blocked:
Local branch mismatch: you are on 'main' but this PR targets 'development'.
RAG context would be built from the wrong branch, which may corrupt the review.
Please run: git checkout development
Example:
# PR: merge 'feature/my-feature' → 'development'
cd /path/to/my-repo # must be inside the repo
git checkout development # must match PR target branch
ai-review pr-review 42
To skip the branch check entirely, disable RAG:
review:
rag:
enabled: false
Installation & Quick Start
1. Install Package
From PyPI:
pip install code-review-ai-cli
With optional LLM SDK extras:
pip install "code-review-ai-cli[bedrock]" # AWS Bedrock
pip install "code-review-ai-cli[openai]" # OpenAI SDK
pip install "code-review-ai-cli[gemini]" # Google Gemini SDK
pip install "code-review-ai-cli[claude]" # Anthropic Claude SDK
pip install "code-review-ai-cli[all]" # All optional SDKs
For development:
pip install -r requirements.txt
pip install "code-review-ai-cli[dev]" # Test suite + linting
2. Initialize Configuration
Generate config templates in your project directory:
ai-review init
Creates:
config.yaml— LLM and review settingsreview_context.example.md— Canonical example reviewer contextreview_context.local.md— Local reviewer context override, ignored by git.gitignoreentry forreview_context.local.md
3. Run Your First Review
# List active PRs
ai-review list-prs
# Review a specific PR
ai-review pr-review 42
# Dry-run (preview without posting)
ai-review pr-review 42 --dry-run
# Check stored token/cost usage
ai-review usage
Configuration File
After ai-review init, edit config.yaml:
llm:
provider: bedrock # or: openai, gemini, claude, etc.
model: anthropic.claude-3-5-sonnet-20240620-v1:0
bedrock:
region: us-east-1
tfs:
base_url: https://dev.azure.com/your-org
project: YourProject
pat: xxxxxxxxx
review:
language: pt
verbosity: detailed # or: quick, security
scope: diff_with_context # diff_with_context, diff_only
file_extensions_filter: [".cs", ".ts", ".py"]
max_diff_files: 50
max_comments_to_post: 20
custom_prompt_file: review_context.local.md
rag:
enabled: true # requires local branch == PR target
max_chars: 40000
project_context:
enabled: true
mode: on_demand # on_demand, full
manifest_max_chars: 60000
retrieval_max_rounds: 2
retrieval_max_files: 20
retrieval_max_chars: 120000
retrieval_file_max_chars: 30000
work_item_context:
enabled: true
max_items: 20
By default, repository context is loaded on demand: the prompt includes explicit
source-branch change packets, full changed-file contents as read-only context,
linked work item documentation, and a repository manifest, then the model
requests any extra files it needs. Inline PR comments must still be grounded in
actual changed lines from the change packets. Set
review.project_context.mode: full to send the full eligible repository
snapshot instead. Bedrock uses a default estimated prompt budget of 180000
tokens; override it with llm.max_prompt_tokens if your model supports more or
less.
Reviewer context is loaded from exactly one Markdown file. By default the CLI
uses review_context.local.md when it exists, otherwise it falls back to the
packaged src/prompts/review_context.example.md. Keep local team tweaks in
review_context.local.md; it is gitignored so the canonical context cannot
drift across machines.
For Copilot-backed reviews, Claude Sonnet models are often strong choices for
large PR validation, for example llm.provider: copilot with a Claude Sonnet
model available to your organization. The tool still enforces the same
source-branch grounding, duplicate checks, and comment cap regardless of model.
Development & Testing
This is a standard Python project with the following structure:
src/
ai_review.py # CLI entry point
config.py # Configuration management
llm_client.py # LLM provider abstraction
tfs_client.py # Azure DevOps integration
git_utils.py # Git diff processing
formatter.py # Output formatting (terminal, markdown, JSON)
rag_engine.py # RAG context via git grep
tests/
test_*.py # Unit and integration tests
RAG Context
Current Implementation
The RAG engine enriches the LLM prompt with related code snippets found in the local repository:
- Extract identifiers — function and class names are parsed from the PR diff
- Search —
git grepfinds files containing those identifiers - Extract snippets — ±10 lines around each match are included as read-only context
All operations run locally with no extra dependencies. The quality of RAG context depends entirely on the local repository state, which is why the local branch must match the PR target branch.
Recommended Stack for Enhanced RAG (Local & Open Source)
For teams wanting semantic similarity instead of keyword search, the recommended local stack is:
| Component | Library | Reason |
|---|---|---|
| Vector database | ChromaDB | Runs in-memory or persists to a local SQLite file — no server needed, pip install chromadb |
| Embeddings | sentence-transformers | Generates vectors locally on CPU — no API calls, no cost |
Example integration pattern:
from sentence_transformers import SentenceTransformer
import chromadb
model = SentenceTransformer("all-MiniLM-L6-v2") # ~80 MB, CPU-friendly
client = chromadb.Client() # in-memory
collection = client.create_collection("repo-index")
# Index
collection.add(
documents=[snippet_text],
embeddings=model.encode([snippet_text]).tolist(),
ids=["file:line"],
)
# Query
results = collection.query(
query_embeddings=model.encode([query]).tolist(),
n_results=5,
)
This stack keeps the CLI lightweight (pip install) and requires no external services or paid APIs.
Run Tests
python -m pytest --cov=src --cov-report=term
Code Quality
Project follows PEP8 with Black formatter and Ruff linter:
# Format code
black src/ tests/
# Lint
ruff check src/ tests/
# Type checking (if using mypy)
mypy src/
VS Code Integration
Predefined tasks for quick execution in VS Code:
Available Tasks
- AI Review: Pull Request (Interactive)
- Interactive mode with main menu
- Run with:
Ctrl+Shift+B→ Select task
- AI Review: PR (Dry-Run)
- Dry-run for a specific PR
- Prompts for PR ID
- AI Review: List Active PRs
- Lists active PRs
- Quick diagnostics
- AI Review: Interactive Mode
- Full tool menu
- Runs in background
How to run tasks
In VS Code:
Ctrl+Shift+P→ "Tasks: Run Task"- Select the desired task
- Fill in parameters if needed
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file code_review_ai_cli-1.3.0.tar.gz.
File metadata
- Download URL: code_review_ai_cli-1.3.0.tar.gz
- Upload date:
- Size: 110.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d65df8396c383e16c682f7bd16f36df9ed204a13bd5231ce2d63e178c2d9d8b
|
|
| MD5 |
3f47581f23b14a15887692da72015164
|
|
| BLAKE2b-256 |
a40ca38699718a20619b643efb9d0bafc50b1d638eaceb5e58682b22b13f1182
|
File details
Details for the file code_review_ai_cli-1.3.0-py3-none-any.whl.
File metadata
- Download URL: code_review_ai_cli-1.3.0-py3-none-any.whl
- Upload date:
- Size: 82.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e6de95c27f4256e75888ecb1efb6e3edeb44de77532e2c3c28cb0c882cb1d2eb
|
|
| MD5 |
fabbe353609f2a37806ad0aaef6fbce4
|
|
| BLAKE2b-256 |
bd04de6196a6c08255d6c648ff93ec0c2b014e6cc52ace80ad2f261684b84d17
|