Dependency Graph Design
AI coding models are highly proficient at isolated logic problems, but they struggle heavily with interconnected systems. Passing code files linearly is a major cause of hallucinations.
codectx injects a visual representation of your Dependency Graph directly into CONTEXT.md.
How it’s Built
Section titled “How it’s Built”- Tree-sitter AST:
codectxutilizes Tree-sitter, an incredibly fast incremental parsing system. We use S-expression queries (like(import_statement)) to specifically target connections between files without running or fully interpreting the code. - Path Normalization: The crawler converts all relative and aliased imports into normalized absolute paths within the repository.
- Graph Rendering: The backend uses an undirected graph topology. It groups files into highly connected clusters and renders an ASCII representation of the connections for the LLM.
Why it works for LLMs
Section titled “Why it works for LLMs”Models like Claude and GPT-4 process sequential text. When presented with a graph as markdown structured text, they can “trace” variable flow backwards to its source conceptually before they even begin generating their response, significantly improving response accuracy on complex structural changes.