Patchlens is a command-line reviewer for GitLab merge requests and GitHub pull requests. It fetches a change request diff, sends the patch to a configured LLM, and prints a structured review locally or posts a summary plus inline comments back to the MR/PR.
The project is intentionally small: one Go binary, no runtime service, and a user-level JSON config file.
- Review GitLab merge requests and GitHub pull requests from flags or a URL.
- Post review summaries and inline comments back to GitLab or GitHub.
- Use OpenAI, Anthropic, Ollama, or a custom OpenAI-compatible chat endpoint.
- Choose focused review modes:
syntax,logic,business, orcomprehensive. - Add repository-specific business context from a local file.
- Print human-readable output or machine-readable JSON.
- Infer repository paths from
git remote get-url originwhen possible.
Patchlens is early-stage software. It is useful today, but APIs, prompts, defaults, and output schemas may change before a stable release. Treat posted comments as assistant-generated review suggestions and keep a human reviewer in the loop.
- Go 1.24 or newer.
- A GitLab or GitHub token with access to the target repository.
- One LLM backend:
- OpenAI-compatible chat completions endpoint.
- Anthropic Messages API.
- Ollama running locally.
- A custom endpoint compatible with Patchlens' OpenAI-style request flow.
Build from source:
git clone https://github.com/CHashtager/patchlens.git
cd patchlens
make buildThe binary is written to bin/patchlens.
You can also install with Go:
go install github.com/CHashtager/patchlens/cmd/patchlens@latestFor local development builds:
go build -o patchlens ./cmd/patchlensConfigure Patchlens once:
patchlens configure \
--provider github \
--github-token YOUR_GITHUB_TOKEN \
--llm-provider openai \
--llm-api-key YOUR_LLM_API_KEY \
--llm-model gpt-4Review a GitHub pull request without posting:
patchlens review --repo owner/repo --pr 123Review a GitLab merge request without posting:
patchlens review --provider gitlab --project group/project --mr 123Review from a URL and post the result:
patchlens review --url https://github.com/owner/repo/pull/123 --post
patchlens review --url https://gitlab.com/group/project/-/merge_requests/123 --postStores user-level settings in your operating system config directory.
Common flags:
--provider gitlab|github
--gitlab-url https://gitlab.com
--gitlab-token TOKEN
--github-api-url https://api.github.com
--github-token TOKEN
--llm-provider openai|anthropic|ollama|custom
--llm-api-url URL
--llm-api-key TOKEN
--llm-model MODEL
--llm-reasoning-effort default|low|medium|high
--review-mode syntax|logic|business|comprehensive
--business-context-file PATH
If no flags are provided and stdin is interactive, Patchlens prompts for values.
Show the redacted config:
patchlens config showPrint the config path:
patchlens config pathFetches a change request, asks the configured LLM to review the diff, and prints or posts the result.
Common flags:
--provider gitlab|github
--project group/project
--mr 123
--repo owner/repo
--pr 123
--url https://github.com/owner/repo/pull/123
--mode syntax|logic|business|comprehensive
--context path/to/context.md
--cwd /path/to/repo
--post
--json
Examples:
patchlens review --provider github --repo owner/repo --pr 123 --mode logic
patchlens review --provider gitlab --project group/project --mr 123 --json
patchlens review --url https://gitlab.example.com/team/app/-/merge_requests/42 --postsyntax: style, formatting, naming, imports, typos, and syntax issues.logic: correctness, edge cases, error handling, algorithm behavior, and races.business: domain correctness, requirement alignment, and validation.comprehensive: syntax, logic, performance, security, maintainability, and tests.
The default mode is comprehensive.
Patchlens can include a local context file in business and comprehensive reviews. By default it looks for:
.gitlab-ai-context.md
You can configure another default:
patchlens configure --business-context-file docs/review-context.mdOr override it per review:
patchlens review --repo owner/repo --pr 123 --context docs/review-context.mdGood context files are short and practical: product rules, domain terms, important invariants, security constraints, and known review preferences.
Patchlens stores config at:
- macOS:
~/Library/Application Support/patchlens/config.json - Linux:
~/.config/patchlens/config.json - Windows:
%AppData%\patchlens\config.json
Example:
{
"provider": "github",
"gitlab": {
"url": "https://gitlab.com",
"token": "glpat_xxx"
},
"github": {
"apiUrl": "https://api.github.com",
"token": "github_pat_xxx"
},
"llm": {
"provider": "openai",
"apiUrl": "",
"apiKey": "sk_xxx",
"model": "gpt-4",
"reasoningEffort": "default"
},
"review": {
"mode": "comprehensive",
"businessContextFile": ".gitlab-ai-context.md"
}
}Config files are written with user-only permissions where supported by the operating system. Do not commit real tokens.
Use the least-privileged token that supports your workflow.
For GitLab, a personal access token with API access is required for fetching MRs and posting comments.
For GitHub, a classic token usually needs repository access for private repositories. A fine-grained token should have access to the target repository and enough pull request, issue, and contents permissions to read changed files and write comments when --post is used.
Patchlens sends diffs and optional business context to the configured LLM provider. Review your provider's data policy before using Patchlens on private code.
OpenAI:
patchlens configure \
--llm-provider openai \
--llm-api-key YOUR_KEY \
--llm-model gpt-4Anthropic:
patchlens configure \
--llm-provider anthropic \
--llm-api-key YOUR_KEY \
--llm-model YOUR_ANTHROPIC_MODELOllama:
ollama serve
ollama pull llama3.1
patchlens configure \
--llm-provider ollama \
--llm-model llama3.1Custom OpenAI-compatible endpoint:
patchlens configure \
--llm-provider custom \
--llm-api-url https://llm.example.com/v1 \
--llm-api-key YOUR_KEY \
--llm-model your-modelUseful commands:
make help
make build
make test
make fmt
make vet
make check
make run ARGS="config show"Project layout:
cmd/patchlens/ CLI entry point and command parsing
internal/config/ User config loading, defaults, validation, redaction
internal/llm/ LLM provider clients
internal/review/ Review prompt, result parsing, printing, comment formatting
internal/scm/ GitLab and GitHub API clients
Ideas that fit the current project direction:
- Tests for URL parsing, config validation, review parsing, and provider clients.
- Better diff position mapping for inline comments.
- Dry-run output for comments that would be posted.
- Configurable output templates.
- CI release builds for common platforms.
- More precise provider documentation and examples.
Patchlens is released under the MIT License. See LICENSE.