<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Git-Hooks | Tobias Theel | Senior Software Engineer</title><link>https://blog.noobygames.de/tags/git-hooks/</link><description>Remote-first Senior Software Engineer specializing in Go, Cloud-Native architecture, and Game Development. 12+ years of experience in distributed environments.</description><generator>Hugo</generator><language>en</language><copyright>© 2026 Tobias Theel</copyright><lastBuildDate>Sun, 22 Nov 2026 08:00:00 +0100</lastBuildDate><atom:link href="https://blog.noobygames.de/tags/git-hooks/index.xml" rel="self" type="application/rss+xml"/><item><title>Token Cost Minimization in Agentic AI — Part 2: code-review-graph, MCP and Hooks</title><link>https://blog.noobygames.de/blog/token-cost-2-code-review-graph/</link><pubDate>Sun, 22 Nov 2026 08:00:00 +0100</pubDate><dc:creator>Tobias Theel</dc:creator><guid isPermaLink="true">https://blog.noobygames.de/blog/token-cost-2-code-review-graph/</guid><category>AI</category><category>ai</category><category>claude-code</category><category>mcp</category><category>tree-sitter</category><category>git-hooks</category><category>token-optimization</category><category>agentic-ai</category><category>code-review</category><description>code-review-graph gives coding agents a Tree-sitter code graph over MCP instead of reading whole files. Install, Claude Code and git hooks, auto-updates, real benchmark numbers and limits.</description><content:encoded><![CDATA[<blockquote>
<p><strong>Series: Token Cost Minimization in Agentic AI.</strong> <a href="/blog/token-cost-1-caveman-ponytail/">Part 1: where the tokens go, Caveman and Ponytail</a> · Part 2: code-review-graph and hooks (you are here) · <span class="link-upcoming">Part 3: Headroom, auto-updates and the combined setup</span></p>
</blockquote>
<aside class="tldr" aria-label="Key takeaways">
<p class="tldr-title">TL;DR</p>
<ul>
<li>code-review-graph v2.4.0 parses a repository with Tree-sitter into a local SQLite graph and answers agent questions over MCP, typically in 2,000 to 4,000 tokens.</li>
<li>Install code-review-graph with <code>uv tool install code-review-graph</code>, then run <code>code-review-graph install</code> and <code>code-review-graph build</code> in the repository root.</li>
<li>A Claude Code <code>PostToolUse</code> hook and four git hooks (<code>pre-commit</code>, <code>post-checkout</code>, <code>post-merge</code>, <code>post-rewrite</code>) keep the graph fresh, and all of them end with <code>|| true</code>.</li>
<li>code-review-graph&rsquo;s headline 63× reduction compares against reading every file; against grep plus the top three files, the vendor&rsquo;s median reduction is 6.65×.</li>
<li>After <code>uv tool upgrade code-review-graph</code>, run <code>code-review-graph install</code> again and check with <code>doctor</code>, because older 2.3.x copies can break the 2.4.0 schema.</li>
</ul>

</aside>

<p>In <a href="/blog/token-cost-1-caveman-ponytail/">Part 1</a> we saw that the biggest share of an agent&rsquo;s token bill is <strong>input</strong>: everything the agent reads, re-sent on every turn as history. The most common input in a coding session is source code. To answer &ldquo;what breaks if I rename this function?&rdquo;, an agent typically greps for the name, opens the three or four best-matching files in full and maybe follows a few imports. Every one of those files then stays in the context for the rest of the session.</p>
<p><a href="https://github.com/tirth8205/code-review-graph" rel="noopener">code-review-graph</a> (MIT, current release <strong>v2.4.0</strong> from 2026-11-11) replaces much of that reading with a query against a local code graph.</p>
<h2 id="how-it-saves-tokens">How it saves tokens</h2>
<p>The tool parses your repository with <a href="https://tree-sitter.github.io/tree-sitter/" rel="noopener">Tree-sitter</a>, the incremental parser behind syntax highlighting in many editors, and stores the result as a graph in one local SQLite file (<code>.code-review-graph/graph.db</code>):</p>
<ul>
<li><strong>Nodes:</strong> files, functions, classes, imports, tests.</li>
<li><strong>Edges:</strong> calls, imports, inheritance, &ldquo;test covers function&rdquo;.</li>
</ul>
<p>The graph is exposed to the agent through the <a href="https://modelcontextprotocol.io/" rel="noopener">Model Context Protocol (MCP)</a>, the open standard for connecting tools to LLM clients. The agent then asks targeted questions instead of reading files:</p>
<table>
	<thead>
			<tr>
					<th>Question</th>
					<th>MCP tool</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>Who calls <code>parseConfig</code>?</td>
					<td><code>query_graph_tool</code> with <code>callers_of</code></td>
			</tr>
			<tr>
					<td>What breaks if this file changes?</td>
					<td><code>get_impact_radius_tool</code></td>
			</tr>
			<tr>
					<td>What does my current diff touch, and how risky is it?</td>
					<td><code>detect_changes_tool</code>, <code>get_review_context_tool</code></td>
			</tr>
			<tr>
					<td>Where is the code for &ldquo;authentication&rdquo;?</td>
					<td><code>semantic_search_nodes_tool</code></td>
			</tr>
			<tr>
					<td>How is the project structured?</td>
					<td><code>get_architecture_overview_tool</code>, <code>list_communities_tool</code></td>
			</tr>
	</tbody>
</table>
<p>A typical answer is 2,000 to 4,000 tokens: names, locations, edges and, on request, the relevant source snippets. The agent reads only what the graph names. Language coverage is broad: Python, JavaScript/TypeScript, Go, Rust, Java, C/C++, C#, Ruby, Kotlin, Swift, PHP, shell, PowerShell, Terraform, notebooks and many more, plus framework-aware edges for Spring and Laravel.</p>
<p>Everything stays on your machine; embeddings for semantic search are optional and can run locally.</p>
<h2 id="installation">Installation</h2>
<p>You need Python 3.10 or newer. The README recommends <a href="https://docs.astral.sh/uv/" rel="noopener">uv</a>, which installs the CLI into its own isolated environment. If you don&rsquo;t have uv yet:</p>
<div class="os-tabs">
<div class="os-tab" data-label="Linux / macOS">
<p class="os-tab-label">Linux / macOS</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">curl -LsSf https://astral.sh/uv/install.sh <span class="p">|</span> sh
</span></span></code></pre></div>
</div>

<div class="os-tab" data-label="Windows (PowerShell)">
<p class="os-tab-label">Windows (PowerShell)</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-powershell" data-lang="powershell"><span class="line"><span class="cl"><span class="n">powershell</span> <span class="n">-ExecutionPolicy</span> <span class="n">ByPass</span> <span class="n">-c</span> <span class="s2">&#34;irm https://astral.sh/uv/install.ps1 | iex&#34;</span>
</span></span></code></pre></div>
</div>

</div>

<p>Then install code-review-graph, set up the AI tools it finds, and build the graph from the repository root:</p>
<div class="os-tabs">
<div class="os-tab" data-label="Linux / macOS">
<p class="os-tab-label">Linux / macOS</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">uv tool install code-review-graph
</span></span><span class="line"><span class="cl"><span class="nb">cd</span> ~/src/my-project
</span></span><span class="line"><span class="cl">code-review-graph install --dry-run   <span class="c1"># preview every change as a diff</span>
</span></span><span class="line"><span class="cl">code-review-graph install             <span class="c1"># MCP entry, hooks, skills, instructions</span>
</span></span><span class="line"><span class="cl">code-review-graph build               <span class="c1"># first full parse</span>
</span></span><span class="line"><span class="cl">code-review-graph detect-changes --brief
</span></span></code></pre></div>
</div>

<div class="os-tab" data-label="Windows (PowerShell)">
<p class="os-tab-label">Windows (PowerShell)</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-powershell" data-lang="powershell"><span class="line"><span class="cl"><span class="n">uv</span> <span class="n">tool</span> <span class="n">install</span> <span class="nb">code-review</span><span class="n">-graph</span>
</span></span><span class="line"><span class="cl"><span class="nb">Set-Location</span> <span class="nv">$HOME</span><span class="p">\</span><span class="n">src</span><span class="p">\</span><span class="nb">my-project</span>
</span></span><span class="line"><span class="cl"><span class="nb">code-review</span><span class="n">-graph</span> <span class="n">install</span> <span class="p">-</span><span class="n">-dry-run</span>   <span class="c"># preview every change as a diff</span>
</span></span><span class="line"><span class="cl"><span class="nb">code-review</span><span class="n">-graph</span> <span class="n">install</span>             <span class="c"># MCP entry, hooks, skills, instructions</span>
</span></span><span class="line"><span class="cl"><span class="nb">code-review</span><span class="n">-graph</span> <span class="n">build</span>               <span class="c"># first full parse</span>
</span></span><span class="line"><span class="cl"><span class="nb">code-review</span><span class="n">-graph</span> <span class="nb">detect-changes</span> <span class="p">-</span><span class="n">-brief</span>
</span></span></code></pre></div>
</div>

</div>

<p>Restart Claude Code (or your editor) afterwards. <code>install</code> detects Claude Code, Codex, Cursor, Windsurf, Zed, Continue, OpenCode, Gemini CLI, Copilot, Kiro and more; <code>--platform claude-code</code> limits it to one. <code>code-review-graph doctor</code> checks the setup without changing anything, and <code>code-review-graph uninstall --dry-run</code> shows how to get rid of it again.</p>
<p>According to the README, a cold build of a ~3,000-file repository takes about 40 seconds.</p>
<h3 id="what-install-writes">What <code>install</code> writes</h3>
<p>For Claude Code, in the repository:</p>
<ul>
<li><code>.mcp.json</code>: the MCP server entry.</li>
<li><code>.claude/settings.json</code>: two Claude Code hooks (see below).</li>
<li>Skills and a block of graph instructions in <code>CLAUDE.md</code> (skip with <code>--no-instructions</code>).</li>
<li>Git hooks in <code>.git/hooks/</code>.</li>
<li><code>.code-review-graph/</code> with the database, added to <code>.gitignore</code> automatically.</li>
</ul>
<p>The generic MCP entry looks like this when the tool was installed with <code>uv tool</code>:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-json" data-lang="json"><span class="line"><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="cl">  <span class="nt">&#34;mcpServers&#34;</span><span class="p">:</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;code-review-graph&#34;</span><span class="p">:</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">      <span class="nt">&#34;type&#34;</span><span class="p">:</span> <span class="s2">&#34;stdio&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">      <span class="nt">&#34;command&#34;</span><span class="p">:</span> <span class="s2">&#34;uvx&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">      <span class="nt">&#34;args&#34;</span><span class="p">:</span> <span class="p">[</span><span class="s2">&#34;code-review-graph&#34;</span><span class="p">,</span> <span class="s2">&#34;serve&#34;</span><span class="p">]</span>
</span></span><span class="line"><span class="cl">    <span class="p">}</span>
</span></span><span class="line"><span class="cl">  <span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><p><code>.mcp.json</code> and <code>.claude/</code> stay visible to git on purpose, so a team can commit them. If you don&rsquo;t want that, <code>install --gitignore</code> adds exactly the files that run created to a marked block in <code>.gitignore</code>. For machine-wide ignores, a <a href="/blog/global-gitignore/">global .gitignore</a> is the cleaner place.</p>
<p>On Windows, the README adds one warning: don&rsquo;t wrap the MCP command in <code>cmd /c</code> in the Claude Code config; point it at the executable directly.</p>
<h2 id="where-to-integrate-it-hooks-that-keep-the-graph-fresh">Where to integrate it: hooks that keep the graph fresh</h2>
<p>A code graph is only useful if it matches the code. A stale graph is worse than none: the agent trusts a caller list that no longer exists. That makes the update strategy the most important part of the setup. There are four places to hook in, from the inner loop to CI.</p>
<h3 id="1-claude-code-hooks-update-after-every-edit">1. Claude Code hooks: update after every edit</h3>
<p><a href="https://code.claude.com/docs/en/hooks" rel="noopener">Claude Code hooks</a> are shell commands that Claude Code runs on lifecycle events. They are configured in <code>settings.json</code> (user-wide in <code>~/.claude/settings.json</code>, per project in <code>.claude/settings.json</code>, personal per project in <code>.claude/settings.local.json</code>). <code>code-review-graph install</code> writes two of them:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-json" data-lang="json"><span class="line"><span class="cl"><span class="p">{</span>
</span></span><span class="line"><span class="cl">  <span class="nt">&#34;hooks&#34;</span><span class="p">:</span> <span class="p">{</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;PostToolUse&#34;</span><span class="p">:</span> <span class="p">[</span>
</span></span><span class="line"><span class="cl">      <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="nt">&#34;matcher&#34;</span><span class="p">:</span> <span class="s2">&#34;Edit|Write&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">        <span class="nt">&#34;hooks&#34;</span><span class="p">:</span> <span class="p">[</span>
</span></span><span class="line"><span class="cl">          <span class="p">{</span>
</span></span><span class="line"><span class="cl">            <span class="nt">&#34;type&#34;</span><span class="p">:</span> <span class="s2">&#34;command&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">            <span class="nt">&#34;command&#34;</span><span class="p">:</span> <span class="s2">&#34;command -v code-review-graph &gt;/dev/null 2&gt;&amp;1 &amp;&amp; code-review-graph hook-update; cat &gt;/dev/null || true&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">            <span class="nt">&#34;timeout&#34;</span><span class="p">:</span> <span class="mi">30</span>
</span></span><span class="line"><span class="cl">          <span class="p">}</span>
</span></span><span class="line"><span class="cl">        <span class="p">]</span>
</span></span><span class="line"><span class="cl">      <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="p">],</span>
</span></span><span class="line"><span class="cl">    <span class="nt">&#34;SessionStart&#34;</span><span class="p">:</span> <span class="p">[</span>
</span></span><span class="line"><span class="cl">      <span class="p">{</span>
</span></span><span class="line"><span class="cl">        <span class="nt">&#34;matcher&#34;</span><span class="p">:</span> <span class="s2">&#34;&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">        <span class="nt">&#34;hooks&#34;</span><span class="p">:</span> <span class="p">[</span>
</span></span><span class="line"><span class="cl">          <span class="p">{</span>
</span></span><span class="line"><span class="cl">            <span class="nt">&#34;type&#34;</span><span class="p">:</span> <span class="s2">&#34;command&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">            <span class="nt">&#34;command&#34;</span><span class="p">:</span> <span class="s2">&#34;cat &gt;/dev/null || true; command -v code-review-graph &gt;/dev/null 2&gt;&amp;1 || exit 0; code-review-graph status --repo \&#34;$(git rev-parse --show-toplevel)\&#34;&#34;</span><span class="p">,</span>
</span></span><span class="line"><span class="cl">            <span class="nt">&#34;timeout&#34;</span><span class="p">:</span> <span class="mi">10</span>
</span></span><span class="line"><span class="cl">          <span class="p">}</span>
</span></span><span class="line"><span class="cl">        <span class="p">]</span>
</span></span><span class="line"><span class="cl">      <span class="p">}</span>
</span></span><span class="line"><span class="cl">    <span class="p">]</span>
</span></span><span class="line"><span class="cl">  <span class="p">}</span>
</span></span><span class="line"><span class="cl"><span class="p">}</span>
</span></span></code></pre></div><p>What each piece does, and why:</p>
<ul>
<li><strong><code>PostToolUse</code> with matcher <code>Edit|Write</code></strong> runs after the agent changed a file. <code>hook-update</code> re-parses only files whose SHA-256 hash changed. The README measures about 2.5 seconds for a two-file edit on a ~3,000-file repository, 1.4 seconds of which is process start-up. So the next graph query within the same session already sees the new code.</li>
<li><strong><code>SessionStart</code></strong> prints the graph status (node count, last update, commit) into the session. Hook output on <code>SessionStart</code> is added to the context, so the agent knows from the first turn that a graph exists and how fresh it is. That costs a few dozen tokens per session.</li>
<li><strong><code>cat &gt;/dev/null</code></strong> reads and discards the JSON event that Claude Code writes to the hook&rsquo;s standard input, so the hook consumes its input cleanly even though it does not need it.</li>
<li><strong><code>command -v … || exit 0</code> and <code>|| true</code></strong> make the hook a no-op on a machine where the tool is not installed, for example a teammate who cloned the repository. A failing hook should never block the agent.</li>
<li><strong><code>timeout</code></strong> caps the hook. If an update takes longer, Claude Code moves on.</li>
</ul>
<p>On Windows, Claude Code runs hook commands through Git Bash, so the POSIX syntax above works unchanged.</p>
<p><strong>Optional: steering.</strong> <code>code-review-graph install --steering</code> adds a third hook for Claude Code that puts graph context (callers, callees, tests) beside every <code>Grep</code>, <code>Glob</code> and <code>Read</code>. It nudges the model towards the graph, but it costs about 0.12 seconds and up to about 220 tokens per call (README, measured on Flask). In a session with 200 reads, that is up to 44,000 extra tokens. I leave it off and rely on the instructions in <code>CLAUDE.md</code>; enable it if you see the agent ignore the graph.</p>
<h3 id="2-git-hooks-update-on-commit-checkout-merge-and-rebase">2. Git hooks: update on commit, checkout, merge and rebase</h3>
<p>The agent is not the only one changing code. You switch branches, pull and rebase. <code>install</code> therefore writes four git hooks, each wrapped in a marked block so it coexists with your own hook code:</p>
<table>
	<thead>
			<tr>
					<th>Git hook</th>
					<th>When</th>
					<th>What it runs</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td><code>pre-commit</code></td>
					<td>before each commit</td>
					<td><code>update</code>, then <code>detect-changes --brief</code> (short risk review in the terminal)</td>
			</tr>
			<tr>
					<td><code>post-checkout</code></td>
					<td>after a branch switch (not file checkouts)</td>
					<td><code>update --quiet</code></td>
			</tr>
			<tr>
					<td><code>post-merge</code></td>
					<td>after <code>git merge</code> / <code>git pull</code></td>
					<td><code>update --quiet</code></td>
			</tr>
			<tr>
					<td><code>post-rewrite</code></td>
					<td>after <code>git rebase</code></td>
					<td><code>update --quiet</code></td>
			</tr>
	</tbody>
</table>
<p>The essential part of the generated <code>post-merge</code> hook, simplified:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl"><span class="cp">#!/bin/sh
</span></span></span><span class="line"><span class="cl"><span class="c1"># &gt;&gt;&gt; code-review-graph sync hook &gt;&gt;&gt;</span>
</span></span><span class="line"><span class="cl"><span class="k">if</span> <span class="nb">command</span> -v code-review-graph &gt;/dev/null 2&gt;<span class="p">&amp;</span>1<span class="p">;</span> <span class="k">then</span>
</span></span><span class="line"><span class="cl">    <span class="nv">root</span><span class="o">=</span><span class="k">$(</span>git rev-parse --show-toplevel 2&gt;/dev/null<span class="k">)</span> <span class="o">||</span> <span class="nb">exit</span> <span class="m">0</span>
</span></span><span class="line"><span class="cl">    code-review-graph update --quiet --repo <span class="s2">&#34;</span><span class="nv">$root</span><span class="s2">&#34;</span> <span class="o">||</span> <span class="nb">true</span>
</span></span><span class="line"><span class="cl"><span class="k">fi</span>
</span></span><span class="line"><span class="cl"><span class="c1"># &lt;&lt;&lt; code-review-graph sync hook &lt;&lt;&lt;</span>
</span></span></code></pre></div><p>All hooks end with <code>|| true</code>, so <strong>the graph never blocks a commit</strong>. They also skip linked <a href="https://git-scm.com/docs/git-worktree" rel="noopener">git worktrees</a> unless you set <code>CRG_HOOK_WORKTREES=1</code>, because each worktree would need its own graph. If you run several agents in parallel worktrees, set that variable, or the agents in the worktrees query a graph of the main checkout.</p>
<p>If your team uses a hook manager such as <a href="https://pre-commit.com/" rel="noopener">pre-commit</a>, <a href="https://typicode.github.io/husky/" rel="noopener">Husky</a> or <a href="https://lefthook.dev/" rel="noopener">Lefthook</a>, it may own <code>.git/hooks/</code>. Add the same <code>code-review-graph update --quiet</code> call as a local hook there instead.</p>
<h3 id="3-watch-mode-and-the-daemon-for-editors-without-hooks">3. Watch mode and the daemon: for editors without hooks</h3>
<p>Editors like Windsurf or Zed don&rsquo;t get agent hooks. For them, and for repositories you edit outside of any agent, there is a watcher:</p>
<div class="os-tabs">
<div class="os-tab" data-label="Linux / macOS">
<p class="os-tab-label">Linux / macOS</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">code-review-graph watch                       <span class="c1"># one repo, foreground</span>
</span></span><span class="line"><span class="cl">crg-daemon add ~/src/project-a --alias proj-a  <span class="c1"># or: several repos in the background</span>
</span></span><span class="line"><span class="cl">crg-daemon add ~/src/project-b
</span></span><span class="line"><span class="cl">crg-daemon start
</span></span><span class="line"><span class="cl">crg-daemon status
</span></span></code></pre></div>
</div>

<div class="os-tab" data-label="Windows (PowerShell)">
<p class="os-tab-label">Windows (PowerShell)</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-powershell" data-lang="powershell"><span class="line"><span class="cl"><span class="nb">code-review</span><span class="n">-graph</span> <span class="n">watch</span>                             <span class="c"># one repo, foreground</span>
</span></span><span class="line"><span class="cl"><span class="nb">crg-daemon</span> <span class="n">add</span> <span class="nv">$HOME</span><span class="p">\</span><span class="n">src</span><span class="p">\</span><span class="nb">project-a</span> <span class="p">-</span><span class="n">-alias</span> <span class="nb">proj-a</span>   <span class="c"># or: several repos in the background</span>
</span></span><span class="line"><span class="cl"><span class="nb">crg-daemon</span> <span class="n">add</span> <span class="nv">$HOME</span><span class="p">\</span><span class="n">src</span><span class="p">\</span><span class="nb">project-b</span>
</span></span><span class="line"><span class="cl"><span class="nb">crg-daemon</span> <span class="nb">start
</span></span></span><span class="line"><span class="cl"><span class="nb">crg-daemon</span> <span class="n">status</span>
</span></span></code></pre></div>
</div>

</div>

<p>The daemon stores its list in <code>~/.code-review-graph/watch.toml</code> and restarts dead watchers every 30 seconds. Don&rsquo;t combine it with the hooks on the same repository without need; both work, but you pay for every update twice.</p>
<h3 id="4-ci-a-risk-comment-on-every-pull-request">4. CI: a risk comment on every pull request</h3>
<p>The same analysis runs as a GitHub Action. It builds the graph on the runner and posts one sticky comment with risk-scored functions, affected flows and test gaps:</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-yaml" data-lang="yaml"><span class="line"><span class="cl"><span class="c"># .github/workflows/code-review-graph.yml</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">on</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">pull_request</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">permissions</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">contents</span><span class="p">:</span><span class="w"> </span><span class="l">read</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">pull-requests</span><span class="p">:</span><span class="w"> </span><span class="l">write</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="nt">jobs</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">  </span><span class="nt">review</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nt">runs-on</span><span class="p">:</span><span class="w"> </span><span class="l">ubuntu-latest</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">    </span><span class="nt">steps</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span>- <span class="nt">uses</span><span class="p">:</span><span class="w"> </span><span class="l">actions/checkout@v7</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">      </span>- <span class="nt">uses</span><span class="p">:</span><span class="w"> </span><span class="l">tirth8205/code-review-graph@v2.4.0</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">        </span><span class="nt">with</span><span class="p">:</span><span class="w">
</span></span></span><span class="line"><span class="cl"><span class="w">          </span><span class="nt">github-token</span><span class="p">:</span><span class="w"> </span><span class="l">${{ secrets.GITHUB_TOKEN }}</span><span class="w">
</span></span></span></code></pre></div><p>The optional <code>fail-on-risk</code> input turns it into a merge gate. If you want a hard gate, put it here rather than in the local <code>pre-commit</code> hook.</p>
<h3 id="convenience-make-targets">Convenience: make targets</h3>
<p>If your project has a Makefile, wrap <code>code-review-graph build</code>, <code>update</code> and <code>detect-changes --brief</code> in three targets such as <code>code-graph-build</code>, <code>code-graph-update</code> and <code>code-graph-changes</code>. Humans find them next to the other build commands, and agents that read the Makefile discover them without extra instructions.</p>
<h2 id="the-numbers">The numbers</h2>
<p>The project publishes a reproducible benchmark (<a href="https://github.com/tirth8205/code-review-graph/blob/staging/docs/REPRODUCING.md" rel="noopener">REPRODUCING.md</a>): six open-source repositories at pinned commits, five sample questions each, fixed seeds, local embeddings.</p>










<figure class="diagram">
    <div class="diagram-canvas" role="img" aria-label="Vendor-measured. The first six bars compare a graph answer with reading the whole repository, an upper bound no real agent pays. The last bar is the realistic baseline: grep and read the top three files. Median 6.65×.">
        <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 720 376" width="720" height="376">
  <text x="20" y="28" class="d-t d-bold" font-size="15">code-review-graph: tokens per question, reduction factor</text>
  <text x="20" y="48" class="d-m" font-size="11.5">Whole-corpus baseline (upper bound) vs. a realistic grep-and-read-top-3 agent baseline.</text>
  <rect x="20" y="62" width="12" height="12" rx="3" fill="#4285f4"/>
  <text x="38" y="72" class="d-t" font-size="11.5">Project benchmark (crg 2.3.7, captured 2026-08-02 and 2026-09-22)</text>
  <line x1="170.0" y1="84" x2="170.0" y2="316" class="d-divider"/>
  <text x="170.0" y="332" class="d-m" font-size="11" text-anchor="middle">0×</text>
  <line x1="290.0" y1="84" x2="290.0" y2="316" class="d-divider"/>
  <text x="290.0" y="332" class="d-m" font-size="11" text-anchor="middle">100×</text>
  <line x1="410.0" y1="84" x2="410.0" y2="316" class="d-divider"/>
  <text x="410.0" y="332" class="d-m" font-size="11" text-anchor="middle">200×</text>
  <line x1="530.0" y1="84" x2="530.0" y2="316" class="d-divider"/>
  <text x="530.0" y="332" class="d-m" font-size="11" text-anchor="middle">300×</text>
  <line x1="650.0" y1="84" x2="650.0" y2="316" class="d-divider"/>
  <text x="650.0" y="332" class="d-m" font-size="11" text-anchor="middle">400×</text>
  <text x="160" y="102.0" class="d-t" font-size="12" text-anchor="end">fastapi</text>
  <path d="M170 90 H595.12 Q599.12 90 599.12 94 V102 Q599.12 106 595.12 106 H170 Z" fill="#4285f4"/>
  <text x="605.12" y="102" class="d-t" font-size="11">357.6×</text>
  <text x="160" y="136.0" class="d-t" font-size="12" text-anchor="end">flask</text>
  <path d="M170 124 H244.48000000000002 Q248.48000000000002 124 248.48000000000002 128 V136 Q248.48000000000002 140 244.48000000000002 140 H170 Z" fill="#4285f4"/>
  <text x="254.48000000000002" y="136" class="d-t" font-size="11">65.4×</text>
  <text x="160" y="170.0" class="d-t" font-size="12" text-anchor="end">code-review-graph</text>
  <path d="M170 158 H244.6 Q248.6 158 248.6 162 V170 Q248.6 174 244.6 174 H170 Z" fill="#4285f4"/>
  <text x="254.6" y="170" class="d-t" font-size="11">65.5×</text>
  <text x="160" y="204.0" class="d-t" font-size="12" text-anchor="end">gin</text>
  <path d="M170 192 H238.36 Q242.36 192 242.36 196 V204 Q242.36 208 238.36 208 H170 Z" fill="#4285f4"/>
  <text x="248.36" y="204" class="d-t" font-size="11">60.3×</text>
  <text x="160" y="238.0" class="d-t" font-size="12" text-anchor="end">httpx</text>
  <path d="M170 226 H230.2 Q234.2 226 234.2 230 V238 Q234.2 242 230.2 242 H170 Z" fill="#4285f4"/>
  <text x="240.2" y="238" class="d-t" font-size="11">53.5×</text>
  <text x="160" y="272.0" class="d-t" font-size="12" text-anchor="end">express</text>
  <path d="M170 260 H207.52 Q211.52 260 211.52 264 V272 Q211.52 276 207.52 276 H170 Z" fill="#4285f4"/>
  <text x="217.52" y="272" class="d-t" font-size="11">34.6×</text>
  <text x="160" y="306.0" class="d-t" font-size="12" text-anchor="end">grep baseline, median</text>
  <path d="M170 294 H173.98999999999998 Q177.98 294 177.98 297.99 V306.01 Q177.98 310 173.98999999999998 310 H170 Z" fill="#4285f4"/>
  <text x="183.98" y="306" class="d-t" font-size="11">6.65×</text>
  <line x1="170" y1="84" x2="170" y2="316" class="d-arrow"/>
  <text x="20" y="364" class="d-m" font-size="10.5">Last row: agent_baseline benchmark, 18 questions on 6 repos (mean 14.8×, range 4.2–72.6×). Source: project README.</text>
</svg>

    </div>
    <figcaption class="diagram-caption">Vendor-measured. The first six bars compare a graph answer with reading the whole repository, an upper bound no real agent pays. The last bar is the realistic baseline: grep and read the top three files. Median 6.65×.</figcaption>
</figure>

<table>
	<thead>
			<tr>
					<th>Repository</th>
					<th>Whole corpus</th>
					<th>Graph answer (avg)</th>
					<th>Reduction</th>
			</tr>
	</thead>
	<tbody>
			<tr>
					<td>fastapi</td>
					<td>948,793</td>
					<td>2,653</td>
					<td>357.6×</td>
			</tr>
			<tr>
					<td>flask</td>
					<td>143,594</td>
					<td>2,196</td>
					<td>65.4×</td>
			</tr>
			<tr>
					<td>code-review-graph</td>
					<td>208,821</td>
					<td>3,190</td>
					<td>65.5×</td>
			</tr>
			<tr>
					<td>gin</td>
					<td>166,868</td>
					<td>2,766</td>
					<td>60.3×</td>
			</tr>
			<tr>
					<td>httpx</td>
					<td>142,356</td>
					<td>2,661</td>
					<td>53.5×</td>
			</tr>
			<tr>
					<td>express</td>
					<td>136,052</td>
					<td>3,936</td>
					<td>34.6×</td>
			</tr>
	</tbody>
</table>
<p><em>Captured 2026-08-02 with crg 2.3.7. Source: <a href="https://github.com/tirth8205/code-review-graph" rel="noopener">README</a>.</em></p>
<p>The headline &ldquo;63× median&rdquo; compares against reading <strong>every file</strong>. The README itself says that baseline is &ldquo;an upper bound no real agent pays&rdquo;. The more honest figure is the <code>agent_baseline</code> benchmark, captured 2026-09-22: a simple grep, the top three files by match count, token-counted against the graph query. Against that, the median reduction across 18 questions on 6 repositories is <strong>6.65×</strong> (mean 14.8×, range 4.2× to 72.6×). The ratio grows with repository size, because the graph answer stays flat at 2,400 to 4,000 tokens while grep results grow with the code base.</p>
<p>Impact analysis has a precision side too: average F1 0.69 against graph-derived ground truth, precision 0.55. It is conservative by design and flags files that <em>might</em> be affected.</p>
<p>I found no independent benchmark of code-review-graph. The third-party articles I found (<a href="https://dev.to/emperorakashi20/how-code-review-graph-cuts-claude-code-token-usage-by-49x-and-whether-its-actually-worth-it-4kn1" rel="noopener">DEV Community</a>, for example) repeat or discuss the project&rsquo;s own numbers.</p>
<h3 id="my-own-measurement-this-blog">My own measurement: this blog</h3>
<p>To see what happens on a repository that is mostly not code, I looked at the graph of this blog&rsquo;s Hugo repository (code-review-graph 2.4.0, <code>status</code> and <code>detect-changes --brief</code>, 2026-11-13):</p>
<ul>
<li><strong>Indexed:</strong> 63 files, 275 nodes, 587 edges. Languages: bash, HTML templates, JavaScript, JSON, YAML. The Markdown posts, which are most of the repository, are not part of the graph.</li>
<li><strong><code>detect-changes --brief</code></strong> on a working tree with 131 changed files printed &ldquo;Full context would be: 452,279 tokens · Graph context used: 2,306 tokens · Saved ~99 %&rdquo;.</li>
</ul>
<p>That 99 % is the tool&rsquo;s <em>estimate</em>, and its baseline is &ldquo;read every changed file in full&rdquo;, which included deleted, generated image caches no agent would ever open. On this repository the graph is genuinely useful for questions about layouts, shortcodes and JavaScript. For writing posts, a plain <code>grep</code> is all the agent needs, and the MCP tools are just extra schema in the context.</p>
<h2 id="costs-and-when-it-does-not-help">Costs and when it does not help</h2>
<ul>
<li><strong>Retrieval only.</strong> All numbers measure the tokens needed to <em>locate</em> an answer. If the agent then opens the files the graph named, it pays the graph answer <em>on top</em> of those reads. <code>semantic_search_nodes_tool(include_source=True)</code> returns code with the locations to avoid that; an end-to-end measurement is, per the README, open work.</li>
<li><strong>Small edits.</strong> For a one-file change, graph context can be bigger than simply reading the file. The formal <code>token_efficiency</code> benchmark reports ratios below 1 for small commits.</li>
<li><strong>Tool schemas cost input.</strong> The MCP server exposes around 30 tools. Their definitions are context, too, unless your client loads tool schemas on demand.</li>
<li><strong>Stale graphs mislead.</strong> Without hooks or a watcher, the agent gets confident wrong answers. Set up the hooks above, or don&rsquo;t use it.</li>
<li><strong>Version drift.</strong> The MCP entry, the git hooks and the daemon can each run a different copy. After <code>uv tool upgrade code-review-graph</code>, run <code>code-review-graph install</code> again and check with <code>doctor</code>. Since 2.4.0 the graph uses schema 15, and older 2.3.x copies refuse or can break it.</li>
<li><strong>Small or non-code repositories</strong> gain little, as my measurement shows.</li>
</ul>
<h2 id="updating">Updating</h2>
<div class="os-tabs">
<div class="os-tab" data-label="Linux / macOS">
<p class="os-tab-label">Linux / macOS</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-bash" data-lang="bash"><span class="line"><span class="cl">uv tool upgrade code-review-graph
</span></span><span class="line"><span class="cl">code-review-graph doctor              <span class="c1"># every copy, MCP entry and hook, and their versions</span>
</span></span><span class="line"><span class="cl">code-review-graph install --dry-run   <span class="c1"># see what changes</span>
</span></span><span class="line"><span class="cl">code-review-graph install
</span></span><span class="line"><span class="cl">code-review-graph build               <span class="c1"># once, so fixes reach all files</span>
</span></span></code></pre></div>
</div>

<div class="os-tab" data-label="Windows (PowerShell)">
<p class="os-tab-label">Windows (PowerShell)</p>
<div class="highlight"><pre tabindex="0" class="chroma"><code class="language-powershell" data-lang="powershell"><span class="line"><span class="cl"><span class="n">uv</span> <span class="n">tool</span> <span class="n">upgrade</span> <span class="nb">code-review</span><span class="n">-graph</span>
</span></span><span class="line"><span class="cl"><span class="nb">code-review</span><span class="n">-graph</span> <span class="n">doctor</span>              <span class="c"># every copy, MCP entry and hook, and their versions</span>
</span></span><span class="line"><span class="cl"><span class="nb">code-review</span><span class="n">-graph</span> <span class="n">install</span> <span class="p">-</span><span class="n">-dry-run</span>   <span class="c"># see what changes</span>
</span></span><span class="line"><span class="cl"><span class="nb">code-review</span><span class="n">-graph</span> <span class="n">install</span>
</span></span><span class="line"><span class="cl"><span class="nb">code-review</span><span class="n">-graph</span> <span class="n">build</span>               <span class="c"># once, so fixes reach all files</span>
</span></span></code></pre></div>
</div>

</div>

<p>You can schedule this exactly like the Headroom update job in <span class="link-upcoming">Part 3</span>. I would not: because of the multi-copy issue, an upgrade should be followed by <code>install</code> and an editor restart, and that is a step I prefer to do consciously.</p>
<p>In the <span class="link-upcoming">last part</span> we add Headroom, a proxy that compresses everything the agent reads that is <em>not</em> source code (logs, JSON, test output), make it update itself with desktop notifications, and put all four tools together into one setup.</p>
<h2 id="sources">Sources</h2>
<ul>
<li><a href="https://github.com/tirth8205/code-review-graph" rel="noopener">code-review-graph README</a>, <a href="https://github.com/tirth8205/code-review-graph/blob/staging/docs/USAGE.md" rel="noopener">USAGE.md</a>, <a href="https://github.com/tirth8205/code-review-graph/blob/staging/docs/REPRODUCING.md" rel="noopener">REPRODUCING.md</a></li>
<li><a href="https://tree-sitter.github.io/tree-sitter/" rel="noopener">Tree-sitter</a>, <a href="https://modelcontextprotocol.io/" rel="noopener">Model Context Protocol</a></li>
<li><a href="https://code.claude.com/docs/en/hooks" rel="noopener">Claude Code hooks reference</a>, <a href="https://code.claude.com/docs/en/settings" rel="noopener">Claude Code settings</a></li>
<li><a href="https://git-scm.com/docs/githooks" rel="noopener">githooks documentation</a></li>
</ul>
]]></content:encoded></item></channel></rss>