LeanKG

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.
Live Demo
Try LeanKG without installing: https://leankg.onrender.com
leankg web --port 9000
Installation
One-Line Install (Recommended)
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
Install via Cargo or Build from Source
cargo install leankg && leankg --version
git clone https://github.com/FreePeak/LeanKG.git && cd LeanKG && cargo build --release
Quick Start
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.
Claude Code Setup
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