ctxgraph-code 0.6.1__tar.gz → 0.6.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. ctxgraph_code-0.6.3/LICENSE +21 -0
  2. ctxgraph_code-0.6.3/MANIFEST.in +4 -0
  3. {ctxgraph_code-0.6.1/src/ctxgraph_code.egg-info → ctxgraph_code-0.6.3}/PKG-INFO +192 -6
  4. ctxgraph_code-0.6.1/PKG-INFO → ctxgraph_code-0.6.3/README.md +587 -434
  5. ctxgraph_code-0.6.3/docs/Benchmark Vs Graphify.jpg +0 -0
  6. ctxgraph_code-0.6.3/docs/benchmark1.jpg +0 -0
  7. ctxgraph_code-0.6.3/docs/benchmark2.jpg +0 -0
  8. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/pyproject.toml +17 -4
  9. ctxgraph_code-0.6.3/src/ctxgraph_code/__init__.py +3 -0
  10. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/cli.py +1 -1
  11. ctxgraph_code-0.6.1/README.md → ctxgraph_code-0.6.3/src/ctxgraph_code.egg-info/PKG-INFO +620 -408
  12. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code.egg-info/SOURCES.txt +5 -0
  13. ctxgraph_code-0.6.1/src/ctxgraph_code/__init__.py +0 -1
  14. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/setup.cfg +0 -0
  15. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/__main__.py +0 -0
  16. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/analyzers/__init__.py +0 -0
  17. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/analyzers/python/__init__.py +0 -0
  18. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/analyzers/python/importer.py +0 -0
  19. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/analyzers/python/semantic.py +0 -0
  20. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/analyzers/python/symbols.py +0 -0
  21. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/analyzers/treesitter/__init__.py +0 -0
  22. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/analyzers/treesitter/analyzer.py +0 -0
  23. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/analyzers/treesitter/languages.py +0 -0
  24. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/config/__init__.py +0 -0
  25. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/config/build_status.py +0 -0
  26. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/config/global_paths.py +0 -0
  27. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/config/hooks.py +0 -0
  28. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/config/init.py +0 -0
  29. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/config/settings.py +0 -0
  30. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/exclude/__init__.py +0 -0
  31. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/exclude/patterns.py +0 -0
  32. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/graph/__init__.py +0 -0
  33. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/graph/builder.py +0 -0
  34. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/graph/models.py +0 -0
  35. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/graph/query.py +0 -0
  36. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/graph/storage.py +0 -0
  37. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/render/__init__.py +0 -0
  38. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/render/_text.py +0 -0
  39. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/render/mermaid.py +0 -0
  40. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/view/__init__.py +0 -0
  41. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code/view/visualizer.py +0 -0
  42. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code.egg-info/dependency_links.txt +0 -0
  43. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code.egg-info/entry_points.txt +0 -0
  44. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code.egg-info/requires.txt +0 -0
  45. {ctxgraph_code-0.6.1 → ctxgraph_code-0.6.3}/src/ctxgraph_code.egg-info/top_level.txt +0 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Shashi Kundan
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,4 @@
1
+ include LICENSE
2
+ graft docs
3
+ recursive-exclude * __pycache__
4
+ recursive-exclude * *.pyc
@@ -1,13 +1,18 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ctxgraph-code
3
- Version: 0.6.1
3
+ Version: 0.6.3
4
4
  Summary: Code knowledge graph for Claude Code. Build a relationship graph of your Python codebase and query it during coding sessions.
5
- Author: ctxgraph-code contributors
6
- License: MIT
7
- Keywords: code-graph,knowledge-graph,claude-code,code-analysis,ctx
5
+ Author-email: Shashi Kundan <shashikundan0001@gmail.com>
6
+ Project-URL: Homepage, https://github.com/shashi3070/ctxgraph-code
7
+ Project-URL: Repository, https://github.com/shashi3070/ctxgraph-code
8
+ Project-URL: Documentation, https://github.com/shashi3070/ctxgraph-code#readme
9
+ Project-URL: Issues, https://github.com/shashi3070/ctxgraph-code/issues
10
+ Project-URL: Changelog, https://github.com/shashi3070/ctxgraph-code/blob/main/CHANGELOG.md
11
+ Keywords: code-graph,knowledge-graph,claude-code,code-analysis,ctx,python,codebase,llm,code-intelligence,tree-sitter,ast,code-navigation
8
12
  Classifier: Development Status :: 3 - Alpha
9
13
  Classifier: Intended Audience :: Developers
10
14
  Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
11
16
  Classifier: Programming Language :: Python :: 3
12
17
  Classifier: Programming Language :: Python :: 3.10
13
18
  Classifier: Programming Language :: Python :: 3.11
@@ -16,6 +21,7 @@ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
21
  Classifier: Topic :: Software Development :: Code Generators
17
22
  Requires-Python: >=3.10
18
23
  Description-Content-Type: text/markdown
24
+ License-File: LICENSE
19
25
  Requires-Dist: typer>=0.9
20
26
  Requires-Dist: rich>=13.0
21
27
  Provides-Extra: full
@@ -23,10 +29,17 @@ Requires-Dist: tree-sitter>=0.22; extra == "full"
23
29
  Requires-Dist: tree-sitter-language-pack>=0.13; extra == "full"
24
30
  Provides-Extra: dev
25
31
  Requires-Dist: pytest>=7.0; extra == "dev"
32
+ Dynamic: license-file
26
33
 
27
34
  # ctxgraph-code
28
35
 
29
- **Code knowledge graph for Claude Code.** Build a relationship graph of your codebase (Python, JavaScript, TypeScript, C, Go, Rust, and more) so Claude Code understands imports, class hierarchies, function calls, and cross-file dependencies without reading every file.
36
+ **How do we give AI the right context without sending the entire codebase every time?**
37
+
38
+ `ctxgraph-code` answers that question. Instead of dumping files into the context window, it builds a **relationship graph** of your codebase using static AST analysis, stores it in a local SQLite database, and retrieves only the relevant symbols and dependencies when Claude Code needs to understand your code.
39
+
40
+ **Result:** One codebase question drops from ~25,000 tokens to ~800 tokens — a **95% reduction** in context usage. A full 30-question benchmark showed **90% fewer tokens** than traditional file reading, and **16% fewer than graph-based alternatives**.
41
+
42
+ ![Product Overview](https://raw.githubusercontent.com/shashi3070/ctxgraph-code/master/docs/benchmark2.jpg)
30
43
 
31
44
  ```bash
32
45
  pip install ctxgraph-code
@@ -67,6 +80,29 @@ ctxgraph-code setup
67
80
  # /ctxgraph-code
68
81
  ```
69
82
 
83
+ ## How It Works (At a Glance)
84
+
85
+ ```
86
+ Your Codebase
87
+
88
+
89
+ 1. Static AST Analysis ──► Extract imports, classes, functions, calls, relationships
90
+
91
+
92
+ 2. Knowledge Graph ──► Store everything in local SQLite (files, symbols, edges)
93
+
94
+
95
+ 3. Query Engine ──► Search graph by relevance, expand to neighbors via BFS
96
+
97
+
98
+ 4. Context Retrieval ──► Only the relevant snippets, not whole files
99
+
100
+
101
+ 5. Claude Code ──► Receives focused context → Better answers, fewer tokens, less noise
102
+ ```
103
+
104
+ No huge graph-building prompts sent to the LLM. The graph is built locally with Python's AST parser — zero LLM calls, zero API costs.
105
+
70
106
  ## Commands
71
107
 
72
108
  ### `setup` (recommended)
@@ -113,6 +149,37 @@ ctxgraph-code init
113
149
 
114
150
  Creates the `.ctxgraph/` directory with a default `config.toml`.
115
151
 
152
+ ### `subgraph`
153
+
154
+ ```bash
155
+ ctxgraph-code subgraph "add pagination to the users endpoint"
156
+ ```
157
+
158
+ Extracts a **focused subgraph** relevant to a task description — returns matching nodes, their relationships, and inline source code in a single compact response. Saves 1-2 tool calls by combining graph search, dependency resolution, and file reading.
159
+
160
+ - `--max-nodes` / `-n` — max nodes in subgraph (default: 10)
161
+
162
+ ### `diff`
163
+
164
+ ```bash
165
+ ctxgraph-code diff
166
+ ctxgraph-code diff --ref main
167
+ ```
168
+
169
+ Compares the graph with the filesystem. Shows files that have been **added, removed, or changed** since the graph was built. Use `--ref` for a git-aware diff against a branch. Essential for knowing when to run `ctxgraph-code build --incremental`.
170
+
171
+ ### `mermaid`
172
+
173
+ ```bash
174
+ ctxgraph-code mermaid classDiagram
175
+ ctxgraph-code mermaid flowchart --output diagram.md
176
+ ```
177
+
178
+ Exports the graph as a **Mermaid diagram** for embedding in documentation or PRs. Supported types: `classDiagram`, `flowchart`, `sequence`.
179
+
180
+ - `--output` / `-o` — save to file instead of stdout
181
+ - `--max-nodes` / `-n` — maximum nodes in diagram (default: 50)
182
+
116
183
  ### `build`
117
184
 
118
185
  ```bash
@@ -348,6 +415,105 @@ This catches the common case where you edit a file after building the graph and
348
415
 
349
416
  ---
350
417
 
418
+ ## Benchmark Results
419
+
420
+ Real-world benchmarks against a production Python/UI codebase. Three approaches compared across 30 code understanding questions.
421
+
422
+ ### Repository Profile
423
+
424
+ | Metric | Value |
425
+ |---|---|
426
+ | Backend Python LOC | 45,570 |
427
+ | UI Source LOC | 37,317 |
428
+ | Documentation LOC | 9,120 |
429
+ | Source Files | 143 |
430
+ | Raw Tokens | ~140,000 |
431
+
432
+ ### Three Retrieval Methods Compared
433
+
434
+ | Approach | How It Works |
435
+ |---|---|
436
+ | **Baseline** (File Reading) | `grep` → read entire files → answer. Every question repeatedly loads large source files. |
437
+ | **Graphify** (Knowledge Graph) | Build full graph → compressed node summaries → answer. Incurs large upfront graph-building cost. |
438
+ | **CtxGraph-Code** (Symbol Graph) | Local AST → SQLite symbol graph → retrieve only relevant files → answer. Only targeted files opened. |
439
+
440
+ ### Combined Results (30 Questions)
441
+
442
+ | Approach | Total Tokens | Avg/Question | Reduction |
443
+ |---|---|---|---|
444
+ | Baseline (File Reading) | 203,590 | 6,786 | — |
445
+ | Graphify | 25,100 | 837 | 88% |
446
+ | **CtxGraph-Code** | **21,120** | **704** | **90%** |
447
+
448
+ CtxGraph-Code is **9.6× more efficient** than reading raw files, and uses **16% fewer tokens** than Graphify.
449
+
450
+ ![Benchmark Comparison](https://raw.githubusercontent.com/shashi3070/ctxgraph-code/master/docs/Benchmark%20Vs%20Graphify.jpg)
451
+
452
+ ### Per-Suite Breakdown
453
+
454
+ | Suite | Baseline | Graphify | CtxGraph-Code | Winner |
455
+ |---|---|---|---|---|
456
+ | BM1: Architecture | 73,500 | 12,100 | 10,150 | CtxGraph-Code |
457
+ | BM2: Data Flow & UI Logic | 130,090 | 13,000 | 10,970 | CtxGraph-Code |
458
+ | **Combined** | **203,590** | **25,100** | **21,120** | **CtxGraph-Code** |
459
+
460
+ ### Biggest Win: File Comparison
461
+
462
+ Question: *"How does tasks_fixed.py differ from tasks.py?"*
463
+
464
+ - `tasks.py`: 2,372 lines
465
+ - `tasks_fixed.py`: 1,512 lines
466
+
467
+ | Approach | Tokens |
468
+ |---|---|
469
+ | Baseline | 31,070 |
470
+ | Graphify | 1,400 |
471
+ | **CtxGraph-Code** | **1,150 (96% savings)** |
472
+
473
+ Instead of reading both files completely, CtxGraph-Code compares symbols and retrieves only relevant differences.
474
+
475
+ ### Context Window Longevity
476
+
477
+ With a 200K token context window:
478
+
479
+ | Approach | Tokens/Question | Questions Before Exhaustion |
480
+ |---|---|---|
481
+ | Baseline | 6,786 | ~29 |
482
+ | Graphify | 837 | ~239 |
483
+ | **CtxGraph-Code** | **704** | **~284 (10× longer sessions)** |
484
+
485
+ ### Graphify vs CtxGraph-Code: Detailed Comparison
486
+
487
+ ![Phase-by-Phase Comparison](https://raw.githubusercontent.com/shashi3070/ctxgraph-code/master/docs/Benchmark%20Vs%20Graphify.jpg)
488
+
489
+ | Metric | Graphify | CtxGraph-Code |
490
+ |---|---|---|
491
+ | **Build approach** | Full knowledge graph first | Local symbol graph via AST + SQLite |
492
+ | **Upfront LLM cost** | ~141,728 input tokens | ~0 tokens (local AST parse, ~246s) |
493
+ | **Total input tokens** | ~157,728 | ~22,500 (**85.7% fewer**) |
494
+ | **Output tokens** | ~12,000 | ~3,500 (**70.8% fewer**) |
495
+ | **Query speed** | Moderate (BFS/DFS traversal) | Fast (SQLite indexed lookup) |
496
+ | **Strengths** | Architecture visualization, community detection, cross-file relationship discovery | Inline source retrieval, indexed search, symbol resolution, implementation-focused answers |
497
+ | **Weaknesses** | No implementation snippets; often requires opening source files after | Less visualization; relationship discovery less deep |
498
+ | **Best for** | Architecture discovery, planning, cross-cutting concerns | Code navigation, execution flow, symbol lookup, implementation questions |
499
+
500
+ **Bottom line:** Use CtxGraph-Code for fast code search and implementation answers. Use Graphify when you need architecture visualization and cross-file relationship discovery.
501
+
502
+ ### Real-World Example Results
503
+
504
+ | Question | Without | With CtxGraph-Code | Savings |
505
+ |---|---|---|---|
506
+ | Learning Mode | 9,498 | 3,267 | 66% |
507
+ | Planner Node | 13,166 | 7,043 | 47% |
508
+ | Dashboard Embedding | 5,180 | 2,840 | 45% |
509
+ | Authentication | 9,498 | 3,267 | 66% |
510
+ | Deep Learning Mode | 25,000 | 800 | 95% |
511
+ | **Overall (30 questions)** | **203,590** | **21,120** | **90%** |
512
+
513
+ ![Detailed Benchmark Results](https://raw.githubusercontent.com/shashi3070/ctxgraph-code/master/docs/benchmark1.jpg)
514
+
515
+ ---
516
+
351
517
  ## Using with Claude Code
352
518
 
353
519
  After `ctxgraph-code setup`, the `/ctxgraph-code` slash command is installed globally by default — it works in every Claude Code session. Claude sees:
@@ -367,6 +533,9 @@ After `ctxgraph-code setup`, the `/ctxgraph-code` slash command is installed glo
367
533
  - `ctxgraph-code overview --dir <name>` -- Show project structure for a specific graph
368
534
  - `ctxgraph-code symbols <path>` -- List classes/functions defined in a file
369
535
  - `ctxgraph-code context "task"` -- Generate a focused context summary
536
+ - `ctxgraph-code subgraph "task"` -- Focused subgraph with inline source
537
+ - `ctxgraph-code diff` -- Files changed since build
538
+ - `ctxgraph-code mermaid --type classDiagram` -- Export as Mermaid diagram
370
539
  - `ctxgraph-code view --dir <name>` -- Visualize a graph interactively
371
540
  ```
372
541
 
@@ -404,13 +573,30 @@ Built-in default exclusion patterns (always applied): `__pycache__`, `*.pyc`, `.
404
573
 
405
574
  ---
406
575
 
576
+ ## Where It Helps
577
+
578
+ `ctxgraph-code` delivers the most value when working with **existing codebases built over months or years**:
579
+
580
+ | Helps Most | Helps Less |
581
+ |---|---|
582
+ | 🐛 Debugging production issues | Tiny projects (2–3 files) |
583
+ | 🏗 Understanding architecture | Throwaway scripts |
584
+ | 🔍 Tracing dependencies | Greenfield projects created entirely in the same Claude session |
585
+ | 🔄 Safe refactoring | Short experiments |
586
+ | 📚 Onboarding into large existing codebases | |
587
+ | 🧩 Multi-module repositories | |
588
+
589
+ The biggest gains come when AI needs to understand **existing code written over months or years**, not when starting from scratch.
590
+
591
+ ---
592
+
407
593
  ## Differences from `ctxgraph`
408
594
 
409
595
  `ctxgraph-code` is a **focused subset** of [ctxgraph](https://github.com/shashi3070/ctxgraph) designed specifically for Claude Code.
410
596
 
411
597
  | Feature | ctxgraph | ctxgraph-code |
412
598
  |---------|----------|---------------|
413
- | CLI commands | 9+ | 17 (init, build, query, deps, usedby, overview, symbols, context, setup, view, info, install-slash, build-status, probe, install-hooks, uninstall-hooks, version) |
599
+ | CLI commands | 9+ | 20 (init, build, query, deps, usedby, overview, symbols, context, subgraph, diff, mermaid, setup, view, info, install-slash, build-status, probe, install-hooks, uninstall-hooks, version) |
414
600
  | LLM integration | Built-in (Ollama, Claude, OpenAI, Azure) | None (delegates to Claude Code) |
415
601
  | Chat sessions | Yes | No |
416
602
  | Visualizer | D3.js HTML + SVG | D3.js HTML (`view` opens in browser, `--tree` for text) |