llm-code-review
is a command-line tool for automated code reviews of GitHub pull requests using OpenAI's GPT models or local models via Ollama. It fetches modified files, extracts diffs, retrieves full file contents for context, and generates concise, constructive code reviews.
- Supports OpenAI API (
gpt-4o-mini
, etc.) - Supports local models via Ollama
- Fetches diffs from GitHub pull requests
- Retrieves full file contents for context
- Provides AI-generated feedback with before/after code snippets
- Filters reviews to focus only on Python files
Install the package from PyPI:
pip install llm-code-review
To review a GitHub pull request:
llm-code-review owner/repository PR_NUMBER
Example:
llm-code-review octocat/hello-world 42
Note that this defaults to OpenAI's gpt-4o-mini
and you have to top up your credit to use it. If you don't want to spend money, download Ollama and use a local model for your code reviews (see below).
llm-code-review octocat/hello-world 42 --model openai:gpt-4o-mini
llm-code-review octocat/Hello-World 42 --model ollama:deepseek-r1:8b
This command fetches the pull request #42 from the octocat/Hello-World
repository, retrieves modified Python files, and reviews the changes using OpenAI.
Before using the tool, you must set up the required API keys as environment variables:
- GitHub Token: To authenticate API requests, create a GitHub personal access token (with
repo
scope for private repositories) and set it as an environment variable. - OpenAI API Key: Obtain an API key from OpenAI and set it as an environment variable.
Add the following lines to your shell profile (e.g., ~/.bashrc
, ~/.zshrc
):
export GITHUB_TOKEN="your_github_token"
export OPENAI_API_KEY="your_openai_api_key"
Then, reload your shell profile:
source ~/.bashrc # or source ~/.zshrc
If you prefer to keep your API keys separate from your shell profile, you can use direnv
to automatically load environment variables when you enter a project directory.
-
Install
direnv
:sudo apt install direnv # Ubuntu/Debian brew install direnv # macOS
-
Enable
direnv
in your shell:echo 'eval "$(direnv hook bash)"' >> ~/.bashrc # For Bash echo 'eval "$(direnv hook zsh)"' >> ~/.zshrc # For Zsh source ~/.bashrc # or source ~/.zshrc
-
Create a
.envrc
file in your project directory:echo 'export GITHUB_TOKEN="your_github_token"' > .envrc echo 'export OPENAI_API_KEY="your_openai_api_key"' >> .envrc
-
Allow
direnv
to load the file:direnv allow
Now, every time you enter the project directory, your API keys will be automatically loaded.
- Fetches pull request details from GitHub.
- Retrieves the full content of modified Python files.
- Sends the diff and full file content to OpenAI for review.
- Displays feedback, focusing on potential improvements and critical issues.
- Only Python (
.py
) files are reviewed. - The review focuses on changes in the PR while using the full file context.
- If a file has more than three issues, only the most important one is highlighted unless critical issues are found.
MIT License
Feel free to open issues or submit pull requests!
Author: Geir Freysson