M05 Β· The Tool Landscape: CodeGraph, okf-rs, and Friends
Learning objectives Intermediate
- Explain CodeGraph's architecture β tree-sitter β SQLite + FTS5, fully local, one MCP call per answer β and read its 7-project benchmark table critically.
- Describe the three-layer auto-sync design (OS watchers β debounced batching β staleness flags) and why "no rebuild step" is an architectural achievement, not a slogan.
- Explain okf-rs's different bet: a git-diffable Markdown bundle instead of a database, with deterministic output and CI-grade validation.
- Contrast structural graphs with Cursor-style semantic indexing (answers vs leads) and with cloud tools (data-sovereignty constraints).
- Apply six comparison axes to evaluate any code-knowledge tool β including ones that don't exist yet.
Graphify (M04) is one point in a design space that filled up fast. This module maps the rest of it β not as a product roundup, but as a set of design decisions: where the graph lives, how it stays fresh, what it labels, and where your code goes. Learn the axes and every future tool launch becomes a 10-minute evaluation instead of a leap of faith.
CodeGraph: the database bet
CodeGraph is an MIT-licensed, open-source code intelligence tool (32,100 GitHub stars) that parses every source file with tree-sitter, extracts symbols (functions, classes, methods, interfaces) and edges (calls, imports, inheritance, implementations), and stores everything in a local SQLiteThe embedded, serverless SQL database that lives in a single file β no server process, no configuration. The most deployed database on earth. database with FTS5SQLite's built-in Full-Text Search extension (version 5): tokenizes text into an index so "which rows mention X" is answered without scanning every row. full-text search enabled. The entire graph lives in one file: .codegraph/codegraph.db. No cloud component, no API key, no network connection, no data transmission.
Where Graphify's canonical output is three files an assistant reads, CodeGraph's center of gravity is the query path: when an AI agent asks "what calls this function?" or "trace the full impact of changing this module," CodeGraph responds in a single MCP tool call β entry points, related symbols, and relevant code snippets. No file-by-file exploration, no agent loops, no context windows bloated with irrelevant file contents. Recall from M00 that most agent tokens are exploration, not reasoning; CodeGraph's design attacks exactly that line item.
The installer is deliberately zero-configuration: it auto-detects which AI tools are present β Claude Code, Cursor, Codex CLI, OpenCode, Gemini CLI, and others β and wires up the MCP integration without manual setup:
# macOS / Linux
curl -fsSL https://raw.githubusercontent.com/colbymchenry/codegraph/main/install.sh | sh
# Windows PowerShell
irm https://raw.githubusercontent.com/colbymchenry/codegraph/main/install.ps1 | iex
# then, per project:
cd your-project
codegraph init -i # -i = initial full-graph buildPractical notes worth keeping: the initial build on very large projects (100,000+ files) can take ten minutes or more β a one-time cost, after which all sync is incremental. macOS users should install Xcode command-line tools first (xcode-select --install); the fallback compatibility mode runs 5β10Γ slower. Default exclusions cover node_modules, vendor, dist, build, target, .venv, gitignored files, and files over 1 MB. Supported languages: TypeScript, Python, Rust, Java, Go, Swift, Kotlin, C/C++, C#, Ruby, PHP, Dart, plus template languages like Svelte and Vue β with the deepest coverage in TypeScript, Python, Rust, and Go, and Objective-C listed as partial.
CodeGraph's benchmarks: the best table in the field
CodeGraph's team ran the most rigorous comparison published so far: seven real open-source projects in seven languages, identical exploration tasks, the same model (Claude Opus 4.7 in headless mode, claude -p), four runs per arm, medians reported β the sole variable being whether the graph was available. Vendor-reported, but methodologically serious. Here is the table, and then the three patterns that matter more than the table:
| Codebase | Language | Size | Token cut | Cost cut | Speedup | Ops cut |
|---|---|---|---|---|---|---|
| VS Code | TypeScript | 10,000 files | 78% | 26% | 52% | 85% |
| Excalidraw | TypeScript | ~640 files | 90% | 52% | 73% | 96% |
| Tokio | Rust | ~790 files | 86% | 82% | 71% | 92% |
| Django | Python | ~3,000 files | 36% | 12% | 19% | 53% |
| Alamofire | Swift | ~110 files | 64% | 47% | 48% | 83% |
| OkHttp | Java | ~645 files | 13% | 2% | 31% | 45% |
| Gin | Go | ~110 files | 34% | 21% | 27% | 40% |
Aggregates: 57% fewer tokens, 71% fewer tool calls, 46% faster responses, 35% lower costs. Now the patterns:
Pattern 1 β size correlates with savings. On VS Code's 10,000-file monorepo, token usage dropped from 2.8 million to 601,000 per benchmark run. On Excalidraw, from 3.5 million to 344,000. The larger the haystack, the more the AI flails without a map β the same corpus-topology law behind Graphify's 6.8Γβ49Γ spread in M04, seen from the other side.
Pattern 2 β Rust benefits disproportionately. Tokio's cost fell 82% ($2.41 β $0.42). The likely cause: Rust's module system β mod declarations, use paths, pub use re-exports, nested hierarchies β creates exploration paths that punish agent-based traversal hardest, and the graph resolves them in one query.
Pattern 3 β small repos see diminishing returns. OkHttp managed 13%; Gin 34%. At small scale brute force isn't that punishing, so the map's marginal value shrinks β the ~500-file floor again, now with per-language data.
And the caveat that reframes everything: these are not model improvements. Same model in both arms. Every saved token was mechanical file exploration eliminated β work that contributed nothing to answer quality. As the CodeGraph write-up put it: the fastest way to make an AI coding tool better might not be to make it smarter β it might be to give it a map.
Static description: a scatter plot of token savings vs repo size. Small repos cluster low (OkHttp 13%, Gin 34%); mid-size and large repos climb (Alamofire 64%, VS Code 78%, Tokio 86%, Excalidraw 90%); Django (36%) sits below trend. A rising trend line shows: the bigger the haystack, the more the map saves β with real scatter around the trend.
The auto-sync architecture: three layers of staying fresh
Before: think of a shared team calendar that only updates when someone remembers to click "refresh." Meetings move, rooms change β and everyone keeps showing up to the old room, because the calendar looked perfectly confident.
The pain: the failure isn't that the calendar is wrong once; it's that nothing tells you it's wrong. A confident stale answer beats no answer at being dangerous.
The mapping: a code graph is that calendar, and commits are the moving meetings. CodeGraph's answer is a three-layer sync design whose goal is that no human ever clicks refresh β and whose most underrated layer is the one that admits when it's behind.
Layer 1 β native OS file watchers. macOS FSEvents, Windows ReadDirectoryChangesW, Linux inotify β the lowest-level change-notification mechanism each OS provides. No polling, no CPU overhead; when a file is saved, the OS pushes the notification.
Layer 2 β debounced batching. A two-second quiet window collects all changes and collapses them into a single incremental sync. A refactor that touches five files in rapid succession triggers one re-index, not five. (Incremental parsing from M03 is what makes each sync proportional to the edit.)
Layer 3 β staleness flags and reconnection reconciliation. Files not yet synchronized are explicitly marked stale, so agents know to read them directly rather than trust outdated graph data. When an AI tool reconnects, a fast (size, mtime) comparison with content-hash verification identifies only the changed files to resync.
The result: an index that stays current with zero developer attention β "there is no rebuild-the-index step in anyone's workflow." Layer 3 deserves special respect: it is the only layer that handles its own failure, telling the consumer "don't trust me on these files yet." Hold that thought β M11 is an entire module about graph-freshness systems that lack such a layer, and the silent, documented ways they rot.
Static description: five file-save events flow into the OS watcher, collect inside a 2-second debounce window (a filling bar), and emerge as one incremental sync into codegraph.db. A parallel red path shows unsynced files getting an explicit stale flag telling agents to read them directly.
Framework route recognition
One CodeGraph feature earns its own section because it solves a debugging chore every API developer knows: "which handler processes POST /api/users?" Answering that by hand means finding the route config, tracing to the view, verifying the middleware β multiple search-and-verify cycles through indirection that exists precisely to keep routing declarative.
CodeGraph natively recognizes routing patterns across 14 web frameworks, covering all four routing paradigms:
| Paradigm | Examples | What the extractor reads |
|---|---|---|
| Annotation-based | Spring, NestJS | @GetMapping/@Controller-style annotations on classes and methods |
| Decorator-based | Flask, FastAPI | @app.post("/invoices") decorators β exactly what orderflow's billing app uses |
| DSL-based | Rails, Laravel | routes files written in a routing mini-language |
| File-convention | Django URLconf, SvelteKit | URL structure encoded in file layout / urlpatterns |
With that in the graph, the URL maps directly to the handler function β through middleware chains, route includes, and decorator stacks β in a single query. For teams managing microservices or large API surfaces, this feature alone can justify the installation.
okf-rs: the Markdown-bundle bet
okf-rs is an open-source Rust CLI (by Jeremy Jeanne, MIT/Apache-2.0 dual-licensed) that turns a codebase into a portable Open Knowledge FormatOKF: Google Cloud's June 2026 spec for knowledge as a directory of Markdown files with YAML frontmatter. Track 3 of this course (M06βM08) covers it in depth. knowledge base: plain Markdown files with YAML frontmatter, cross-linked into a real call graph, readable by humans and agents. No proprietary database, no vector store, no SDK required to read it back. It's git-diffable, greppable, and renders natively on GitHub.
The output difference is philosophical. Where CodeGraph's graph lives in codegraph.db (query it through the tool), okf-rs generates a knowledge/ directory β one .md file per module, struct, enum, function, or method:
$ okf-rs generate .
Generated 146 concepts into knowledge
Module 16 Struct 18 Enum 6 Function 87 Method 19
$ okf-rs validate
knowledge β no issues foundA single generated concept looks like this β remember the shape; you'll be writing these by hand in M06:
---
type: Rust Method
title: verify_token
resource: src/main.rs#L4-L6
generated:
by: okf-rs/0.1.0
---
## Signature
`fn verify_token(&self, token: &str) -> bool`
## Calls
- [decode_jwt](../../../functions/src/Auth/decode_jwt.md)Its design principles read like a checklist of everything this track has taught: Open β the output is the artifact, no runtime needed to read it. Fast β native Rust core on tree-sitter, not a compiler frontend. Deterministic β identical source produces byte-identical output (no timestamps, no unordered-map noise; M03's reproducibility argument as a hard guarantee). AI-ready without requiring AI β structured enough for an LLM to consume, no LLM involved in producing it.
And the feature list runs deep for a young tool. Highlights, grouped:
- Extraction: 11 languages (Rust, Python, TypeScript, JavaScript, Go, Java, C#, PHP, Kotlin, C/C++, Swift) with per-language visibility rules (M03's table); a resolved call graph covering bare, method/
self/this, static, scoped, and qualified calls; optional LSP-backed disambiguation (--lsp, via rust-analyzer/pyright); content-hash incremental caching and awatchmode with debouncing. - Search: exact/substring, ranked full-text (Tantivy, with camelCase/snake_case boundary matching β
verifyTokenfindsverify_token), and optional semantic search against any OpenAI-compatible embeddings endpoint. - Optional AI enrichment β genuinely optional:
generate --enrichfills in missing descriptions via any OpenAI-compatible endpoint (Ollama, LM Studio, a cloud provider) and never overwrites an existing description;suggest-linksproposes plausible missing relationships, advisory only. - Deterministic architecture extraction β no AI required:
graph layers(dependency depth),graph domains,graph communities(ClausetβNewmanβMoore modularity clustering β verified by dogfooding to split an 18-crate workspace that connected-components collapses into one blob),graph patterns(Builder/Singleton/Factory/Visitor signals),graph features(REST endpoints, DB models by convention). - CI & review:
impact <ref-a> <ref-b>scores every changed concept by transitive-caller count (blast radius β M01's metric, productionized), public-API membership, and cycle participation;reviewrenders a sticky-comment-ready Markdown report with--fail-on-riskgating and a ready-made GitHub Action. - Validation built for CI: schema checks, dangling-link and orphan detection, duplicate identities,
Calls/CalledByasymmetry β with a--ciflag that hardens warnings into failures. - Exports: HTML, paginated PDF, GraphML (Gephi/yEd), Obsidian vaults, and a two-way DITA bridge β round-tripped on its own 715-concept export with zero data loss.
- MCP server:
okf-mcpexposessearch,graph_callers,graph_callees,graph_api,graph_cycles,graph_modules,graph_path, and a compositeexplore. One-line registration:Because it speaks plain MCP over stdio, the same binary works with any MCP client β build the bundle once, every agent in your toolchain gets it. (M09 dissects this server and its token economics, including the ~400Γ per-query worked example.)shell Β· register with Claude Codeclaude mcp add okf-rs -- /path/to/okf-mcp /path/to/project
One more habit worth copying: every feature was dogfooded against okf-rs's own ~850-concept codebase β which caught a real DTD-handling bug in the DITA round-trip that a hand-written fixture would have missed. init also idempotently updates CLAUDE.md, AGENTS.md, and .github/copilot-instructions.md with a marked section pointing agents at the bundle, and the CI recipe okf-rs generate --no-cache && okf-rs validate --ci ensures a stale bundle never ships silently β a one-line preview of everything M11 stands for.
Semantic indexing vs structural graphs: leads vs answers
Cursor's built-in codebase indexing is the most widely deployed alternative, and it works on a different principle: vector embeddings. Your query is vectorized; the system returns code snippets ranked by similarity. Genuinely useful for exploration β "what files are related to authentication?" β when you don't know where to look.
But recall M02's structural blind spot, now in its sharpest form: semantic search doesn't understand relationships. It doesn't know that handleAuth() calls validateToken(), which imports from jwt_utils β it knows these functions contain similar language. So the AI receives leads β similarity-ranked hints it must verify by reading files one by one. A structural graph returns answers β definitive relationships, no verification reads. For code exploration, that's a fundamentally different information architecture, and it's why the two approaches complement rather than replace each other (M10 makes this a full three-layer design).
"Structural tools make semantic indexing obsolete." β No. "Find things related to payments" is a semantic question; "find things that call charge()" is structural. You met the honest data in M04: on QA accuracy Graphify ties dense vector RAG. Different questions, different layers.
"These tools improve the model's reasoning." β They are enhancers, not replacements: they cut exploration cost. If you ask "why is this query slow?" or "design a caching layer," the heavy cognitive lifting remains with the model β the graph just delivers the relevant context cheaply.
"Local vs cloud is just a preference." β For regulated industries and proprietary codebases it's a hard constraint: cloud indexing means your code leaves the machine. That single row of the comparison table can end the evaluation before benchmarks matter.
The cloud alternatives
- Gemini Code Assist (formerly Google Cloud Code): cloud-hosted understanding that handles enormous repositories β but your code is processed on Google's infrastructure. For data-sovereignty environments, that's disqualifying regardless of quality.
- Sourcegraph: powerful universal code search and browsing; requires server deployment, indexer configuration, and maintenance. Right for organizations needing a shared platform; heavy for individuals.
- GitHub Copilot's codebase indexing: limited beta, cloud-only, restricted rollout.
Against that landscape, the local tools' shared niche is precise: local-first, zero-configuration, structured-graph code intelligence β no servers, no API keys, no data transmission, and deterministic relationships instead of probability scores. Within the niche, the differentiation is the storage substrate and freshness model you've now seen from both sides.
The six comparison axes
Tools will keep launching. Evaluate every one of them on these six axes β each axis is a question with concrete consequences:
| Axis | The question | The spread you've seen |
|---|---|---|
| 1 Β· Storage substrate | Where does the graph live? | SQLite DB (CodeGraph) Β· JSON + HTML + MD artifacts (Graphify) Β· Markdown bundle in git (okf-rs) |
| 2 Β· Sync model | How does it stay fresh? | OS watchers + debounce + stale flags (CodeGraph) Β· watch mode + content-hash cache (okf-rs) Β· manual/hook-driven rebuilds (Graphify β M11's cautionary tale) |
| 3 Β· Provenance labeling | Does it say what's a fact vs a guess? | EXTRACTED/INFERRED(/AMBIGUOUS) tags (Graphify, okf-rs, the course extractor) Β· unlabeled |
| 4 Β· Local vs cloud | Does code leave the machine? | Fully local (all three locals) Β· cloud-processed (Gemini, Copilot) Β· self-hosted server (Sourcegraph) |
| 5 Β· Query surface | How do agents and humans ask? | MCP single-call (CodeGraph, okf-mcp) Β· CLI + slash-command + MCP (Graphify) Β· CLI + MCP + exports (okf-rs) |
| 6 Β· Multimodal reach | Code only, or docs/PDFs/images too? | Code + docs/PDFs/images/video via LLM pass (Graphify) Β· code-focused (CodeGraph, okf-rs β though okf-rs imports DITA doc corpora) |
Static description: a matrix fills row by row. Substrate: Graphify = 3 artifacts, CodeGraph = SQLite+FTS5, okf-rs = Markdown bundle. Sync: hooks/manual vs watchers+stale-flags vs watch+content-hash. Provenance: EXTRACTED/INFERRED (Graphify, okf-rs), unlabeled (CodeGraph). All three are fully local. Query surfaces: CLI/slash/MCP vs single-call MCP vs CLI+MCP+exports. Multimodal: Graphify covers docs/images; the others are code-focused.
In the 90 days after Karpathy's April 2026 post, this space went from zero to three serious open-source tools plus Google's spec. Whatever launches next quarter, the six axes will still be the evaluation: substrate, sync, provenance, locality, query surface, reach. Add M04's two honesty checks β replicated-vs-vendor numbers, and the ~500-file floor β and M11's question ("how would you detect a stale graph within 24 hours?"), and you have a complete due-diligence kit.
Walk it, step by step
The same repository through each tool in turn. Read it as a decision, not a ranking β the last step is the table that tells you which one your situation actually calls for.
Hands-on exercise: build the matrix for your own repo
No lab folder for this module β the exercise runs on your real project. Time: ~30 minutes.
- Step 1 β profile the repo. Count files and languages (
git ls-files | wc -l; look at extensions). Note whether you're above or below the ~500-file floor and which benchmark row (Gin? Django? VS Code?) your repo most resembles. - Step 2 β fill the six axes for your constraints. For each axis, write the requirement your environment imposes (e.g., "code cannot leave the machine" β axis 4 eliminates cloud tools immediately; "we live in PRs" β axis 2 favors okf-rs's git-diffable bundle).
- Step 3 β pick and verify. Choose the tool the matrix points to. Install it, build the graph, and ask the three orderflow-style questions from the M04 lab ("who calls X", a path query, an impact query). β Checkpoint: each answer verified against your own knowledge of the code.
- Step 4 β record the honest number. Measure one real task with and without the graph (tokens or wall-clock). Compare against the benchmark row you predicted in Step 1. Keep this note β the capstone asks for it.
Stretch: run TWO tools on the same repo and diff their edge sets for one module. Where they disagree, determine which is right by reading the code β you'll usually find an INFERRED edge on one side and silence on the other, which is the provenance axis made tangible.
Knowledge check
1. Where does CodeGraph's entire knowledge graph live?
.codegraph/codegraph.db β with FTS5 full-text search; no cloud, no API key, no data transmission2. In CodeGraph's 7-project benchmark, Tokio (Rust) saved 86% of tokens while OkHttp (Java) saved 13%. What best explains the spread?
3. What is Layer 3 of CodeGraph's auto-sync, and why does this course keep pointing at it?
4. What is okf-rs's determinism guarantee, and what does it enable?
5. Cursor's semantic index returns "leads"; a structural graph returns "answers." What's the operational difference?
6. Your security team requires that proprietary code never leave developer machines. Which axis decides, and what survives?
Module summary
CodeGraph
tree-sitter β SQLite+FTS5, fully local, one MCP call per answer. Benchmarks: 57% fewer tokens / 71% fewer tool calls aggregate; savings scale with repo size (90% Excalidraw β 13% OkHttp).
Auto-sync done right
OS watchers β 2s debounce β staleness flags. The flag layer β admitting what's behind β is the design M11 will show everyone else missing.
okf-rs
The Markdown-bundle bet: git-diffable, byte-deterministic, CI-validated, MCP-served, with impact/review PR automation. Bridges directly into Track 3.
Six axes
Substrate Β· sync Β· provenance Β· locality Β· query surface Β· reach. Plus the standing caveats: enhancers-not-replacements, and semantic vs structural = leads vs answers.
What we built on orderflow: nothing new in code this time β instead, a durable evaluation kit, plus your own repo's profile and (if you did the stretch) a two-tool edge diff that made provenance labeling concrete.
Next module preview: Track 3 begins. okf-rs generated Markdown-with-frontmatter files because a spec told it what shape agents can rely on. That spec β Google's Open Knowledge Format, one required field, a single page of conformance rules, and a surprising amount of design wisdom β is M06.
References
- CodeGraph β GitHub repository (MIT); 7-project benchmark methodology and results; auto-sync and route-recognition docs
- okf-rs β github.com/jyjeanne/okf-rs (releases, ROADMAP.md, pr-review.yml GitHub Action)
- Graphify β M04's references; BENCHMARKS.md for the vendor-vs-replicated context
- Sourcegraph, Gemini Code Assist, GitHub Copilot indexing β vendor docs (cloud/server alternatives)
- Course exercise: this module's embedded 4-step matrix exercise (no lab folder)