Interactive git diff learning tool with LLM-powered explanations
DiffLearn helps developers understand code changes through an interactive terminal UI with AI-powered explanations. Navigate diffs with keyboard controls, click on changes to ask questions, and get instant AI insights.
- π¨ Interactive Diff Viewer - Red/green syntax highlighting with keyboard navigation
- π¬ Click-to-Ask - Select any change and ask questions about it
- π Unified Dashboard - View local, staged, and history on one screen in the terminal
- π Commit Comparison - Select any two commits in Web or CLI to see and analyze the diff between them
- π Remote Web UI - Beautiful local web interface with comparison support and AI chat
- π Use Your Subscriptions - Works with Gemini CLI, Claude Code, Cursor (no API fees!)
- π€ API Support - Native support for OpenAI, Anthropic, and Google AI APIs
- π MCP Server - Full integration with Cursor, Claude Code, and other MCP clients
- β¨οΈ Keyboard First - Full scrolling and windowing support for large diffs and histories
curl -fsSL https://raw.githubusercontent.com/lertsoft/DiffLearn/master/install.sh | bash# Clone and install
git clone https://github.com/lertsoft/DiffLearn.git
cd DiffLearn
bun install
# Run directly
bun run dev
# Or install globally
bun link# Clone and install
git clone https://github.com/lertsoft/DiffLearn.git
cd DiffLearn
bun run dev
# Launch web UI
bun run web
# Run tests
bun test# π Launch the Web UI (recommended!)
difflearn web
# Terminal: View local changes interactively
difflearn local
# View staged changes only
difflearn local --staged
# Compare commits
difflearn commit abc123
difflearn commit abc123 --compare def456
# Compare branches
difflearn branch main feature/new-auth
# Quick AI explanations (non-interactive)
difflearn explain
difflearn review
difflearn summary
# Interactive Compare
difflearn local # Use Tab to switch to History, then Enter to select
difflearn web # Click '+' buttons next to commits to compare two SHAsThe Web Interface (difflearn web) is fully accessible and keyboard-friendly:
| Key | Action |
|---|---|
s/j/β |
Select next commit in list |
w/k/β |
Select previous commit in list |
Enter |
Select currently focused commit / Confirm comparison |
a/β |
Switch to previous view (e.g. History β Staged) |
d/β |
Switch to next view (e.g. Local β Staged) |
/ |
Focus Chat Input |
Esc |
Close panels / Exit comparison mode |
+ (Web) |
Click the '+' button next to commits to select for comparison (max 2) |
| Key | Action |
|---|---|
Tab |
Switch between Local Changes, Staged Changes, and History |
β/β |
Navigate history list or scroll long AI responses |
Enter |
View diff for selected commit or file |
/ / i |
Focus AI Chat input |
Esc |
Exit chat/scrolling mode back to dashboard |
q |
Quit or go back from current view |
c (Chat) |
Clear current chat history |
| Command | Description |
|---|---|
/explain |
Get AI explanation of current changes |
/review |
Get AI code review with suggestions |
/summarize |
Get a quick summary of changes |
/update |
Check for updates |
/export |
Export diff as markdown |
/web |
Open web UI in browser |
/config |
Show LLM configuration status |
The easiest way to configure DiffLearn is with the interactive wizard:
difflearn configThis will:
- Show available providers (CLI-based and API-based)
- Guide you through authentication
- Save configuration securely to
~/.difflearn
Use your existing AI subscriptions without extra API costs:
| Provider | Requirement |
|---|---|
| Gemini CLI | Install gemini-cli |
| Claude Code | Install claude |
| OpenAI Codex | Install codex |
| Cursor | Cursor IDE installed |
# Check which providers are available
difflearn config --status
# Example: Use Gemini CLI
export DIFFLEARN_LLM_PROVIDER=gemini-cliRun AI locally on your machine with no API costs and full privacy:
| Provider | Default URL | Setup |
|---|---|---|
| Ollama | localhost:11434 |
Install Ollama + ollama pull llama3.2 |
| LM Studio | localhost:1234 |
Install LM Studio + start local server |
The easiest way to configure is with the wizard, which detects your downloaded models:
difflearn config
# Select Ollama or LM Studio, then choose from your available modelsOr set environment variables directly:
# Use Ollama
export DIFFLEARN_LLM_PROVIDER=ollama
export DIFFLEARN_MODEL=llama3.2
# Use LM Studio
export DIFFLEARN_LLM_PROVIDER=lmstudio
# Custom base URL (if not using default port)
export DIFFLEARN_BASE_URL=http://localhost:8080/v1For direct API access (pay-per-use):
# Option 1: OpenAI (default)
export OPENAI_API_KEY=sk-...
# Option 2: Anthropic
export ANTHROPIC_API_KEY=sk-ant-...
export DIFFLEARN_LLM_PROVIDER=anthropic
# Option 3: Google AI
export GOOGLE_AI_API_KEY=...
export DIFFLEARN_LLM_PROVIDER=google
# Optional: Custom model
export DIFFLEARN_MODEL=gpt-4o-miniDiffLearn stores config in ~/.difflearn:
# ~/.difflearn
DIFFLEARN_LLM_PROVIDER=gemini-cli
OPENAI_API_KEY=sk-...Environment variables override the config file.
Note: DiffLearn works without an API key! When no LLM is configured, it outputs formatted prompts you can use with any AI tool.
Add to your MCP configuration:
{
"mcpServers": {
"difflearn": {
"command": "bun",
"args": ["run", "/path/to/DiffLearn/src/mcp/server.ts"]
}
}
}get_local_diff- Get uncommitted changesget_commit_diff- Get diff for a commitget_branch_diff- Compare branchesget_commit_history- List recent commitsexplain_diff- AI explanation of changesreview_diff- AI code reviewask_about_diff- Ask questions about changes
# Start API server
difflearn serve --api --port 3000
# Endpoints
GET /diff/local # Local changes
GET /diff/commit/:sha # Single commit or comparison (using ?compare=sha2)
GET /diff/branch/:b1/:b2 # Branch diff
GET /history # Commit history with windowing support
POST /explain # AI explanation (supports commit/staged/compare)
POST /review # AI code review (supports commit/staged/compare)
POST /ask # Ask questions (supports commit/staged/compare)
POST /summary # Quick summary (supports commit/staged/compare)| Command | Description |
|---|---|
local [--staged] |
View local changes interactively |
commit <sha> [--compare <sha2>] |
View commit diff |
branch <b1> <b2> |
Compare branches |
explain [--staged] |
AI explanation |
review [--staged] |
AI code review |
summary [--staged] |
Quick summary |
export [--format json|markdown] |
Export diff |
history [-n count] |
List commits |
web [-p port] |
Launch the web UI |
config [--status] |
Configure LLM provider |
serve --mcp|--api |
Start server |
src/
βββ cli/
β βββ index.tsx # CLI entry point
β βββ components/
β βββ App.tsx # Main app component
β βββ DiffViewer.tsx # Interactive diff viewer
β βββ ChatPanel.tsx # Q&A chat panel
βββ git/
β βββ extractor.ts # Git operations
β βββ parser.ts # Diff parsing
β βββ formatter.ts # Output formatting
βββ llm/
β βββ client.ts # LLM providers
β βββ prompts.ts # Prompt templates
βββ mcp/
β βββ server.ts # MCP server
βββ api/
βββ server.ts # REST API
MIT
