PR Context Lens is a fully-scaffolded Chrome Extension that:
- Detects GitHub PR pages
- Parses unified diffs into structured format
- Sends diffs to AI providers (OpenAI GPT-4o or Anthropic Claude)
- Displays analysis results in a sidebar panel
- ✅ Full TypeScript project with strict type checking
- ✅ React 18 UI with Tailwind CSS
- ✅ Chrome Extension Manifest V3 configuration
- ✅ Modular architecture with clear separation of concerns
- ✅ Comprehensive test suite (21 passing tests)
- ✅ All core modules implemented and tested
- ✅ Build system configured (Vite + TypeScript)
# Dependencies are already installed, but if needed:
npm install# Watch mode for development
npm run dev# Compile TypeScript and build extension
npm run build# Run all unit tests
npm run test
# Watch mode for tests
npm run test -- --watch
# UI mode for tests
npm run test:ui- Run
npm run buildto create thedist/folder - Open
chrome://extensions/ - Toggle "Developer mode" (top right)
- Click "Load unpacked"
- Select the
dist/folder - Visit a GitHub PR page and look for the "📊 PR Analysis" button!
src/
├── shared/ # Types and utilities
│ ├── types.ts # Core TypeScript interfaces
│ └── cache.ts # Diff caching with chrome.storage
│
├── analyzer/ # Diff parsing and prompt building
│ ├── diff-parser.ts # Parse unified diff format
│ └── prompt-builder.ts # Build AI analysis prompts
│
├── providers/ # AI provider integrations
│ ├── openai.ts # OpenAI API client
│ ├── anthropic.ts # Anthropic API client
│ └── index.ts # Provider factory & routing
│
├── background/ # Service worker
│ └── service-worker.ts # Message handling hub
│
├── content/ # Content script
│ └── github-detector.ts # Detect PRs, inject UI
│
└── panel/ # React UI components
├── App.tsx # Main panel component
├── components/ # Reusable UI components
└── index.tsx # Panel entry point
Before using the extension, you need to set API keys:
- Click the extension icon on a GitHub PR page
- Click the ⚙️ settings icon
- Enter your OpenAI or Anthropic API key
- Select your preferred provider
- Click "Save Configuration"
- OpenAI: https://platform.openai.com/api-keys (paid account required)
- Anthropic: https://console.anthropic.com/account/keys (paid account required)
- Content Script detects GitHub PR pages
- Service Worker fetches diffs from GitHub API
- Diff Parser converts raw diff to structured format
- Prompt Builder creates AI analysis prompts
- AI Provider (OpenAI or Anthropic) analyzes the prompt
- React Panel displays results with formatting
GitHub PR Page
↓
Content Script (github-detector.ts)
↓ Injects button, fetches diff
Service Worker (service-worker.ts)
↓ Caches & routes messages
Diff Parser (diff-parser.ts)
↓ Parses unified diff
Prompt Builder (prompt-builder.ts)
↓ Builds AI prompt
AI Provider (openai.ts or anthropic.ts)
↓ Analyzes PR
React Panel (App.tsx)
↓ Displays results
All code follows these standards:
- ✅ TypeScript strict mode
- ✅ Functional components only
- ✅ JSDoc comments on public functions
- ✅ Comprehensive unit tests
- ✅ Type-only imports where appropriate
- ✅ No external UI libraries beyond Tailwind
- ✅ Async/await (no .then() chains)
Current test suites:
- diff-parser.test.ts - Unified diff parsing (3 tests)
- prompt-builder.test.ts - Prompt construction (4 tests)
- openai.test.ts - OpenAI API integration (4 tests)
- anthropic.test.ts - Anthropic API integration (4 tests)
- github-detector.test.ts - Content script utilities (3 tests)
- service-worker.test.ts - Service worker basics (1 test)
Total: 21 passing tests ✅
- Code Review Comments - Generate comments for specific lines
- Performance Analysis - Detect performance regressions
- Security Scanning - Flag security vulnerabilities
- Dependency Updates - Check for vulnerable dependencies
- Author Context - Learn from previous PRs by the author
- Add more comprehensive error handling
- Implement progress tracking for large diffs
- Add keyboard shortcuts
- Support PR comments and discussions
- Add dark/light theme toggle
- Persistent analysis history
- Open
chrome://extensions/ - Find "PR Context Lens"
- Click "Inspect views → service worker" to debug background script
- Open DevTools on any GitHub page to debug content script
// In Chrome DevTools console on any page:
chrome.storage.local.get(['openai_api_key', 'anthropic_api_key'], console.log);// In Chrome DevTools console:
chrome.storage.local.remove('pr_context_lens_cache');"API key not configured"
- Make sure to set your API key in the extension settings (⚙️ icon)
"Failed to fetch diff"
- Check if you're on a valid GitHub PR page (github.com/user/repo/pull/number)
- Private repos may require authentication token
"Analysis failed"
- Check your API key is valid and has credits
- Try a smaller PR first
- Check browser console for error details
- Diff Caching: Diffs are cached for 1 hour to avoid redundant API calls
- Bundle Size: ~60.76 KB gzipped (React + Tailwind included)
- API Costs: Each PR analysis uses ~100-200 tokens depending on diff size
- Frontend: React 18 + Tailwind CSS
- Bundler: Vite (modern, fast builds)
- Language: TypeScript 5 (strict mode)
- Testing: Vitest (fast, Vite-native)
- APIs: OpenAI + Anthropic
- Extension API: Chrome Manifest V3
Happy reviewing! 🚀
For more detailed information, see README.md