Codegraph
Turn any codebase into a queryable knowledge graph. Health scores, drift detection, impact analysis, onboarding guides -- all from your AST.
Why Codegraph?
Most code intelligence tools need embeddings, vector stores, or LLM API keys before they do anything useful. Codegraph builds a real graph from your source code using tree-sitter AST parsing -- 25+ languages, zero configuration, no API keys required. The graph is a NetworkX DiGraph: nodes are symbols (functions, classes, modules), edges are relationships (imports, calls, inheritance). Every analysis command operates on this graph directly.
It works standalone or as a force multiplier for AI coding assistants (Claude Code, Cursor, Gemini CLI, Codex, and more).
Quick Start
pip install codegraph
cd your-project/
codegraph .
That's it. Open codegraph-out/graph.html for the interactive visualization, or codegraph-out/GRAPH_REPORT.md for the architectural report.
Core Commands
| Command | What it does |
|---|---|
codegraph <path> |
Build knowledge graph from source code |
codegraph debt |
Composite health score (0-100) with letter grade |
codegraph drift snapshot |
Save current architecture as a named baseline |
codegraph drift compare |
Detect what changed since the last baseline |
codegraph onboard |
Generate a guided codebase tour from graph topology |
codegraph impact "<file>" |
Blast radius -- what breaks if you change this? |
codegraph test-impact |
Which tests to run for your changed files |
codegraph security |
Attack surface analysis: source-to-sink path tracing |
codegraph owners |
Git-blame overlay: knowledge silos, bus factor, orphaned code |
codegraph refactor-plan "<target>" |
Safe refactoring order with dependency-aware risk assessment |
Example: codegraph debt
ARCHITECTURAL DEBT SCORE
========================================
72.4 / 100 [B]
Graph: 1,247 nodes, 3,891 edges, 18 communities
BREAKDOWN
----------------------------------------
[======== ] God Node Concentration (25%)
Top nodes: Router(47), Database(38), Config(31)
[=========== ] Cross-Community Coupling (25%)
412/3891 edges cross boundaries
[=============] Import Cycles (20%)
0 cycle(s) detected
[========= ] Community Cohesion (20%)
Avg density: 34% across 18 communities
[============ ] Dead Code (10%)
89/1247 nodes unreferenced (7%)
RECOMMENDATIONS
----------------------------------------
1. Split Router (degree 47) -- extract route groups into sub-modules
2. Reduce coupling between Community 3 <-> Community 7 (28 edges)
All Commands
| Command | Description |
|---|---|
codegraph <path> |
Build knowledge graph from source code |
codegraph update |
Incrementally rebuild only changed files |
codegraph debt |
Architectural debt score (0-100) with CI gating (--threshold) |
codegraph drift snapshot |
Save current graph as a named baseline |
codegraph drift compare |
Compare current graph against a baseline |
codegraph drift history |
List saved baselines |
codegraph changelog |
Git-aware architectural changelog (--since 2w, --ref HEAD~10) |
codegraph onboard |
Guided codebase tour from graph topology |
codegraph impact "<file>" |
Blast radius analysis with risk assessment |
codegraph test-impact |
Map changed files to affected tests (pipe to xargs pytest) |
codegraph security |
Attack surface: source-to-sink path tracing |
codegraph owners |
Ownership analysis: knowledge silos, bus factor, --codeowners generation |
codegraph refactor-plan "<target>" |
Dependency-aware refactoring plan with safe ordering |
codegraph tui |
Interactive terminal navigator (keyboard-driven, no dependencies) |
codegraph dashboard |
Live architecture dashboard at localhost:8787 |
codegraph affected "<node>" |
Reverse traversal: all nodes impacted by a change |
codegraph simulate remove "<node>" |
Simulate removing a node -- cascade analysis |
codegraph simulate merge "<A>" "<B>" |
Simulate merging two modules |
codegraph simulate refactor "<a>" "<b>" --into <name> |
Simulate extracting nodes into a new module |
codegraph discover |
Detect latent connections, bridges, capability clusters |
codegraph features |
Identify product features from code structure |
codegraph patterns |
Match against 10 software architecture patterns |
codegraph diagnose |
Diagnose architectural issues |
codegraph reflect |
Generate architectural reflection from saved Q&A |
codegraph explain "<node>" |
Explain a node and its connections |
codegraph path "<A>" "<B>" |
Shortest path between two concepts |
codegraph query "<question>" |
Natural language query (requires LLM) |
codegraph tree |
Interactive collapsible dependency tree (HTML) |
codegraph god-nodes |
List the most connected nodes |
codegraph prs |
PR dashboard: CI state, review status |
codegraph export html|neo4j|obsidian|svg|graphml|callflow-html|wiki |
Export to various formats |
codegraph global add <path> |
Add a repo to the cross-repo global graph |
codegraph benchmark |
Measure token reduction vs naive full-corpus approach |
All commands support --json for machine-readable output.
Supported Languages (25+)
Python, JavaScript, TypeScript, Go, Rust, Java, C, C++, C#, Ruby, Kotlin, Scala, PHP, Swift, Lua, Zig, PowerShell, Elixir, Objective-C, Julia, Verilog, Fortran, Bash, Groovy, Apex, Dart, Pascal, OCaml, Common Lisp, Terraform (HCL), Robot Framework, DM (BYOND), Razor, Blade, SQL, JSON/config, Markdown
Language detection is automatic. Each language has a dedicated tree-sitter extractor.
How It Works
Source Code
|
v
[tree-sitter AST parsing] -- per-language extractors for 25+ languages
|
v
[Symbol extraction] -- functions, classes, modules, imports, calls
|
v
[Cross-file resolution] -- resolve imports, inheritance, call chains
|
v
[NetworkX DiGraph] -- nodes = symbols, edges = relationships
|
v
[Analysis / Simulation / Visualization]
|--- Debt scoring (health grade 0-100)
|--- Drift detection (baseline snapshots)
|--- Impact & test-impact analysis
|--- Security (source-to-sink tracing)
|--- Simulation engine (remove, merge, refactor)
|--- Discovery engine (latent connections, features, patterns)
|--- Interactive HTML + TUI + dashboard
|--- Export (Neo4j, Obsidian, SVG, GraphML)
Zero-LLM default mode: The core pipeline (parse, build, analyze, simulate, discover, debt, drift, onboard, security, test-impact, owners, refactor-plan) works without any API key. LLM integration is optional for natural language queries, enriched reports, and community labeling.
AI Agent Integration
codegraph install claude # Claude Code
codegraph install cursor # Cursor
codegraph install gemini # Gemini CLI
codegraph install codex # OpenAI Codex
codegraph install kilo # Kilo Code
codegraph install vscode # VS Code Copilot Chat
codegraph install antigravity # Google Antigravity
codegraph install kiro # Kiro IDE/CLI
An MCP server is also available:
pip install "codegraph[mcp]"
codegraph-mcp # exposes suggest_refactoring + impact_analysis tools
CI Integration
Use codegraph debt --threshold as a CI quality gate:
# .github/workflows/codegraph.yml
- name: Architecture health check
run: |
pip install codegraph
codegraph . --code-only
codegraph debt --threshold 60
Use codegraph test-impact --changed to run only affected tests:
- name: Smart test selection
run: |
codegraph test-impact --changed | xargs pytest
Optional Extras
pip install "codegraph[mcp]" # MCP server for AI coding assistants
pip install "codegraph[openai]" # OpenAI LLM integration
pip install "codegraph[anthropic]" # Anthropic LLM integration
pip install "codegraph[ollama]" # Ollama (local LLM) integration
pip install "codegraph[neo4j]" # Neo4j graph database export
pip install "codegraph[falkordb]" # FalkorDB graph database export
pip install "codegraph[pdf]" # PDF document ingestion
pip install "codegraph[watch]" # File watcher for live rebuilds
pip install "codegraph[svg]" # Static SVG diagram export
pip install "codegraph[office]" # Word/Excel document ingestion
pip install "codegraph[video]" # Video transcription ingestion
pip install "codegraph[postgres]" # PostgreSQL schema introspection
pip install "codegraph[all]" # Everything
Requirements
- Python 3.10+
- No API keys required for core functionality
License
MIT License. See LICENSE for details.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file codeknow-1.1.0.tar.gz.
File metadata
- Download URL: codeknow-1.1.0.tar.gz
- Upload date:
- Size: 891.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03dc1abac3f29fe376f2b02d1f081f76262f51683b317e3f85e0819cf9fe33d8
|
|
| MD5 |
3ca4633f6b1b844b33ad7324a3abedb1
|
|
| BLAKE2b-256 |
517ed6393aa11e8de2b0695f46d2f284a2216c4719e04a8ed37900e925a45037
|
File details
Details for the file codeknow-1.1.0-py3-none-any.whl.
File metadata
- Download URL: codeknow-1.1.0-py3-none-any.whl
- Upload date:
- Size: 941.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a821f2cae61e8d8ab71e35a9fe2a9aab20136cc0f052347b164d8570a0c84917
|
|
| MD5 |
ff2e34b16bd968ecf4615d8bf16cc439
|
|
| BLAKE2b-256 |
664a5f2a607bc6eda4606d6c3d33cb18d428f24a30b1cc8b00b9d5ab4a0c9489
|