by FreePeak
LeanKG: Stop Burning Tokens. Start Coding Lean.
# Add to your Claude Code skills
git clone https://github.com/FreePeak/LeanKGGuides for using mcp servers skills like LeanKG.
Last scanned: 5/30/2026
{
"issues": [],
"status": "PASSED",
"scannedAt": "2026-05-30T15:43:50.096Z",
"npmAuditRan": true,
"pipAuditRan": true
}No comments yet. Be the first to share your thoughts!
Top skills in this category by stars
30 days in the Featured rail · terms & refunds
Lightweight Knowledge Graph for AI-Assisted Development
LeanKG is a local-first knowledge graph that gives AI coding tools accurate codebase context. It indexes your code, builds dependency graphs, and exposes an MCP server so tools like Cursor, OpenCode, and Claude Code can query the knowledge graph directly. No cloud services, no external databases.
Visualize your knowledge graph with force-directed layout, WebGL rendering, and community clustering.

See docs/web-ui.md for more features.
Try LeanKG without installing: https://leankg.onrender.com
leankg web --port 9000
curl -fsSL https://raw.githubusercontent.com/FreePeak/LeanKG/main/scripts/install.sh | bash -s -- <target>
Supported targets:
| Target | AI Tool | Auto-Installed |
|---|---|---|
opencode |
OpenCode AI | Binary + MCP + Plugin + Skill + AGENTS.md |
cursor |
Cursor AI | Binary + MCP + Skill + AGENTS.md + Session Hook |
claude |
Claude Code | Binary + MCP + Plugin + Skill + CLAUDE.md + Session Hook |
gemini |
Gemini CLI | Binary + MCP + Skill + GEMINI.md |
kilo |
Kilo Code | Binary + MCP + Skill + AGENTS.md |
antigravity |
Google Antigravity | Binary + MCP + Skill + GEMINI.md |
Examples:
curl -fsSL https://raw.githubusercontent.com/FreePeak/LeanKG/main/scripts/install.sh | bash -s -- cursor
curl -fsSL https://raw.githubusercontent.com/FreePeak/LeanKG/main/scripts/install.sh | bash -s -- claude
cargo install leankg && leankg --version
git clone https://github.com/FreePeak/LeanKG.git && cd LeanKG && cargo build --release
docker compose -f docker-compose.rocksdb.yml up
This starts the LeanKG MCP HTTP server on port 9699 with auto-indexing enabled. Requires Docker or OrbStack.
leankg init # Initialize LeanKG in your project
leankg index ./src # Index your codebase
leankg watch ./src # Auto-index on file changes
leankg impact src/main.rs --depth 3 # Calculate blast radius
leankg status # Check index status
leankg metrics # View token savings
leankg web # Start Web UI at http://localhost:8080
leankg export --format mermaid # Export graph as Mermaid, DOT, or JSON
leankg quality --min-lines 50 # Find oversized functions
leankg detect-clusters # Identify functional code communities
leankg trace --all # Show feature-to-code traceability
leankg annotate src/main.rs::main -d "Entry point" # Annotate code elements
# Run shell commands with RTK compression
leankg run -- cargo test -- --compress
# REST API server with auth
leankg api-serve --port 8081 --auth
leankg api-key create --name my-key
# Process management
leankg proc status # Show running LeanKG/Vite processes
leankg proc kill # Kill all LeanKG/Vite processes
# Obsidian vault sync
leankg obsidian init # Initialize Obsidian vault structure
leankg obsidian push # Push LeanKG data to Obsidian notes
leankg obsidian pull # Pull annotation edits from Obsidian
leankg obsidian watch # Watch vault for changes and auto-pull
leankg obsidian status # Show vault status
# Microservice call graph (via Web UI)
leankg web # Start Web UI at http://localhost:8080
# Then visit http://localhost:8080/services
# Multi-repo registry
leankg register my-project # Register a repository
leankg list # List all registered repos
leankg setup # Configure MCP for all repos + install Claude hooks
See docs/cli-reference.md for all commands.
LeanKG auto-triggers in Claude Code sessions via lifecycle hooks that route search intents to LeanKG tools instead of native tools.
# Install LeanKG with Claude Code hooks and plugin
leankg setup
# Then restart Claude Code or run:
/reload-plugins
What leankg setup installs:
.claude-plugin/ - Plugin manifest for Claude Code validationhooks/ - Full lifecycle hooks: Setup, SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, Stopleankg@local to enabledPlugins in ~/.claude/settings.jsonHook lifecycle:
Setup - Version gating on startupSessionStart - Injects tool selection hierarchy into every sessionUserPromptSubmit - Initializes session context with LeanKG patternsPreToolUse - Nudges toward LeanKG when you use Grep/Read/Bash for code analysisPostToolUse - Logs LeanKG MCP tool usage for analyticsStop - Captures session summary for future context retrievalgraph LR
subgraph "Without LeanKG"
A1[AI Tool] -->|Full codebase context| B1[15,000-45,000 tokens]
B1 --> A1
end
subgraph "With LeanKG"
A2[AI Tool] -->|Targeted subgraph| C[LeanKG Graph]
C -->|Context reduction| A2
end
Without LeanKG: AI processes full context from files found via grep/search. With LeanKG: AI queries knowledge graph for targeted context. Token reduction varies by task complexity (see benchmark results).
detect_changes classifies risk as critical/high/medium/lowIMPORTS, CALLS, TESTED_BY edges@Entity, @HiltViewModel, and other annotationsSee docs/architecture.md for system design and data model details.
| Tool | Auto-Setup | Session Hook | Plugin | Full Lifecycle Hooks |
|---|---|---|---|---|
| Cursor | Yes | session-start | - | - |
| Claude Code | Yes | session-start | Yes | Setup, SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, Stop |
| OpenCode | Yes | - | Yes | - |
| Docker | Yes | - | - | - |
| Kilo Code | Yes | - | - | - |
| Gemini CLI | Yes | - | - | - |
| Google Antigravity | Yes | - | - | - |
| Codex | Yes | - | - | - |
Note: Cursor requires per-project installation. The AI features work on a per-workspace basis, so LeanKG should be installed in each project directory where you want AI context injection.
See docs/agentic-instructions.md for detailed setup and auto-trigger behavior.
Track token savings to understand LeanKG's efficiency.
leankg metrics --json # View with JSON output
leankg metrics --since 7d # Filter by time
leankg metrics --tool search_code # Filter by tool
See docs/metrics.md for schema and examples.
# Check current version
leankg version
# Update LeanKG binary (kills processes, removes old binary, installs hooks)
leankg update
# Or via install script
curl -fsSL https://raw.githubusercontent.com/FreePeak/LeanKG/main/scripts/install.sh | bash -s -- update
# Obsidian vault sync
leankg obsidian init # Initialize Obsidian vault
leankg obsidian push # Push LeanKG data to Obsidian notes
leankg obsidian pull # Pull annotation edits from Obsidian
| Doc | Description |
|---|---|
| docs/cli-reference.md | All CLI commands |
| docs/mcp-tools.md | MCP tools reference |
| docs/agentic-instructions.md | AI tool setup & auto-trigger |
| docs/architecture.md | System d |