ctxgraph-code 0.1.0__py3-none-any.whl

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.
@@ -0,0 +1,279 @@
1
+ Metadata-Version: 2.4
2
+ Name: ctxgraph-code
3
+ Version: 0.1.0
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
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
16
+ Classifier: Topic :: Software Development :: Code Generators
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ Requires-Dist: typer>=0.9
20
+ Requires-Dist: rich>=13.0
21
+ Provides-Extra: dev
22
+ Requires-Dist: pytest>=7.0; extra == "dev"
23
+
24
+ # ctxgraph-code
25
+
26
+ **Code knowledge graph for Claude Code.** Build a relationship graph of your Python codebase so Claude Code understands imports, class hierarchies, function calls, and cross-file dependencies without reading every file.
27
+
28
+ ```bash
29
+ pip install ctxgraph-code
30
+ cd my-project
31
+ ctxgraph-code setup
32
+ ```
33
+
34
+ Then in Claude Code, type `/ctxgraph-code` and Claude will use the graph.
35
+
36
+ ---
37
+
38
+ ## Why?
39
+
40
+ Claude Code already reads files, searches code, and understands syntax. But it can't see **relationships** between files without manual exploration:
41
+
42
+ - *What does this file import?*
43
+ - *What depends on this function?*
44
+ - *Where is this class defined?*
45
+ - *What calls this API endpoint?*
46
+
47
+ These questions require running multiple `grep` commands or reading dependency chains file by file. `ctxgraph-code` pre-computes all of this via static AST analysis and stores it in a queryable SQLite graph — so Claude can answer relationship questions in one command.
48
+
49
+ ## Quick Start
50
+
51
+ ```bash
52
+ # Install
53
+ pip install ctxgraph-code
54
+
55
+ # Navigate to your Python project
56
+ cd my-project
57
+
58
+ # One-command setup: init + build + configure Claude Code
59
+ ctxgraph-code setup
60
+
61
+ # Open Claude Code and type:
62
+ # /ctxgraph-code
63
+ ```
64
+
65
+ ## Commands
66
+
67
+ ### `setup` (recommended)
68
+
69
+ ```bash
70
+ ctxgraph-code setup
71
+ ```
72
+
73
+ Does everything in one step:
74
+ 1. Creates `.ctxgraph/config.toml` with defaults
75
+ 2. Builds the knowledge graph from all Python files
76
+ 3. Creates `.claude/commands/ctxgraph-code.md` with instructions for Claude Code
77
+
78
+ ### `init`
79
+
80
+ ```bash
81
+ ctxgraph-code init
82
+ ```
83
+
84
+ Creates the `.ctxgraph/` directory with a default `config.toml`.
85
+
86
+ ### `build`
87
+
88
+ ```bash
89
+ ctxgraph-code build
90
+ ctxgraph-code build --exclude "tests/" --exclude "*.generated.py"
91
+ ```
92
+
93
+ Scans all `*.py` files in the project, runs AST analysis:
94
+ - **Imports**: which files import other files
95
+ - **Class definitions**: class names, base classes, methods
96
+ - **Function definitions**: function names, arguments
97
+ - **Function calls**: which functions call which (within the project)
98
+ - **Docstrings**: extracted as node summaries
99
+
100
+ Stores the result in `.ctxgraph/graph.db`.
101
+
102
+ ### `query`
103
+
104
+ ```bash
105
+ ctxgraph-code query "user authentication"
106
+ ctxgraph-code query "database connection" --max 20
107
+ ```
108
+
109
+ Searches the graph by relevance scoring (name matches > summary matches > path matches) and expands to neighboring nodes via BFS up to depth 2.
110
+
111
+ ### `deps`
112
+
113
+ ```bash
114
+ ctxgraph-code deps src/api/routes.py
115
+ ```
116
+
117
+ Shows all relationships for a file: imports, imported-by, function calls, class definitions.
118
+
119
+ ### `usedby`
120
+
121
+ ```bash
122
+ ctxgraph-code usedby src/utils/helpers.py
123
+ ```
124
+
125
+ Shows every file that imports or calls something in the given file. Useful to understand **ripple effects** before making changes.
126
+
127
+ ### `overview`
128
+
129
+ ```bash
130
+ ctxgraph-code overview
131
+ ```
132
+
133
+ Prints the project structure: every file with its summary and top-level symbols.
134
+
135
+ ### `symbols`
136
+
137
+ ```bash
138
+ ctxgraph-code symbols src/main.py
139
+ ```
140
+
141
+ Lists all classes and functions defined in a file, with line numbers and docstring summaries.
142
+
143
+ ### `context`
144
+
145
+ ```bash
146
+ ctxgraph-code context "add pagination to the users endpoint"
147
+ ```
148
+
149
+ Generates a focused context summary: relevant files, their symbols, and dependency/call edges between them. This is the closest equivalent to `ctxgraph`'s capsule format.
150
+
151
+ ### `info`
152
+
153
+ ```bash
154
+ ctxgraph-code info
155
+ ```
156
+
157
+ Shows graph statistics: node/edge counts, type distribution, build time.
158
+
159
+ ---
160
+
161
+ ## How It Works
162
+
163
+ ```
164
+ Python files ──AST──> Import/Symbol/Call analysis ──> SQLite graph.db
165
+
166
+ Claude Code ──/ctxgraph-code──> CLI query/deps/overview <────┘
167
+ ```
168
+
169
+ 1. **Build phase**: `ctxgraph-code build` parses every `.py` file with Python's `ast` module. It extracts imports, class/function definitions, function calls, and docstrings. The result is a graph of **nodes** (files, classes, functions) and **edges** (imports, defines, extends, calls) stored in SQLite.
170
+
171
+ 2. **Query phase**: In Claude Code, the `/ctxgraph-code` slash command injects instructions into the conversation. Claude then runs `ctxgraph-code` commands as shell commands to query the graph. Claude reads the text output and reasons about it alongside its own file-reading capabilities.
172
+
173
+ ### What's in the graph
174
+
175
+ | Node type | Example ID | Stored |
176
+ |-----------|-----------|--------|
177
+ | `file` | `file:src/api/routes.py` | Name, path, size, summary |
178
+ | `class` | `class:src/api/routes.py::UserAPI` | Name, path, parent file, docstring, line number |
179
+ | `function` | `func:src/models.py::get_user` | Name, path, parent, docstring, line number |
180
+
181
+ | Edge relation | Meaning |
182
+ |--------------|---------|
183
+ | `imports` | File A imports file B (or a symbol from it) |
184
+ | `defines` | A file/class defines a class/function |
185
+ | `extends` | Class A extends class B |
186
+ | `calls` | Function A calls function B |
187
+
188
+ Edge weights: `imports=1.0`, `defines=1.0`, `extends=0.8`, `calls=0.7`
189
+
190
+ ### Query relevance scoring
191
+
192
+ 1. Tokenize query (lowercase, split on word boundaries, remove stopwords)
193
+ 2. For each matching node: name match → +2.0 per token, text match → +0.5 per occurrence
194
+ 3. Multiply by `0.5 + importance` (files=0.5, classes=0.6, functions=0.5)
195
+ 4. BFS expansion: neighbor nodes get `0.1 × number_of_matched_neighbors`
196
+ 5. Return top-N results sorted by score
197
+
198
+ ---
199
+
200
+ ## Using with Claude Code
201
+
202
+ After `ctxgraph-code setup`, Claude Code in the project directory will have the `/ctxgraph-code` slash command available.
203
+
204
+ When you type `/ctxgraph-code`, Claude sees:
205
+
206
+ ```
207
+ # ctxgraph-code: Code Relationship Graph
208
+
209
+ This project has a knowledge graph at `.ctxgraph/graph.db`.
210
+ The graph knows about imports, class hierarchies, and function calls.
211
+
212
+ Available commands:
213
+ - ctxgraph-code query "search terms" -- Find relevant files, classes, and functions
214
+ - ctxgraph-code deps <path> -- Show what a file imports and what calls it
215
+ - ctxgraph-code usedby <path> -- Show what depends on a file
216
+ - ctxgraph-code overview -- Show the full project structure
217
+ - ctxgraph-code symbols <path> -- List classes/functions defined in a file
218
+ - ctxgraph-code context "task" -- Generate a focused context summary
219
+ ```
220
+
221
+ Claude then uses these commands as needed during the conversation.
222
+
223
+ ### Example workflow
224
+
225
+ **You:** "Add rate limiting to the user API endpoints"
226
+
227
+ **Claude does:**
228
+ 1. `ctxgraph-code query "user api endpoint rate limit"` → finds relevant files
229
+ 2. `ctxgraph-code deps src/api/users.py` → sees what it imports and what calls it
230
+ 3. Reads actual source via built-in `read` tool
231
+ 4. Writes the rate-limiting code, knowing the full dependency context
232
+
233
+ ---
234
+
235
+ ## Configuration
236
+
237
+ Configure via `.ctxgraph/config.toml` (created by `init` or `setup`):
238
+
239
+ ```toml
240
+ [graph]
241
+ # Additional exclude patterns beyond defaults
242
+ exclude = ["tests/", "examples/"]
243
+ # Follow symlinks when scanning
244
+ follow_symlinks = false
245
+ # Skip files larger than this (MB)
246
+ max_file_size_mb = 5
247
+ ```
248
+
249
+ Default exclusion patterns: `__pycache__`, `*.pyc`, `.git`, `node_modules`, `venv`, `.venv`, `dist`, `build`, `*.egg-info`, `.pytest_cache`, `.mypy_cache`, `.ruff_cache`, `.tox`, `migrations`, `*.min.js`, `*.min.css`.
250
+
251
+ ---
252
+
253
+ ## Differences from `ctxgraph`
254
+
255
+ `ctxgraph-code` is a **focused subset** of [ctxgraph](https://github.com/shashi3070/ctxgraph) designed specifically for Claude Code.
256
+
257
+ | Feature | ctxgraph | ctxgraph-code |
258
+ |---------|----------|---------------|
259
+ | CLI commands | 9 (build, capsule, query, view, serve, info, init, ask, chat, history, skill) | 8 (init, build, query, deps, usedby, overview, symbols, context, setup, info) |
260
+ | LLM integration | Built-in (Ollama, Claude, OpenAI, Azure) | None (delegates to Claude Code) |
261
+ | Chat sessions | Yes | No |
262
+ | Visualizer | D3.js HTML + SVG | No |
263
+ | Skills system | Yes (customizable skill TOML files) | No |
264
+ | MCP server | Yes | No |
265
+ | Token savings | Yes (capsule DSL compression) | No |
266
+ | Dependency | `mcp` optional, `anyio` optional | `typer`, `rich` only |
267
+ | Claude integration | MCP protocol (Claude Desktop) | Slash command (Claude Code) |
268
+ | Windows compatibility | Blocked by `pywintypes.dll` with mcp≥1.27.2 | No issues |
269
+
270
+ ## Requirements
271
+
272
+ - Python 3.10+
273
+ - A Claude Code subscription (for the `/ctxgraph-code` slash command — the graph itself works standalone)
274
+
275
+ ---
276
+
277
+ ## License
278
+
279
+ MIT
@@ -0,0 +1,24 @@
1
+ ctxgraph_code/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ ctxgraph_code/__main__.py,sha256=AfV3Onj_9FoL9W8B5jOWOeIyYF2MwX6S4-wyF9U90wM,41
3
+ ctxgraph_code/cli.py,sha256=Lkh_zqsHH24m_JDs2z-Fz9O3QvC6AybZuDitoMrncws,11265
4
+ ctxgraph_code/render.py,sha256=iqJMzFzPxLoTINrO2qqqAisoOoP_f5p0wl1kZ9rDs7s,8477
5
+ ctxgraph_code/analyzers/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ ctxgraph_code/analyzers/python/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
7
+ ctxgraph_code/analyzers/python/importer.py,sha256=e7uGvszNqfGmvDc4wacYjoZq_KQsZ8FdYNF1-yU1NOM,4129
8
+ ctxgraph_code/analyzers/python/semantic.py,sha256=i9SvvJ2u4QfoKk6vVFjj0H6xItTsxKgO1-w202ve5oM,2332
9
+ ctxgraph_code/analyzers/python/symbols.py,sha256=Ny6IF3AgmFUChLNHZSVGaIc_vN_bLuaWxB85loC7ZMk,6027
10
+ ctxgraph_code/config/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
11
+ ctxgraph_code/config/init.py,sha256=Qzx0bEDDdkNjaB4NnKwzsw4BexPxuY5Zfm9DULnOCxE,314
12
+ ctxgraph_code/config/settings.py,sha256=JXNKiiuXXrf9DVvW-jUIhkuXgQu1a5_Pn8A8V4m7okc,3484
13
+ ctxgraph_code/exclude/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
14
+ ctxgraph_code/exclude/patterns.py,sha256=_XOjELhH3f6M1WGswVvYzbio9oT_dqAhG6DmnCOpAEU,1597
15
+ ctxgraph_code/graph/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
16
+ ctxgraph_code/graph/builder.py,sha256=JFrD6EV-o_rwXJ9nWtpj9QM4so1mBarAVxAP9sO1gj8,2453
17
+ ctxgraph_code/graph/models.py,sha256=JTgvfK8K2-F-7RPmdQrCq1RP0E4bBVeI2jRFqHqyiTI,2296
18
+ ctxgraph_code/graph/query.py,sha256=qwGIdmTZ7-csL_FMkIdABfwpUCQ1ph9TbDeE3eY_YSU,3414
19
+ ctxgraph_code/graph/storage.py,sha256=BMhcbybFP_hZv58WQTgR1SBldgFPWTuvk6im70MBMpU,7007
20
+ ctxgraph_code-0.1.0.dist-info/METADATA,sha256=_dcW2swrhbKvlfwi9bfOlPA1h5H6xSTvP9tsETKwBnk,9530
21
+ ctxgraph_code-0.1.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
22
+ ctxgraph_code-0.1.0.dist-info/entry_points.txt,sha256=Q6poS8LApu1uGl_T9hjoZ7VMC8-iXZFCMslDx6OjlRo,56
23
+ ctxgraph_code-0.1.0.dist-info/top_level.txt,sha256=ZOmow7lPtFHkcRJhLFOP5DVbt_SVaFrzsgXsawzMsq8,14
24
+ ctxgraph_code-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ ctxgraph-code = ctxgraph_code.cli:app
@@ -0,0 +1 @@
1
+ ctxgraph_code