<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: foldwork</title>
    <description>The latest articles on DEV Community by foldwork (@foldwork).</description>
    <link>https://dev.to/foldwork</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4025993%2F42fd2f5a-0a5a-4da1-8af9-5151f3c363e9.jpg</url>
      <title>DEV Community: foldwork</title>
      <link>https://dev.to/foldwork</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/foldwork"/>
    <language>en</language>
    <item>
      <title>Why the codebase is your biggest context bill, and why output compression doesn't fix it</title>
      <dc:creator>foldwork</dc:creator>
      <pubDate>Sun, 12 Jul 2026 15:30:47 +0000</pubDate>
      <link>https://dev.to/foldwork/why-the-codebase-is-your-biggest-context-bill-and-why-output-compression-doesnt-fix-it-5cp2</link>
      <guid>https://dev.to/foldwork/why-the-codebase-is-your-biggest-context-bill-and-why-output-compression-doesnt-fix-it-5cp2</guid>
      <description>&lt;p&gt;When people think about reducing AI coding costs, they usually think about the model's output: fewer words, shorter explanations, tighter responses. It's intuitive. The AI talks a lot. Make it talk less.&lt;/p&gt;

&lt;p&gt;The problem is that output is the wrong target.&lt;/p&gt;

&lt;p&gt;Paul Kinlan &lt;a href="https://aifoc.us/the-token-salary/" rel="noopener noreferrer"&gt;analysed OpenRouter's programming traffic&lt;/a&gt; using their public usage rankings and a reproducible script against the OpenRouter API. What he found:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Real-world data from OpenRouter's programming category shows 93.4% input tokens, 2.5% reasoning tokens, and just 4.0% output tokens. It's almost entirely input."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That stat surfaced in &lt;a href="https://news.ycombinator.com/item?id=47581701" rel="noopener noreferrer"&gt;a 471-point Hacker News thread&lt;/a&gt; discussing output-compression techniques. Even if you silenced the model completely, you'd be optimising 4% of the problem.&lt;/p&gt;

&lt;p&gt;The other 93% is what you put &lt;em&gt;in&lt;/em&gt;: your codebase, loaded into context on every message.&lt;/p&gt;




&lt;h2&gt;
  
  
  Why input is so heavy
&lt;/h2&gt;

&lt;p&gt;When a coding agent works on a real project, every conversation turn is expensive on the input side:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The agent reads files to understand the current state&lt;/li&gt;
&lt;li&gt;Build output, test results, and error logs get appended&lt;/li&gt;
&lt;li&gt;Tool call results feed back into context&lt;/li&gt;
&lt;li&gt;The previous turn's entire response rolls forward as history&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A typical agentic session on a mid-sized codebase can consume tens of thousands of input tokens per task, sometimes hundreds of thousands. The AI's response is a small fraction of that. The ratio is not 1:1. It's more like 50:1.&lt;/p&gt;

&lt;p&gt;Output compression approaches like CLAUDE.md instruction files are addressing 4% of a 50:1 problem.&lt;/p&gt;




&lt;h2&gt;
  
  
  What other tools in this space do
&lt;/h2&gt;

&lt;p&gt;Several tools target different slices of the input problem:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/rtk-ai/rtk" rel="noopener noreferrer"&gt;RTK&lt;/a&gt;&lt;/strong&gt; (70.4k GitHub stars) is a Rust CLI proxy that intercepts shell command output before it reaches the model. When the agent runs &lt;code&gt;git status&lt;/code&gt; or &lt;code&gt;cargo test&lt;/code&gt;, RTK rewrites the output into a compact form, stripping boilerplate, grouping related lines, truncating long logs. It claims 60-90% reduction on supported commands and covers 100+ commands across git, test runners, Docker, AWS, and more.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/cwinvestments/memstack" rel="noopener noreferrer"&gt;MemStack&lt;/a&gt;&lt;/strong&gt; is a structured skill framework for Claude Code with 125+ skills across free and Pro tiers. Skills load on demand and include session memory and project handoffs. It addresses a different problem: reloading the same project context from scratch at the start of every session.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/thedotmack/claude-mem" rel="noopener noreferrer"&gt;claude-mem&lt;/a&gt;&lt;/strong&gt; captures everything an agent does during a session, compresses it with AI, and injects relevant context back into future sessions. Persistent cross-session memory.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/ory/lumen" rel="noopener noreferrer"&gt;Lumen&lt;/a&gt;&lt;/strong&gt; by ORY applies local semantic search so the agent retrieves only the code fragments most relevant to the current query, rather than entire files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/chopratejas/headroom" rel="noopener noreferrer"&gt;Headroom&lt;/a&gt;&lt;/strong&gt; is an API proxy that applies general-purpose compression to the entire request payload before it leaves your machine.&lt;/p&gt;

&lt;p&gt;These tools are largely complementary. None of them address the core structural problem the same way: the codebase itself, loaded as raw text.&lt;/p&gt;




&lt;h2&gt;
  
  
  The structural problem: AST folding vs. loading raw files
&lt;/h2&gt;

&lt;p&gt;When an agent needs to understand a function, it typically reads the entire file containing that function. For a 500-line Go file with 12 functions, it might only need the signature, parameters, and return type of 11 of them, but it loads all 500 lines anyway.&lt;/p&gt;

&lt;p&gt;This is not a tooling problem. It's a representation problem. The agent has no way to ask for "just the structure" and can only read files.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;AST body-folding&lt;/strong&gt; changes the representation. Instead of loading the raw file, the codebase is indexed using its abstract syntax tree. Function bodies are replaced with fold markers, preserving:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Every function and method signature&lt;/li&gt;
&lt;li&gt;All type definitions and interfaces&lt;/li&gt;
&lt;li&gt;All imports and package structure&lt;/li&gt;
&lt;li&gt;All comments and docstrings&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The result is a structural view that lets the agent understand the architecture of a file at a fraction of the token cost. When the agent needs a specific function body to actually edit it, it requests that file uncompressed. Everything else stays folded.&lt;/p&gt;




&lt;h2&gt;
  
  
  The actual numbers, on a real codebase
&lt;/h2&gt;

&lt;p&gt;The Next.js monorepo is a useful benchmark because it's large, well-known, and representative of the TypeScript projects that most Cursor and Claude Code users work on.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Benchmark: vercel/next.js&lt;/strong&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Representation&lt;/th&gt;
&lt;th&gt;Tokens&lt;/th&gt;
&lt;th&gt;vs. raw&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Raw (all source files uncompressed)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;23,963,330&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;baseline&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Compressed (mcp-injector default)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;10,212,684&lt;/strong&gt;&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;-57.4%&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That's &lt;strong&gt;13.75 million tokens saved&lt;/strong&gt; per full codebase load.&lt;/p&gt;

&lt;p&gt;At current Claude Sonnet 5 pricing ($2.00/M for input tokens, with a 10% cache-hit multiplier for repeated context on the compressed representation), loading the raw Next.js codebase costs approximately &lt;strong&gt;$47.93&lt;/strong&gt;. With compression: approximately &lt;strong&gt;$2.04&lt;/strong&gt;. Difference: &lt;strong&gt;$45.88 saved&lt;/strong&gt; on a single full load.&lt;/p&gt;

&lt;p&gt;The benchmark data across other repositories (Django, Spring, Tokio, Gin, Redis, cURL, and more) is available at &lt;a href="https://foldwork.dev/benchmarks" rel="noopener noreferrer"&gt;foldwork.dev/benchmarks&lt;/a&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  The objection you're already thinking of
&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;"But mcp-injector is itself an MCP server. Doesn't installing it add to the same token overhead it claims to reduce?"&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Yes, and it's worth being precise about this.&lt;/p&gt;

&lt;p&gt;An MCP server adds its tool definitions to every message. mcp-injector has 5 tools. Those definitions cost a few thousand tokens of fixed overhead per message.&lt;/p&gt;

&lt;p&gt;From the Next.js benchmark: the tool saves &lt;strong&gt;13,750,646 tokens&lt;/strong&gt; per full codebase load. The fixed overhead of 5 tool definitions is in the low thousands.&lt;/p&gt;

&lt;p&gt;The overhead is real but it's roughly &lt;strong&gt;1,000-4,000x smaller&lt;/strong&gt; than the saving. It's not a close call.&lt;/p&gt;

&lt;p&gt;The concern about MCP server overhead is legitimate in the abstract. A commenter in the Hacker News thread raised exactly this point, noting that six MCP servers with 15-20 tools each can add 22,000+ tokens per message. That's a real problem. The answer is to be selective about which MCP servers you install, and to understand the fixed-overhead cost of each one relative to what it returns.&lt;/p&gt;




&lt;h2&gt;
  
  
  What this is and isn't
&lt;/h2&gt;

&lt;p&gt;AST folding is not a replacement for RTK, Lumen, Headroom, MemStack, or claude-mem. Shell output compression, semantic search, session memory, and API-level compression solve real problems that body folding doesn't touch. A well-configured setup could reasonably stack several of them.&lt;/p&gt;

&lt;p&gt;What AST folding is: a structural solution to a structural problem. The codebase is your biggest input source. Loading it as raw text is a choice, not a requirement.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;mcp-injector is available at &lt;a href="https://foldwork.dev" rel="noopener noreferrer"&gt;foldwork.dev&lt;/a&gt;. It works with Claude Desktop, Cursor, VS Code, Devin Desktop, and Antigravity. The Pro tier is $12/month or $99/year.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>claude</category>
      <category>ai</category>
      <category>programming</category>
      <category>mcp</category>
    </item>
  </channel>
</rss>
