Local Usage
All three commands work locally without a GitHub repository. You only need an API key for your chosen provider.
Installation options
No install needed — run directly with npx:
npx @giolabsuy/ai-code-reviewer review-file src/users/users.service.tsGlobal install — for frequent use from anywhere:
npm install -g @giolabsuy/ai-code-reviewer
ai-code-reviewer review-diff --stagedProject devDependency — for pre-commit hooks or team consistency:
npm install --save-dev @giolabsuy/ai-code-reviewerThen reference it in scripts or hooks as npx ai-code-reviewer <command>.
Setup
Create a .env file at the root of the project you want to review:
# OpenAI (default)
OPENAI_API_KEY=sk-...
# Anthropic
# ANTHROPIC_API_KEY=sk-ant-...
# Gemini
# GEMINI_API_KEY=AI...dotenv is loaded automatically. For Ollama, no key is needed — just have the service running at http://localhost:11434.
Review a single file
npx @giolabsuy/ai-code-reviewer review-file src/users/users.service.tsUseful when iterating on your rules: make a change to code-review-rules.md, re-run review-file, see if the finding appears or disappears.
Review staged changes
npx @giolabsuy/ai-code-reviewer review-diff --stagedReviews the output of git diff --cached. Run this before committing to catch issues early.
Review against a base branch
npx @giolabsuy/ai-code-reviewer review-diff --base mainEquivalent to git diff main...HEAD. Useful for a full review of a feature branch before opening a PR.
Pre-commit hook
Wire review-diff --staged as a pre-commit hook to get inline feedback before every commit.
With Husky
npm install --save-dev husky
npx husky initThen edit .husky/pre-commit:
#!/bin/sh
npx @giolabsuy/ai-code-reviewer review-diff --staged --min-severity majorThis runs the reviewer on staged changes and exits 1 if there are major or critical findings, blocking the commit.
Without Husky (raw git hook)
Create .git/hooks/pre-commit and make it executable:
#!/bin/sh
npx @giolabsuy/ai-code-reviewer review-diff --staged --min-severity majorchmod +x .git/hooks/pre-commitUse --min-severity major in pre-commit hooks to avoid blocking commits on minor/nitpick findings. Save those for the full PR review.
Save a Markdown report
Any command accepts --save <path> to write a full Markdown report:
npx @giolabsuy/ai-code-reviewer review-diff --base main --save review-report.md