I Built a GitHub Bot That Reviews My Pull Requests Using a Local LLM Creation of a GitHub bot that uses a local large language model (LLM) via Ollama to automatically review pull requests. When a PR is opened, the bot receives a webhook, retrieves the code diff using GitHub's REST API, sends it to the locally running LLM for analysis, and posts the review as a comment. The author explains the technical setup, including configuring a GitHub App, handling authentication with short-lived installation tokens, and splitting large diffs into smaller chunks to fit within the LLM's context window. Last month I pushed a bug to production which I would have caught if I had somebody look at my code. Well, it's not like I was the only one working on the project, so I had to read it myself and then forget about it, only to spend an annoying Tuesday trying to figure out why it didn't ship. I was thinking about Ollama. I had heard about it a couple of times but never really needed to use it for anything. So this weekend I built a GitHub bot that reviews pull requests with a local LLM, without sending any code out of the box. It makes a comment on the PR with what it finds. Here's how I built it. What the bot actually does When you open a pull request, GitHub fires a webhook. The bot receives it, pulls the diff for each changed file using GitHub's REST API, sends that diff to a locally running LLM via Ollama, and posts the review back as a comment on the PR. The output looks like this on your PR: Project Structure: self-hosted-ai-code-review-bot-for-github-prs/ ├── src/ │ ├── server.js │ ├── github.js │ ├── ollama.js │ ├── diffParser.js │ └── chunker.js ├── private-key.pem ├── .env ├── package-lock.json └── package.json Setting up the GitHub App first Before any code, you need a GitHub App. A GitHub App has its own identity, which gets installed on specific repos, and uses short-lived installation tokens instead of long-lived credentials. Go to GitHub → Settings → Developer Settings → GitHub Apps → New GitHub App. Permissions you need: - Pull requests: Read & write - Issues: Read & write - Metadata: Read-only Under webhook events, subscribe to Pull request. Set the webhook URL to your ngrok address + /webhook we'll come back to that . Generate and download the private key .pem file . GitHub uses this to sign the installation tokens. Clone the repo and install dependencies: git clone