VerBodh

VerBodh · AI KB Internals · Coding agents

AI KB Internals

Two graphs for coding agents: fewer tokens, and lessons that last

VerBodh · 22 October 2026

A coding agent spends much of its token budget on finding code: it searches, opens files, and reads them to learn who calls what. This article shows two graphs that change that. A code graph answers where the code is in one call. A work graph remembers why and what was proved, so the agent gets better from one session to the next without retraining.

Who it is for: developers who build LLM apps and coding-agent setups, and teams that pay for the tokens their agents use.

What this covers

  1. The token problem
  2. Inside a code graph
  3. How the agent talks to it: MCP
  4. Wiring it into Claude Code, Codex, Copilot and Gemini
  5. What the context hook costs
  6. Measure the tool, not the promise
  7. Traps
  8. The second graph: a work graph
  9. How an agent improves between sessions
  10. Keep the two graphs apart
 question: "who calls X?"
      │
      ├─► CODE GRAPH (where)            SQLite: symbols + links, built from source
      │      one MCP call ─► source + callers + impact ─► open only those files
      │
      ├─► edit ─► the graph's file watcher re-indexes on save
      │
      └─► WORK GRAPH (why, what was proved)
             task ─► acceptance criteria ─► evidence ─► check ─► lesson
                                                                  │
             next session reads the lesson before it starts ◄─────┘

1. The token problem

Search returns lines; the agent must still open files to find which function each line sits in. A code graph returns the calling functions themselves.

Lookup grep Code graph
Button in TabBridge (public, 51 files) 27 lines · 2,947 characters 463 characters: 6 dependents, each with its function and line
An access check in a 2,376-file Rust and TypeScript monorepo 8,732 characters, 18 files 5,592 characters: 60 callers
A membership check, same monorepo 6,648 characters 4,209 characters: 43 callers
A lookup helper in a Python tools repository 2,638 characters 1,000 characters: 15 callers

The graph's answer is 36–84% shorter, and it is already the answer, not a list of places to look.

Two other things already cut token cost, so measure the graph's saving on top of them: prompt caching, which makes repeated context cheap, and a hook that summarises long search output before the model reads it.

2. Inside a code graph

The examples use CodeGraph, an open-source (MIT) code graph. It parses source with tree-sitter and stores the result in one SQLite file, .codegraph/codegraph.db. Two tables do the work: every function, class or route is a row in nodes, and every relation between two of them is a row in edges.

CREATE TABLE nodes (id TEXT PRIMARY KEY, kind TEXT, name TEXT, file_path TEXT,
                    start_line INTEGER, end_line INTEGER, signature TEXT /* … */);
CREATE TABLE edges (source TEXT REFERENCES nodes(id), target TEXT REFERENCES nodes(id),
                    kind TEXT /* contains, calls, references, imports … */, line INTEGER);

"Who calls X" is one join. Run against TabBridge:

SELECT s.name AS caller, s.kind, e.line, s.file_path
FROM edges e JOIN nodes t ON t.id = e.target JOIN nodes s ON s.id = e.source
WHERE e.kind = 'calls' AND t.name = 'Button';

caller        kind      line  file_path
ApprovalCard  function  33    extension/src/pane/ApprovalCard.tsx
Actions       function  130   extension/src/pane/shared.tsx
Pane          function  11    extension/src/popup.tsx

The tool reports 6 dependents, not 3: it counts the 3 functions that call Button and the 3 files that import it. Know what your tool counts before you compare numbers.

3. How the agent talks to it: MCP

The agent starts codegraph serve --mcp as a child process and talks JSON-RPC over stdin and stdout (Model Context Protocol). In version 1.6.2 the server offers one tool, codegraph_explore. Its answer holds the source of the relevant symbols, the call path between them and a list of what depends on them.

→ {"method":"initialize", …}
← {"serverInfo":{"name":"codegraph","version":"1.6.2"},
   "instructions":"# Codegraph — available (per-project; pass projectPath) …"}
→ {"method":"tools/call","params":{"name":"codegraph_explore",
   "arguments":{"query":"Button ApprovalCard"}}}
← "- ApprovalCard → Button   [dynamic: renders <Button>] … Found 25 symbols …"

The instructions string matters. Claude Code puts each server's instructions into the model's context, so the model reads "ask the graph before you read files" before its first tool call.

4. Wiring it into Claude Code, Codex, Copilot and Gemini

One command connects the agents it supports. Turn telemetry off first: indexing before that queues anonymous usage data.

npm i -g @colbymchenry/codegraph@1.6.2
codegraph telemetry off
codegraph init -y .                                   # in the repository root
codegraph install -y --target claude,copilot-cli,codex
agy mcp add codegraph -- codegraph serve --mcp         # Gemini through Antigravity CLI

For Claude Code, the installer writes three things: the server in ~/.claude.json, a permission mcp__codegraph__* in ~/.claude/settings.json, and a UserPromptSubmit hook, codegraph prompt-hook.

Agents that run in a fresh clone need more. A CI job or a cloud runner has no index, and Claude Code started with --strict-mcp-config uses only the MCP servers passed with --mcp-config, never the global ones. Such a runner must build the index in the clone and pass the server itself.

5. What the context hook costs

The hook reads each prompt before the model does. For a question about code structure it adds a <codegraph_context> block with source and callers. It saves a tool call, but it is not free.

Prompt, in TabBridge Context the hook adds
"who calls Button?" 9,251 characters: more than grep's 2,947 for the same question
"is there any sensitive info to publish this article" a short hint naming publishApprovals, because the word "publish" matched
"fix the typo in README" nothing

The hook matches words, not intent. On a small repository its context can cost more than the search it replaces.

6. Measure the tool, not the promise

Version 0.6.8 of the same tool answered "No callers found" for the access check with 60 callers. Version 1.6.2 finds all of them.

Lookup 0.6.8 1.6.2
Access check no callers (wrong) 60 callers
Membership check 29 callers (missed 14) 43 callers
A helper defined 3 times 1 of 3 definitions all 3, 15 callers
Full index of the monorepo 21 s 9 s

An agent trusts what the graph says. A wrong "no callers" invites it to delete live code.

7. Traps

Trap What happens Do instead
Deleting "unused" code Calls through strings, macros or reflection are invisible to any static graph Confirm with one search before you delete
Git worktrees A worktree has no index of its own; the tool answers from an index in a parent folder and says "not found" codegraph init -y in the worktree; codegraph uninit -f . before you remove it
Same name, many functions callers lists every definition Narrow with -f <file>
After a pull with no agent open Only the MCP server watches files codegraph sync .
Committing the index The monorepo's index is 148 MiB, over GitHub's 100 MB limit, and changes on every save Keep .codegraph/ in .gitignore; each machine builds its own

8. The second graph: a work graph

A code graph knows where code is. It cannot know why it was written, what "done" meant, or what went wrong last time. A work graph holds that. Ours is called Graph-Engineering: a small SQLite graph per project with four kinds of node.

Node Holds Linked by
Task what is being built requires its criteria
Acceptance criterion an observable result, pending until proved verified_by its evidence
Evidence a real test or check result —
Lesson a trigger, the cause, the action for next time guides the tasks it applies to

The completion check passes only when every criterion links to real evidence. A passing build is not evidence that a user flow works.

9. How an agent improves between sessions

A model does not learn from your sessions. Its weights stay the same. What can change is what it reads at the start of the next session. That is the whole mechanism, so build it on purpose:

failure or owner correction ─► lesson (trigger · cause · action · evidence)
        ─► next task reads matching lessons first ─► applies the action
        ─► evidence shows it worked ─► lesson marked effective
                                  └─► it failed ─► revise or retire the lesson

10. Keep the two graphs apart

Code graph Work graph
Answers where the code is why, and what was proved
Changes on every save when a task moves
Lifetime a cache: rebuilt per machine, wiped by a version upgrade a record: kept
Owner a third-party tool you

Merging them would put your records in a cache that the next upgrade rebuilds. Link them thinly instead: a lesson names the symbol it is about, and evidence can hold an impact report from the code graph.

Checklist

Where this fits

iKanban ships both ideas to its subscribers. A setup skill in the developer kit installs and connects the code graph for each agent. On the laptop runner, a Use CodeGraph setting, on by default, indexes each run's fresh clone.

Limits

Sources

VERBODH PTE. LTD. · SINGAPORE · support@verbodh.com
UEN 202640155R · Privacy, Terms & Security