Build an Autonomous GitHub PR Review Agent with Gemini CLI
Create a self‑running agent that analyses pull requests, generates detailed code reviews, and opens review comments on GitHub automatically.
The Workflow
9 steps · click a step number to mark it done
Open Gemini CLI and have it ready before you start
Install Gemini CLI by running `npx @google/gemini-cli@latest` in your terminal
Create a `gemini.md` guardrail file in your home directory (e.g., `~/.mini/gemini.md`) that defines the agent’s role as an expert code reviewer
Set environment variables `GITHUB_TOKEN` and `OPENAI_API_KEY` with your personal access token and API key
Run `gemini init` and follow the prompts to link the agent to your target GitHub repository and branch
Enter a detailed prompt asking Gemini to generate a PR review agent that: • scans changed files • flags bugs, security issues, and style violations • writes a markdown summary • creates a new branch, commits the summary, and opens a pull request
Approve the autogenerated plan when Gemini displays it, then let the CLI execute the plan
After the run finishes, open the created pull request on GitHub and verify that the review comments and summary file were added
Securely grant the agent GitHub access via Ozero OAuth flow
Run the agent again; Ozero will open a consent screen, you approve, and the agent receives a short‑lived token to comment on future PRs without storing secrets