Lean KG

LeanKG: Stop Burning Tokens. Start Coding Lean.

LeanKG

LeanKG

License: MIT Rust crates.io

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.

LeanKG Graph Visualization LeanKG Obsidian

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:

TargetAI ToolAuto-Installed
opencodeOpenCode AIBinary + MCP + Plugin + Skill + AGENTS.md
cursorCursor AIBinary + MCP + Skill + AGENTS.md + Session Hook
claudeClaude CodeBinary + MCP + Plugin + Skill + CLAUDE.md + Session Hook
geminiGemini CLIBinary + MCP + Skill + GEMINI.md
kiloKilo CodeBinary + MCP + Skill + AGENTS.md
antigravityGoogle AntigravityBinary + 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

# 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

See docs/cli-reference.md for all commands.


How LeanKG Helps

graph LR
    subgraph "Without LeanKG"
        A1[AI Tool] -->|Scans entire codebase| B1[10,000+ tokens]
        B1 --> A1
    end

    subgraph "With LeanKG"
        A2[AI Tool] -->|13-42 tokens| C[LeanKG Graph]
        C -->|Targeted subgraph| A2
    end

Without LeanKG: AI scans entire codebase (~10,000+ tokens). With LeanKG: AI queries knowledge graph for targeted context (13-42 tokens). 98% token saving for impact analysis.


Highlights

  • Auto-Init -- Install script configures MCP, rules, skills, and hooks automatically
  • Auto-Trigger -- Session hooks inject LeanKG context into every AI tool session
  • Token Concise -- 13-42 tokens per query vs 10,000+ for full codebase scan
  • Token Saving -- Up to 98% token reduction for impact analysis
  • Impact Radius -- Compute blast radius before making changes
  • Dependency Graph -- Build call graphs with IMPORTS, CALLS, TESTED_BY edges
  • MCP Server -- Expose graph via MCP protocol for AI tool integration
  • Multi-Language -- Index Go, TypeScript, Python, Rust, Java, Kotlin with tree-sitter

See docs/architecture.md for system design and data model details.


Supported AI Tools

ToolAuto-SetupSession HookPlugin
CursorYessession-start-
Claude CodeYessession-startYes
OpenCodeYes-Yes
Kilo CodeYes--
Gemini CLIYes--
Google AntigravityYes--
CodexYes--

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.


Context Metrics

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.


Update

# Check current version
leankg version

# Update LeanKG binary 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

Documentation

DocDescription
docs/cli-reference.mdAll CLI commands
docs/mcp-tools.mdMCP tools reference
docs/agentic-instructions.mdAI tool setup & auto-trigger
docs/architecture.mdSystem design, data model
docs/web-ui.mdWeb UI features
docs/metrics.mdMetrics schema & examples
docs/benchmark.mdPerformance benchmarks
docs/roadmap.mdFeature planning
docs/tech-stack.mdTech stack & structure

Requirements

  • Rust 1.70+
  • macOS or Linux

License

MIT


Star History

Star History Chart

Related Servers

NotebookLM Web Importer

Import web pages and YouTube videos to NotebookLM with one click. Trusted by 200,000+ users.

Install Chrome Extension