An automated GitHub Pull Request code reviewer powered by Gemini and local AST dependency analysis.
Code-Sage is designed to run natively in your CI/CD pipeline, automatically posting precise, inline code reviews and engineering suggestions directly onto your Pull Request diffs.
Unlike conventional AI code reviewers that analyze files in isolation, Code-Sage builds an Abstract Syntax Tree (AST) call-graph of your project to trace the downstream "blast radius" of signature changes. This ensures that if you change an export signature, Code-Sage locates and reviews unmodified files that call it—catching integration bugs before they merge.
- Inline Line-Level Reviews: Publishes reviews directly onto the specific files and lines modified or affected.
- Intelligent Diff Matching: Leverages
@octokit/restto map comments directly to PR diff coordinate regions. - Unified Review Fallbacks: Automatically falls back to posting a structured, high-level summary review if coordinate drifts occur.
- Module Dependency Mapping: Extracts function declarations, class structures, imports, and caller-site nodes locally.
- Contextual Prompting: Feeds Gemini only the changed diff and the 10-line context surrounding unmodified calling locations.
- Token Efficiency: Prevents context window overload by bypassing bloated, repository-wide file loading.
To enable automated reviews on every Pull Request:
- Navigate to your GitHub repository Settings ➔ Secrets and variables ➔ Actions.
- Click New repository secret.
- Create a secret named
GEMINI_API_KEYand paste your API key (get one from Google AI Studio).
In the root directory of your project, run:
npx code-sage-cli --initThis automatically creates .github/workflows/code-review.yml with the correct permissions and runner commands:
name: Code-Sage Reviewer
on:
pull_request:
types: [opened, synchronize]
jobs:
review:
runs-on: ubuntu-latest
permissions:
pull-requests: write # Required to post inline reviews
contents: read # Required to checkout code
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Required to calculate git diffs between commits
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20
- name: Run Code-Sage
run: npx code-sage-cli --staged
env:
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Provided automatically by GitHub ActionsCommit and push the generated workflow file:
git add .github/workflows/code-review.yml
git commit -m "ci: integrate code-sage-cli PR review workflow"
git push origin mainYou can also run Code-Sage locally to review uncommitted code changes before staging or committing:
- macOS/Linux:
export GEMINI_API_KEY="your_api_key_here" - Windows (PowerShell):
$env:GEMINI_API_KEY="your_api_key_here"
# Review all local modifications (staged + unstaged)
npx code-sage-cli
# Review staged changes only
npx code-sage-cli --staged
# Review unstaged changes only
npx code-sage-cli --unstagedIf you want to customize the review prompts, heuristics, or extend AST parsing support:
- Clone the repository and install dependencies:
npm install
- Compile the TypeScript compiler output:
npm run build
- Link the package locally:
npm link
- Run locally from source:
code-sage-cli
MIT License.