[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-1649":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":17,"stars7d":18,"stars30d":19,"stars90d":16,"forks30d":16,"starsTrendScore":18,"compositeScore":20,"rankGlobal":10,"rankLanguage":10,"license":21,"archived":22,"fork":22,"defaultBranch":23,"hasWiki":22,"hasPages":22,"topics":24,"createdAt":10,"pushedAt":10,"updatedAt":45,"readmeContent":46,"aiSummary":47,"trendingCount":16,"starSnapshotCount":16,"syncStatus":15,"lastSyncTime":48,"discoverSource":49},1649,"LeanKG","FreePeak\u002FLeanKG","FreePeak","LeanKG: Stop Burning Tokens. Start Coding Lean.","https:\u002F\u002Fwww.leankg.com",null,"Rust",196,19,183,2,0,1,3,9,48.3,"MIT License",false,"main",[25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44],"antigravity","claude-code","concise-context","cursor","gemini","graph-database","kilo-code","kn","knowledge-graph","knowlege-base","lean-code","lean-context","lean-token","llm","mcp","mcp-server","opencode","saving-token","second-brain","token","2026-06-12 04:00:10","\u003Cp align=\"center\">\n  \u003Cimg src=\"https:\u002F\u002Fwww.leankg.com\u002Ficon.svg\" alt=\"LeanKG\" width=\"80\" height=\"80\">\n\u003C\u002Fp>\n\n# LeanKG\n\n[![License: MIT](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FLicense-MIT-blue.svg)](https:\u002F\u002Fopensource.org\u002Flicenses\u002FMIT)\n[![Rust](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Frust-1.75%2B-orange?logo=rust&logoColor=white)](https:\u002F\u002Fwww.rust-lang.org\u002F)\n[![crates.io](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002Fcrates.io-latest-orange)](https:\u002F\u002Fcrates.io\u002Fcrates\u002Fleankg)\n[![SafeSkill 77\u002F100](https:\u002F\u002Fimg.shields.io\u002Fbadge\u002FSafeSkill-77%2F100_Passes%20with%20Notes-yellow)](https:\u002F\u002Fsafeskill.dev\u002Fscan\u002Ffreepeak-leankg)\n\n**Lightweight Knowledge Graph for AI-Assisted Development**\n\nLeanKG 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.\n\n\nVisualize your knowledge graph with force-directed layout, WebGL rendering, and community clustering.\n\n![LeanKG Graph Visualization](docs\u002Fscreenshots\u002Fgraph.jpeg)\n![LeanKG Obsidian](docs\u002Fscreenshots\u002Fobsidian.jpeg)\n\nSee [docs\u002Fweb-ui.md](docs\u002Fweb-ui.md) for more features.\n\n---\n\n## Live Demo\n\nTry LeanKG without installing: **https:\u002F\u002Fleankg.onrender.com**\n\n```bash\nleankg web --port 9000\n```\n\n---\n\n## Installation\n\n### One-Line Install (Recommended)\n\n```bash\ncurl -fsSL https:\u002F\u002Fraw.githubusercontent.com\u002FFreePeak\u002FLeanKG\u002Fmain\u002Fscripts\u002Finstall.sh | bash -s -- \u003Ctarget>\n```\n\n**Supported targets:**\n\n| Target | AI Tool | Auto-Installed |\n|--------|---------|-----------------|\n| `opencode` | OpenCode AI | Binary + MCP + Plugin + Skill + AGENTS.md |\n| `cursor` | Cursor AI | Binary + MCP + Skill + AGENTS.md + Session Hook |\n| `claude` | Claude Code | Binary + MCP + Plugin + Skill + CLAUDE.md + Session Hook |\n| `gemini` | Gemini CLI | Binary + MCP + Skill + GEMINI.md |\n| `kilo` | Kilo Code | Binary + MCP + Skill + AGENTS.md |\n| `antigravity` | Google Antigravity | Binary + MCP + Skill + GEMINI.md |\n\n**Examples:**\n```bash\ncurl -fsSL https:\u002F\u002Fraw.githubusercontent.com\u002FFreePeak\u002FLeanKG\u002Fmain\u002Fscripts\u002Finstall.sh | bash -s -- cursor\ncurl -fsSL https:\u002F\u002Fraw.githubusercontent.com\u002FFreePeak\u002FLeanKG\u002Fmain\u002Fscripts\u002Finstall.sh | bash -s -- claude\n```\n\n### Install via Cargo or Build from Source\n\n```bash\ncargo install leankg && leankg --version\n```\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002FFreePeak\u002FLeanKG.git && cd LeanKG && cargo build --release\n```\n\n---\n\n## Quick Start\n\n```bash\nleankg init                              # Initialize LeanKG in your project\nleankg index .\u002Fsrc                        # Index your codebase\nleankg watch .\u002Fsrc                        # Auto-index on file changes\nleankg impact src\u002Fmain.rs --depth 3       # Calculate blast radius\nleankg status                             # Check index status\nleankg metrics                            # View token savings\nleankg web                                # Start Web UI at http:\u002F\u002Flocalhost:8080\nleankg export --format mermaid            # Export graph as Mermaid, DOT, or JSON\nleankg quality --min-lines 50             # Find oversized functions\nleankg detect-clusters                    # Identify functional code communities\nleankg trace --all                        # Show feature-to-code traceability\nleankg annotate src\u002Fmain.rs::main -d \"Entry point\"  # Annotate code elements\n\n# Run shell commands with RTK compression\nleankg run -- cargo test -- --compress\n\n# REST API server with auth\nleankg api-serve --port 8081 --auth\nleankg api-key create --name my-key\n\n# Process management\nleankg proc status                        # Show running LeanKG\u002FVite processes\nleankg proc kill                          # Kill all LeanKG\u002FVite processes\n\n# Obsidian vault sync\nleankg obsidian init                      # Initialize Obsidian vault structure\nleankg obsidian push                      # Push LeanKG data to Obsidian notes\nleankg obsidian pull                      # Pull annotation edits from Obsidian\nleankg obsidian watch                     # Watch vault for changes and auto-pull\nleankg obsidian status                    # Show vault status\n\n# Microservice call graph (via Web UI)\nleankg web                                # Start Web UI at http:\u002F\u002Flocalhost:8080\n                                          # Then visit http:\u002F\u002Flocalhost:8080\u002Fservices\n\n# Multi-repo registry\nleankg register my-project                # Register a repository\nleankg list                               # List all registered repos\nleankg setup                              # Configure MCP for all repos + install Claude hooks\n```\n\nSee [docs\u002Fcli-reference.md](docs\u002Fcli-reference.md) for all commands.\n\n---\n\n## Claude Code Setup\n\nLeanKG auto-triggers in Claude Code sessions via lifecycle hooks that route search intents to LeanKG tools instead of native tools.\n\n```bash\n# Install LeanKG with Claude Code hooks and plugin\nleankg setup\n\n# Then restart Claude Code or run:\n\u002Freload-plugins\n```\n\n**What `leankg setup` installs:**\n- `.claude-plugin\u002F` - Plugin manifest for Claude Code validation\n- `hooks\u002F` - Full lifecycle hooks: Setup, SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, Stop\n- Adds `leankg@local` to `enabledPlugins` in `~\u002F.claude\u002Fsettings.json`\n\n**Hook lifecycle:**\n- `Setup` - Version gating on startup\n- `SessionStart` - Injects tool selection hierarchy into every session\n- `UserPromptSubmit` - Initializes session context with LeanKG patterns\n- `PreToolUse` - Nudges toward LeanKG when you use Grep\u002FRead\u002FBash for code analysis\n- `PostToolUse` - Logs LeanKG MCP tool usage for analytics\n- `Stop` - Captures session summary for future context retrieval\n\n---\n\n## How LeanKG Helps\n\n```mermaid\ngraph LR\n    subgraph \"Without LeanKG\"\n        A1[AI Tool] -->|Full codebase context| B1[15,000-45,000 tokens]\n        B1 --> A1\n    end\n\n    subgraph \"With LeanKG\"\n        A2[AI Tool] -->|Targeted subgraph| C[LeanKG Graph]\n        C -->|Context reduction| A2\n    end\n```\n\n**Without LeanKG**: AI processes full context from files found via grep\u002Fsearch.\n**With LeanKG**: AI queries knowledge graph for targeted context. Token reduction varies by task complexity (see [benchmark results](tests\u002Fbenchmark\u002Fresults\u002Fclean-benchmark-2026-04-21.md)).\n\n---\n\n\n## Highlights\n\n- **Auto-Init** -- Install script configures MCP, rules, skills, and hooks automatically\n- **Auto-Trigger** -- Session hooks inject LeanKG context into every AI tool session\n- **Token Optimized** -- Targeted subgraph retrieval vs full file scanning\n- **Impact Radius** -- Compute blast radius before making changes\n- **Pre-Commit Risk Analysis** -- `detect_changes` classifies risk as critical\u002Fhigh\u002Fmedium\u002Flow\n- **Dependency Graph** -- Build call graphs with `IMPORTS`, `CALLS`, `TESTED_BY` edges\n- **MCP Server** -- Expose graph via MCP protocol for AI tool integration (40 tools)\n- **Orchestration** -- Smart context routing with caching via natural language intent\n- **Community Detection** -- Auto-detect functional clusters in your codebase\n- **Multi-Language** -- Index Go, TypeScript, Python, Rust, Java, Kotlin, Ruby, PHP, Perl, R, Elixir, Bash with tree-sitter\n- **Android** -- Extract XML layouts, resources, manifest relationships, and navigation graphs\n- **Service Topology** -- Microservice call graph visualization\n- **Annotation Search** -- Search code by `@Entity`, `@HiltViewModel`, and other annotations\n- **Graph Export** -- Export as JSON, DOT, or Mermaid formats\n- **REST API** -- Full REST API with auth and API key management\n- **RTK Compression** -- Run shell commands with token-saving compression\n\nSee [docs\u002Farchitecture.md](docs\u002Farchitecture.md) for system design and data model details.\n\n---\n\n## Supported AI Tools\n\n| Tool | Auto-Setup | Session Hook | Plugin | Full Lifecycle Hooks |\n|------|------------|--------------|--------|---------------------|\n| Cursor | Yes | session-start | - | - |\n| Claude Code | Yes | session-start | Yes | Setup, SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, Stop |\n| OpenCode | Yes | - | Yes | - |\n| Kilo Code | Yes | - | - | - |\n| Gemini CLI | Yes | - | - | - |\n| Google Antigravity | Yes | - | - | - |\n| Codex | Yes | - | - | - |\n\n> **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.\n\nSee [docs\u002Fagentic-instructions.md](docs\u002Fagentic-instructions.md) for detailed setup and auto-trigger behavior.\n\n---\n\n## Context Metrics\n\nTrack token savings to understand LeanKG's efficiency.\n\n```bash\nleankg metrics --json              # View with JSON output\nleankg metrics --since 7d           # Filter by time\nleankg metrics --tool search_code   # Filter by tool\n```\n\nSee [docs\u002Fmetrics.md](docs\u002Fmetrics.md) for schema and examples.\n\n---\n\n## Update\n\n```bash\n# Check current version\nleankg version\n\n# Update LeanKG binary (kills processes, removes old binary, installs hooks)\nleankg update\n\n# Or via install script\ncurl -fsSL https:\u002F\u002Fraw.githubusercontent.com\u002FFreePeak\u002FLeanKG\u002Fmain\u002Fscripts\u002Finstall.sh | bash -s -- update\n\n# Obsidian vault sync\nleankg obsidian init                      # Initialize Obsidian vault\nleankg obsidian push                      # Push LeanKG data to Obsidian notes\nleankg obsidian pull                      # Pull annotation edits from Obsidian\n```\n\n\n---\n\n## Documentation\n\n| Doc | Description |\n|-----|-------------|\n| [docs\u002Fcli-reference.md](docs\u002Fcli-reference.md) | All CLI commands |\n| [docs\u002Fmcp-tools.md](docs\u002Fmcp-tools.md) | MCP tools reference |\n| [docs\u002Fagentic-instructions.md](docs\u002Fagentic-instructions.md) | AI tool setup & auto-trigger |\n| [docs\u002Farchitecture.md](docs\u002Farchitecture.md) | System design, data model |\n| [docs\u002Fweb-ui.md](docs\u002Fweb-ui.md) | Web UI features |\n| [docs\u002Fmetrics.md](docs\u002Fmetrics.md) | Metrics schema & examples |\n| [docs\u002Fbenchmark.md](docs\u002Fbenchmark.md) | Performance benchmarks |\n| [docs\u002Froadmap.md](docs\u002Froadmap.md) | Feature planning |\n| [docs\u002Ftech-stack.md](docs\u002Ftech-stack.md) | Tech stack & structure |\n| [docs\u002Fandroid-extraction.md](docs\u002Fandroid-extraction.md) | Android XML & resource extraction |\n\n---\n\n## Troubleshooting\n\n## Troubleshooting\n\n### High RAM Usage on macOS\n\nLeanKG uses memory-mapped I\u002FO and in-memory caching which can consume significant RAM on macOS. Primary causes:\n\n| Cause | Location | Fix |\n|-------|----------|-----|\n| SQLite mmap_size=256MB | `src\u002Fdb\u002Fschema.rs:20` | Set `LEANKG_MMAP_SIZE=134217728` (128MB) |\n| Deprecated `all_elements()` | `src\u002Fgraph\u002Fquery.rs:537` | Use `get_elements_paginated()` instead |\n| Deprecated `all_relationships()` | `src\u002Fgraph\u002Fquery.rs:992` | Use `get_relationships_paginated()` |\n| SessionCache 500K tokens | `src\u002Fcompress\u002Fsession_cache.rs:11` | Set `LEANKG_CACHE_MAX_TOKENS=100000` |\n| Multiple GraphEngine cached | `src\u002Fmcp\u002Fserver.rs:48-49` | Cache eviction with TTL |\n| Multiple cache layers | Various | Enable `memory_only` mode for PersistentCache |\n\n**Quick fix - add to your shell profile:**\n```bash\nexport LEANKG_MMAP_SIZE=134217728   # 128MB instead of 256MB\nexport LEANKG_CACHE_MAX_TOKENS=100000  # 100K instead of 500K\n```\n\nSee [INSTRUCTION.md](INSTRUCTION.md) for detailed memory tuning and MCP server setup.\n\n### Database Lock Error\n\nIf you see `database is locked (code 5)`, another LeanKG process is holding the database:\n\n```bash\n# Kill all leankg and vite processes\nleankg-kill\n\n# Or manually\npkill -9 -f \"leankg\"\npkill -9 -f \"vite\"\n```\n\n### Process Management\n\n```bash\nleankg proc kill        # Kill all leankg and vite processes\nleankg proc status      # Show running leankg\u002Fvite processes\n```\n\n**Important:** Always kill the web server before indexing to avoid database lock conflicts.\n\n---\n\n## Performance Benchmarks\n\n### Load Test Results (100K nodes)\n\n| Operation | Throughput |\n|-----------|------------|\n| Insert elements | ~57,618 elements\u002Fsec |\n| Insert relationships | ~67,067 relationships\u002Fsec |\n| Retrieve all elements | ~418,718 elements\u002Fsec |\n| Cache speedup (cold to warm) | 345-461x |\n\nRun load tests:\n```bash\ncargo test --release load_test -- --nocapture\n```\n\n### A\u002FB Benchmark Results\n\nSee [tests\u002Fbenchmark\u002Fresults\u002Fclean-benchmark-2026-04-21.md](tests\u002Fbenchmark\u002Fresults\u002Fclean-benchmark-2026-04-21.md) for detailed A\u002FB testing results comparing LeanKG vs baseline code search.\n\n---\n\n## Requirements\n\n- Rust 1.75+\n- macOS or Linux\n\n---\n\n## License\n\nMIT\n\n---\n\n## Star History\n\n\u003Ca href=\"https:\u002F\u002Fwww.star-history.com\u002F?repos=FreePeak%2FLeanKG&type=date&legend=top-left\">\n \u003Cpicture>\n   \u003Csource media=\"(prefers-color-scheme: dark)\" srcset=\"https:\u002F\u002Fapi.star-history.com\u002Fchart?repos=FreePeak\u002FLeanKG&type=date&theme=dark&legend=top-left\" \u002F>\n   \u003Csource media=\"(prefers-color-scheme: light)\" srcset=\"https:\u002F\u002Fapi.star-history.com\u002Fchart?repos=FreePeak\u002FLeanKG&type=date&legend=top-left\" \u002F>\n   \u003Cimg alt=\"Star History Chart\" src=\"https:\u002F\u002Fapi.star-history.com\u002Fchart?repos=FreePeak\u002FLeanKG&type=date&legend=top-left\" \u002F>\n \u003C\u002Fpicture>\n\u003C\u002Fa>\n","LeanKG 是一个轻量级的知识图谱工具，旨在为AI辅助开发提供精确的代码库上下文。它使用Rust语言构建，能够索引代码、生成依赖关系图，并通过MCP服务器让Cursor、OpenCode和Claude Code等工具直接查询知识图谱。其核心功能包括本地优先的数据处理方式，无需云服务或外部数据库支持，同时提供了基于WebGL渲染的可视化界面来展示知识图谱。LeanKG适用于需要高效利用代码库信息以提高开发效率的场景，特别是在与AI编码助手集成时，能够显著减少不必要的API调用，从而节省成本。","2026-06-11 02:45:14","CREATED_QUERY"]