June 13, 2025 · essay
Local PR Buddy For Better Code Insights Before You Push
Meet Local PR Buddy: Your AI co-pilot for Git! Get descriptions, reviews, improvement suggestions, and answers about your code changes locally, before you even create a Pull Request. Shift left and code smarter!
The short version
- LLM
- The Local PR Buddy tool itself uses LLMs (configurable via LiteLLM, e.g., GPT-4o-mini, Claude, Gemini) to analyze code. This blog post was drafted with AI assistance to explain the tool.
- Why
- To introduce 'Local PR Buddy,' a CLI tool (with planned VS Code integration) that provides AI-powered feedback on local Git changes (branch diffs or staged changes) before a remote Pull Request is created, enabling developers to 'shift left' and improve code quality early.
- Challenge
- Bridging the gap between local development and formal PR reviews. Many issues are caught late. Newer developers can be intimidated by PRs. This tool aims to provide early, private, AI-driven insights (describe, review, improve, ask) to address these challenges.
- Outcome
- A functional Python CLI tool with four core AI-powered commands that analyze local Git diffs. The tool is designed to be extensible and integrate with VS Code, promoting better coding habits and earlier issue detection. This blog post explains its features, benefits, and future vision.
- AI approach
- Local PR Buddy is an AI-First tool for developers. It uses LLMs as its core analysis engine. The development of the tool itself heavily involved AI for code generation, prompt refinement, and debugging, embodying an AI-First development philosophy for creating AI-powered developer tools.
- Learnings
- Developing a local-first AI tool requires robust Git interaction (handling branch diffs, staged changes, merge-bases), effective prompt engineering for varied AI tasks (summarization, review, suggestion, Q&A), and a modular architecture. Providing full content of new files to the AI is crucial for accurate analysis. VS Code integration is key for usability.
Local PR Buddy For Better Code Insights Before You Push
We've all been there. You've poured your energy into a new feature or a tricky bug fix. Your branch is a testament to your efforts, and now it's time to share it with the world – or at least, with your team. But as you hover over the "Create Pull Request" button, a familiar wave of questions might surface: "Is this really ready?", "Did I overlook something critical?", "How can I best explain these changes?" That moment, filled with a mix of accomplishment and slight trepidation, is universal.
Getting feedback is a cornerstone of quality software development, but traditionally, that feedback loop starts after you've formally proposed your changes. What if you could shift that process left, getting a valuable "second look" and helpful insights right on your local machine, long before your code faces public scrutiny? This desire for earlier, private, and constructive feedback, much like the importance of nailing down your user story before you build, is what inspired the creation of Local PR Buddy.
It's a command-line tool I've been building, designed to bring AI-powered code analysis directly into your local Git environment, helping you refine your work, understand your changes better, and ultimately, push with greater confidence.
What is a Pull Request Anyway And Why Should I Care Locally
If you're navigating the world of software development, especially in a team, you'll constantly encounter "Pull Requests" (PRs) or "Merge Requests" (MRs) on platforms like GitHub or GitLab. So, what are they?
At its core, a Pull Request is a formal proposal to merge the code changes you've made on your own branch (your "feature branch" or "bugfix branch") into another, usually more central, branch (like main, develop, or master). It’s not just a technical action; it's a critical point for communication and collaboration. When you open a PR, you're essentially saying, "Here’s the work I’ve done to implement X or fix Y. I believe it's ready. Can the team please review it, discuss it, and if all looks good, approve it to be integrated into the main codebase?" This typically kicks off:
- Code Review: Teammates examine your code for correctness, style, potential issues, and adherence to project standards.
- Discussion: Questions are asked, clarifications are made, and suggestions are offered.
- Automated Checks: Continuous Integration (CI) pipelines run tests, linters, and other automated quality gates.
This process is invaluable for maintaining code quality and ensuring shared understanding in a team.
Now, you might be thinking, "That sounds great for team projects, but why should I care about all this locally, on my own machine, especially if I'm working solo or just learning?"
The answer is simple: early feedback, continuous improvement, and building better habits. Applying PR-like scrutiny to your own work before it's shared offers tremendous advantages:
- Catch Mistakes When They're Easiest to Fix: It's far simpler to correct a small logical error, a typo, or a confusing variable name when the code is fresh in your mind, rather than days or weeks later during a formal review.
- Learn and Improve in a Private Space: Get insights on your code's quality or areas for improvement without the pressure of public critique. It’s a safe environment to understand what "good code" looks like.
- Build Confidence: Submitting an eventual remote PR becomes less daunting if you've already had a "first pass" automated review and refined your changes.
- Develop Stronger Habits: Regularly describing your changes, thinking about their impact, and considering potential issues locally instills practices that make you a more effective developer and collaborator, even on solo projects. It helps you internalize the AI-First philosophy of iterative refinement.
This is precisely where Local PR Buddy steps in. It's designed to be your personal, AI-powered assistant for these local pre-flight checks.
Introducing Local PR Buddy The What
Local PR Buddy is a Python-based CLI tool that uses Large Language Models (LLMs) to analyze your Git changes directly from your local repository. It doesn't require your code to be on a remote server for its core analysis. It can look at:
- Branch Diffs: The changes on your current feature branch compared to a target branch (e.g., main), smartly using the merge-base for an accurate comparison.
- Staged Changes: The modifications you've selected with git add and are about to commit.
It offers several commands to help you:
- /describe: Struggling to articulate what you've just built? This command provides an AI-generated title for your set of changes, a suggested "type" (like "Feature," "Bug fix," "Refactor"), and a concise bullet-point summary. It’s incredibly helpful for drafting good commit messages or the initial description for a pull request.
- /review: Want a quick, high-level opinion on your work? This command gives you an AI-driven review, often highlighting potential areas for improvement, security considerations, and even a rough estimate of the review effort. It's like getting an initial, automated code critique.
- /improve: This is where the AI gets more specific. It analyzes your code (focusing on new additions) and offers concrete suggestions for improvement, often showing your existing code snippet alongside the proposed enhanced version and an explanation of the benefits. This is a fantastic way to learn new patterns or catch subtle issues.
- /ask {your question}": Have a question about the code you just wrote or refactored? "Is this new error handling robust enough?" or "Can you explain the logic in this modified function?" Ask away, and the AI will try to answer based on the provided diff.
Think of it as an AI peer who’s always available for a quick, private look over your shoulder, helping you polish your code before you share it.
Why This Matters The Benefits Across the Developer Spectrum
The motivation behind Local PR Buddy is to address common pain points and enhance the development experience for everyone, from seasoned coders to those just starting out.
For Experienced Developers:
Even if you're confident in your skills, an extra layer of automated review can be surprisingly beneficial:
- The "Second Pair of Eyes": We all have blind spots. A quick local review can catch typos, overlooked edge cases, or moments where clarity could be improved.
- Pre-Review Polish: Submitting a PR that's already had some automated scrutiny can make the human review process smoother and faster for your team.
- Documentation Head Start: The output from /describe can be a great starting point for writing comprehensive PR descriptions.
For Newer Developers (And Those Navigating the Git Maze):
The world of Git, branches, and formal code reviews can feel overwhelming. Local PR Buddy aims to be a supportive learning companion:
- Code Review Rehearsal: Using /review and /improve locally gives you a private, low-pressure way to see what kind of feedback you might get.
- Actionable Learning: The /improve suggestions show you how your code could be better, accelerating your learning. This aligns with the idea of leveling up your vibe coding.
- Articulating Your Work: The /describe command helps you practice summarizing your changes.
- Confidence Boost: Making improvements based on local AI feedback can significantly increase your confidence.
For All Developers:
- True "Shift Left": Local PR Buddy brings quality checks to the very beginning of your workflow.
- Focus on What Matters: Iterate faster and spend less time on minor issues during formal reviews.
- Privacy and Control: Your code diffs are processed locally and sent only to your configured LLM API (perhaps even a local one via Ollama).
A Quick Look Under the Hood The Tech Behind the Buddy
Local PR Buddy is built with Python, leveraging several key libraries and concepts:
- Git Interaction: Uses GitPython for sophisticated Git operations (like merge-bases) and direct git diff --staged parsing for staged changes. It ensures full content of newly added files is sent to the AI.
- AI Integration: Employs LiteLLM for flexible connections to various LLM providers (OpenAI, Anthropic, Google, local models via Ollama, etc.), similar to the flexibility offered by OpenRouter. API keys are managed via a local .env file.
- Prompt Engineering: Carefully crafted prompts in .toml files (using Jinja2 templating) guide the AI for each tool, drawing on principles similar to those for code2prompt and Context7.
- Structured Output: Prompts instruct the AI to return YAML, which the Python tools parse.
- Modular Design: Organized into core, providers, tools, and prompts directories, a key part of my AI development power stack.
- User Interface: A CLI with styled output via colorama, plus .vscode/tasks.json for VS Code integration.
Thinking Bigger Unexpected Wins and Future Ideas
While the primary goal is pre-PR feedback, Local PR Buddy can spark other ideas:
- Commit Message Co-Pilot: Use /describe outputs as a starting point for well-formatted conventional commit messages.
- Automated Pre-Commit Checks: Imagine a Git hook running a quick /improve --staged, taking local automation further, akin to advanced n8n automations.
- Onboarding and Training: A gentle intro for new team members to coding standards and review expectations.
The Road Ahead Next Steps for Your Local Buddy
The core Python CLI with its four main tools is now functional. The immediate future is about deeper VS Code integration.
- VS Code Extension: We've started building this to trigger commands from the Command Palette and show results in VS Code's Output Channel.
- Webviews for Richer UI: The plan is for Python tools to output structured JSON, enabling the extension to render results in interactive HTML Webview panels. This mirrors UI approaches in my Desktop AI Assistant and PlantDex projects.
- Future Polish (Phase 4): Ideas include SARIF output for the "Problems" panel and interactive application of suggestions.
Join the Local Feedback Revolution
Local PR Buddy aims to make development smoother and more insightful by leveraging AI early and locally. It's about fostering good habits and improving code quality with less stress. The journey of building this tool with AI itself has been a testament to a new era in software development.
As this project evolves (look for it on my GitHub soon!), I’d love your feedback. For more on AI in development, visit workflows.diy.
Local PR Buddy Q&A Your Questions Answered
-
Q: What's the main benefit of a "local" PR
tool?
A: Privacy (your code isn't sent to a third-party review service before you're ready), speed (instant feedback without waiting for CI/human reviewers), and the ability to iterate and fix issues privately before creating a formal Pull Request. -
Q: I'm new to Git. How can Local PR Buddy help
me?
A: It's a great learning tool! Commands like /describe help you summarize your work (good for commit messages). /review and /improve give you a gentle, private introduction to the kinds of feedback you might get in a real code review, helping you understand what to look out for. -
Q: Does this replace human code reviewers or tools
like GitHub Copilot?
A: Absolutely not! It complements them. Local PR Buddy is for pre-flight checks by the developer. Human reviewers provide essential context and architectural oversight. Tools like Copilot assist with writing code line-by-line; Local PR Buddy analyzes a *set of changes* (a diff). -
Q: How does it actually "see" my code
changes?
A: It uses your local Git repository. For branch comparisons, it intelligently finds the common ancestor (merge-base) to get an accurate diff. For staged changes, it processes the output of git diff --staged. The relevant diff text is then sent to an AI. -
Q: What AI models can I use with it?
A: It's built with LiteLLM, which supports a wide range of models (OpenAI's GPT series, Anthropic's Claude, Google's Gemini, and many open-source models runnable locally with Ollama). You configure your preferred model and API key. -
Q: Is it complicated to set up the prompts for the
AI?
A: The tool comes with pre-defined, optimized prompts for each command (/describe, /review, etc.) stored in .toml files. Advanced users could potentially customize these, but it works out-of-the-box. -
Q: How does the /improve command work? Does it
change my code?
A: The /improve command sends your code diff to the AI and asks for specific suggestions. It will show you your existing code and the AI's proposed improved version, along with an explanation. It does not automatically change your code; you decide if and how to apply the suggestions. -
Q: Will this slow down my local development
process?
A: The goal is the opposite! While an AI call takes a few seconds, catching issues locally that would have caused lengthy back-and-forth in a PR review, or even a broken build, saves significant time in the long run. -
Q: What's the "Shift Left" concept you
mentioned?
A: "Shift Left" means moving quality assurance activities (like testing and reviews) to earlier stages in the development pipeline. Local PR Buddy helps you "shift left" by enabling AI-assisted review of your code on your local machine before you even commit or push. -
Q: How will the VS Code extension make this better
than just a CLI tool?
A: The extension will integrate these commands directly into the VS Code UI (e.g., via the Command Palette or context menus). Future versions aim to display results in rich Webview panels, making the feedback more interactive and visually appealing than raw terminal output.