<?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: Paul Irolla</title>
    <description>The latest articles on DEV Community by Paul Irolla (@paul_irolla_6b5ae261d0224).</description>
    <link>https://dev.to/paul_irolla_6b5ae261d0224</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%2F2183047%2Fc0c55e95-e0dd-4375-8123-478cede020d8.png</url>
      <title>DEV Community: Paul Irolla</title>
      <link>https://dev.to/paul_irolla_6b5ae261d0224</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/paul_irolla_6b5ae261d0224"/>
    <language>en</language>
    <item>
      <title>Claude Code /compact: What It Costs and What Survives</title>
      <dc:creator>Paul Irolla</dc:creator>
      <pubDate>Mon, 26 Oct 2026 05:29:37 +0000</pubDate>
      <link>https://dev.to/paul_irolla_6b5ae261d0224/claude-code-compact-what-it-costs-and-what-survives-2cfm</link>
      <guid>https://dev.to/paul_irolla_6b5ae261d0224/claude-code-compact-what-it-costs-and-what-survives-2cfm</guid>
      <description>&lt;p&gt;The same &lt;code&gt;/compact&lt;/code&gt; can cost you a few cents or a couple of dollars, and the context size does not decide which. The cache does. Anthropic's own &lt;a href="https://code.claude.com/docs/en/prompt-caching#compacting-the-conversation" rel="noopener noreferrer"&gt;prompt caching documentation for Claude Code&lt;/a&gt; says it plainly: to write the summary, Claude Code sends a separate request carrying your whole history, and "while the cache is warm, that request reads your prefix from the cache, so a mid-session &lt;code&gt;/compact&lt;/code&gt; costs a fraction of what the context size suggests". After a break longer than the cache lifetime, the same request "reprocesses the full history as uncached input". That is why &lt;code&gt;/compact&lt;/code&gt; costs the most right after you resume an old session.&lt;/p&gt;

&lt;p&gt;Most guides on Claude Code compaction stop at "it summarizes your conversation" and a rule of thumb for when to run it. This one puts the cost mechanics beside the survival rules, and names the alternatives, so you can tell which move is cheap at the moment you are about to make it.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;/compact&lt;/code&gt; sends one extra request containing your full conversation plus a summarization instruction. While the &lt;a href="https://tokenade.net/en/glossary/prompt-caching" rel="noopener noreferrer"&gt;prompt cache&lt;/a&gt; is warm it reads that history at cache price; once the cache has expired it pays full input price.&lt;/li&gt;
&lt;li&gt;The turn after compaction is cheap: it only rebuilds the cache for the short summary.&lt;/li&gt;
&lt;li&gt;CLAUDE.md, auto memory, the plan and a fresh git status come back from disk. Path-scoped rules, nested CLAUDE.md files and anything a hook injected earlier are summarized away.&lt;/li&gt;
&lt;li&gt;Auto-compact fires near the model's limit: around 967K tokens on 1M-window models, at 200K on 200K-window setups. &lt;code&gt;/autocompact&lt;/code&gt; moves that point.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/clear&lt;/code&gt; costs nothing, &lt;code&gt;/rewind&lt;/code&gt; reuses a cache that already exists, and &lt;code&gt;/recap&lt;/code&gt; summarizes without touching the cache. Pick &lt;code&gt;/compact&lt;/code&gt; when you need continuity and the cache is still warm.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What /compact actually does
&lt;/h2&gt;

&lt;p&gt;Compaction replaces your message history with a summary written by the model. Anthropic's &lt;a href="https://claude.com/blog/using-claude-code-session-management-and-1m-context" rel="noopener noreferrer"&gt;session management post&lt;/a&gt; (Thariq Shihipar, April 15, 2026) describes it as "lossy, but you didn't have to write anything yourself", and you can steer it with instructions such as &lt;code&gt;/compact focus on the auth refactor, drop the test debugging&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Mechanically, the &lt;a href="https://code.claude.com/docs/en/prompt-caching#compacting-the-conversation" rel="noopener noreferrer"&gt;prompt caching page&lt;/a&gt; lists four steps:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Claude Code sends a separate request with the same system prompt, tools and history as your conversation, with the summarization instruction appended as a final user message.&lt;/li&gt;
&lt;li&gt;The model writes the summary. As of v2.1.198 that request inherits your session's extended thinking setting, according to the &lt;a href="https://code.claude.com/docs/en/context-window#what-survives-compaction" rel="noopener noreferrer"&gt;context window page&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Claude Code swaps the history for the summary and reloads project context (CLAUDE.md, memory) from disk.&lt;/li&gt;
&lt;li&gt;Your next turn builds a new cache entry for the shorter history.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Two consequences follow. First, compaction invalidates the conversation layer of the cache by design, because the new history shares no prefix with the old one. The system prompt layer survives. Second, because CLAUDE.md is reloaded from disk, any edit you made to it mid-session takes effect at that point: the docs note that CLAUDE.md is "read once at session start" and that a new version "loads on the next &lt;code&gt;/clear&lt;/code&gt;, &lt;code&gt;/compact&lt;/code&gt;, or restart". If you edited CLAUDE.md since the session started, that reload is a cache miss on the project-context layer too.&lt;/p&gt;

&lt;p&gt;In a fresh session, &lt;code&gt;/compact&lt;/code&gt; does nothing useful. The &lt;a href="https://code.claude.com/docs/en/costs#manage-context-proactively" rel="noopener noreferrer"&gt;costs page&lt;/a&gt; says it prints &lt;code&gt;Not enough messages to compact.&lt;/code&gt; when there is no history to summarize.&lt;/p&gt;

&lt;p&gt;If you want the broader picture of why every turn re-sends the whole conversation, our explainer on &lt;a href="https://tokenade.net/en/articles/context-window-token-bill" rel="noopener noreferrer"&gt;how the context window drives your token bill&lt;/a&gt; covers the base mechanism this section builds on.&lt;/p&gt;

&lt;h2&gt;
  
  
  What compaction costs: warm cache vs cold cache
&lt;/h2&gt;

&lt;p&gt;The number that matters is not your context size. It is whether the cached prefix is still alive when the summarization request goes out.&lt;/p&gt;

&lt;p&gt;Cache lifetime depends on how you pay. The &lt;a href="https://code.claude.com/docs/en/prompt-caching#which-ttl-each-request-gets" rel="noopener noreferrer"&gt;TTL table in the Claude Code docs&lt;/a&gt; splits requests into two buckets:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Request bucket&lt;/th&gt;
&lt;th&gt;Claude subscription, within plan usage&lt;/th&gt;
&lt;th&gt;Usage credits, API key, or cloud provider&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Main conversation&lt;/td&gt;
&lt;td&gt;One hour&lt;/td&gt;
&lt;td&gt;Five minutes&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Everything else (subagents, forks, compaction, titles)&lt;/td&gt;
&lt;td&gt;Five minutes, except some server-controlled helpers&lt;/td&gt;
&lt;td&gt;Five minutes&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Compaction sits in the second bucket, but the docs specify that the summarization call uses the same prefix-sharing approach as subagents, so it reads the cache your main conversation built. What decides whether that cache exists is how long you have been idle: under an hour on a subscription, under five minutes on an API key.&lt;/p&gt;

&lt;p&gt;Here is what that means in dollars, using Anthropic's &lt;a href="https://platform.claude.com/docs/en/build-with-claude/prompt-caching#pricing" rel="noopener noreferrer"&gt;published prompt caching prices&lt;/a&gt; for Claude Opus 5.5 as of October 1, 2026: $4 per million input tokens, $0.20 per million for cache hits, $5 and $8 per million for 5-minute and 1-hour cache writes. This is arithmetic on list prices, not a measured bill, and it leaves out the output tokens of the summary itself.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;400K tokens of history, warm cache:&lt;/strong&gt; 400,000 × $0.20 / 1M = &lt;strong&gt;$0.08&lt;/strong&gt; of input for the summarization request.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;400K tokens of history, cold cache:&lt;/strong&gt; 400,000 × $4 / 1M = &lt;strong&gt;$1.60&lt;/strong&gt; of input, twenty times more for the same command.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;On Sonnet 5.5 ($2 input, $0.20 cache hit per million on the same page), the same cold compaction costs $0.80 of input and the warm one stays at $0.08. The gap between warm and cold is a ratio of input price to cache-hit price, so it widens on the more expensive models.&lt;/p&gt;

&lt;p&gt;On a Pro or Max plan you do not see dollars, but the same tokens count against your limits. The &lt;a href="https://code.claude.com/docs/en/costs#why-usage-climbs-in-a-long-session" rel="noopener noreferrer"&gt;costs page&lt;/a&gt; lists compaction among the reasons usage climbs in a long session: "&lt;code&gt;/compact&lt;/code&gt; reads the conversation it summarizes, so compacting a large context is itself a large request." For the plan side of this, see &lt;a href="https://tokenade.net/en/articles/claude-usage-limits-explained" rel="noopener noreferrer"&gt;how Claude usage limits work&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The practical rule that falls out: compact while you are still working, not after lunch. If you come back to a large session after the cache has expired, Claude Code on Pro or Max offers to &lt;a href="https://code.claude.com/docs/en/prompt-caching#cache-lifetime" rel="noopener noreferrer"&gt;resume from a summary&lt;/a&gt;, which is the same trade made at the cheapest available moment.&lt;/p&gt;

&lt;h2&gt;
  
  
  What survives compaction, and what quietly disappears
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://code.claude.com/docs/en/context-window#what-survives-compaction" rel="noopener noreferrer"&gt;context window documentation&lt;/a&gt; gives a per-mechanism table. Condensed:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Kept or restored&lt;/th&gt;
&lt;th&gt;Lost into the summary&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;System prompt and output style&lt;/td&gt;
&lt;td&gt;Path-scoped rules (&lt;code&gt;paths:&lt;/code&gt; frontmatter) until a matching file is read again&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Project-root CLAUDE.md and unscoped rules, re-read from disk&lt;/td&gt;
&lt;td&gt;Nested CLAUDE.md files in subdirectories, same condition&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Auto memory, re-read from disk&lt;/td&gt;
&lt;td&gt;Context that hooks injected earlier&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;The plan written in plan mode, re-read from disk&lt;/td&gt;
&lt;td&gt;Everything else in the conversation not captured by the summary&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;A fresh git status snapshot&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Up to five recently modified files Claude read or edited&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Invoked skill bodies, capped at 5,000 tokens each and 25,000 in total&lt;/td&gt;
&lt;td&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Three details in that table cause most of the "Claude forgot X after compaction" reports.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Files over 5,000 tokens come back as a path only.&lt;/strong&gt; Claude Code re-reads up to five files, most recently modified first, but a large file returns as &lt;code&gt;Referenced file&lt;/code&gt; without its content. If the model needs that file, it reads it again, and you pay for the read again. Our guide to &lt;a href="https://tokenade.net/en/articles/skeleton-compression-file-reads" rel="noopener noreferrer"&gt;skeleton compression for file reads&lt;/a&gt; covers ways to make those re-reads smaller.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Skills get truncated from the bottom.&lt;/strong&gt; Truncation keeps the start of &lt;code&gt;SKILL.md&lt;/code&gt;, and the oldest invoked skills drop first once the 25,000-token budget is exceeded. The docs advise putting the most important instructions near the top of the file. More on what skills cost in context in &lt;a href="https://tokenade.net/en/articles/claude-code-skills" rel="noopener noreferrer"&gt;Claude Code skills: what they are, what they cost&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Rules scoped to paths vanish until triggered again.&lt;/strong&gt; A rule with &lt;code&gt;paths:&lt;/code&gt; frontmatter loads into message history when its trigger file is read, so compaction summarizes it away. If a rule must hold for the whole session, the docs say to drop the &lt;code&gt;paths:&lt;/code&gt; frontmatter or move it to the project-root CLAUDE.md. That moves its tokens into every turn, so it is a trade worth making only for rules that matter. &lt;a href="https://tokenade.net/en/articles/claude-md-token-bloat" rel="noopener noreferrer"&gt;How a bloated CLAUDE.md inflates your bill&lt;/a&gt; shows what that trade costs.&lt;/p&gt;

&lt;h2&gt;
  
  
  When auto-compact fires
&lt;/h2&gt;

&lt;p&gt;Auto-compact is the same pass as &lt;code&gt;/compact&lt;/code&gt;, triggered for you. The &lt;a href="https://code.claude.com/docs/en/model-config#default-auto-compact-thresholds" rel="noopener noreferrer"&gt;model configuration page&lt;/a&gt; lists the defaults:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Models running with a native 1M window compact "at about 967K tokens by default". On the Anthropic API that covers Sonnet 5, the Fable models and Opus 4.7 and later.&lt;/li&gt;
&lt;li&gt;Sonnet 4.6 and Opus 4.6 without extended context compact at the 200K boundary, as do Opus 4.8 and later when they run with a 200K window on Bedrock, Google Cloud or Foundry.&lt;/li&gt;
&lt;li&gt;Setting &lt;code&gt;CLAUDE_CODE_DISABLE_1M_CONTEXT=1&lt;/code&gt; holds 1M models to 200K, and they compact there.&lt;/li&gt;
&lt;li&gt;An unrecognized model ID, such as a gateway alias, compacts at the window Claude Code assumes for it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can move the trigger with &lt;code&gt;/autocompact 500k&lt;/code&gt; (saved to your user settings as &lt;code&gt;autoCompactWindow&lt;/code&gt;), with the &lt;code&gt;--autocompact&lt;/code&gt; flag for a single launch, or with the &lt;code&gt;CLAUDE_CODE_AUTO_COMPACT_WINDOW&lt;/code&gt; environment variable, which overrides both. The command and flag accept 100K to 1M tokens.&lt;/p&gt;

&lt;p&gt;Waiting for the default has a quality cost on top of the token cost. The Anthropic post on session management puts it this way: "due to context rot, the model is at its least intelligent point when compacting." It also explains bad compactions: they happen "when the model can't predict the direction your work is going", for example when a long debugging session gets summarized and your next message asks about a warning the summary dropped. Our glossary entry on &lt;a href="https://tokenade.net/en/glossary/context-rot" rel="noopener noreferrer"&gt;context rot&lt;/a&gt; covers the underlying effect.&lt;/p&gt;

&lt;p&gt;There is also a timing cost. Auto-compact fires mid-task, wherever the threshold falls. The &lt;a href="https://code.claude.com/docs/en/prompt-caching#compacting-the-conversation" rel="noopener noreferrer"&gt;prompt caching page&lt;/a&gt; recommends running &lt;code&gt;/compact&lt;/code&gt; "at a natural break in your work, such as between tasks, instead of waiting for auto-compaction to trigger mid-task", so you choose when the overhead lands.&lt;/p&gt;

&lt;h2&gt;
  
  
  /compact, /clear, /rewind, /recap: which one, when
&lt;/h2&gt;

&lt;p&gt;Four commands shrink or reshape what the model sees. They differ in cost and in what they keep.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;/clear&lt;/code&gt;&lt;/strong&gt; starts a new conversation. The &lt;a href="https://code.claude.com/docs/en/costs#why-usage-climbs-in-a-long-session" rel="noopener noreferrer"&gt;costs page&lt;/a&gt; is direct: "When you want a fresh start instead of continuity, &lt;code&gt;/clear&lt;/code&gt; costs nothing." The price is effort: you write the brief yourself ("we're refactoring the auth middleware, the constraint is X, the files that matter are A and B"), and the model starts from what you decided was relevant. Anthropic's rule of thumb is that a new task deserves a new session.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;/rewind&lt;/code&gt;&lt;/strong&gt; (double Esc) truncates back to an earlier turn. Because "the remaining history is the same content the cache was built from at that point", the next request &lt;a href="https://code.claude.com/docs/en/prompt-caching#rewinding-the-conversation" rel="noopener noreferrer"&gt;hits the earlier cache entry&lt;/a&gt;. Use it when Claude went down a wrong path: keep the useful file reads, drop the failed attempt, re-prompt with what you learned. &lt;code&gt;/rewind&lt;/code&gt; also offers "Summarize from here" and "Summarize up to here" to compact part of the conversation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;/recap&lt;/code&gt;&lt;/strong&gt; generates a summary for display in your terminal. Unlike &lt;code&gt;/compact&lt;/code&gt;, it &lt;a href="https://code.claude.com/docs/en/prompt-caching#running-%2Frecap" rel="noopener noreferrer"&gt;appends the summary as command output&lt;/a&gt; rather than replacing your history, so the cached prefix stays intact. It reorients you; it does not free any context.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;/compact&lt;/code&gt;&lt;/strong&gt; keeps continuity without you writing anything. It is the right call mid-task when the session is full of stale exploration you will not need again, and the cache is still warm.&lt;/p&gt;

&lt;p&gt;A fifth option prevents the problem: send work that produces a lot of throwaway output to a subagent, so the file reads stay in its context window and only the result comes back. Anthropic's test is "will I need this tool output again, or just the conclusion?" Subagents have their own startup cost; &lt;a href="https://tokenade.net/en/articles/measure-agent-token-usage" rel="noopener noreferrer"&gt;measuring AI agent token usage&lt;/a&gt; explains how to check whether delegation paid off in your session.&lt;/p&gt;

&lt;h2&gt;
  
  
  Steering what the summary keeps
&lt;/h2&gt;

&lt;p&gt;You have three levers on the summary's content, all documented.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Instructions on the command line.&lt;/strong&gt; &lt;code&gt;/compact Focus on code samples and API usage&lt;/code&gt; tells Claude what to preserve. The &lt;a href="https://code.claude.com/docs/en/costs#manage-context-proactively" rel="noopener noreferrer"&gt;costs page&lt;/a&gt; uses this exact example.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A standing section in CLAUDE.md.&lt;/strong&gt; The same page shows a &lt;code&gt;# Compact instructions&lt;/code&gt; heading in the project-root CLAUDE.md, for example "When you are using compact, please focus on test output and code changes". Since project-root CLAUDE.md is re-injected after every compaction, these instructions stay available for every summary.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A SessionStart hook on the &lt;code&gt;compact&lt;/code&gt; source.&lt;/strong&gt; The &lt;a href="https://code.claude.com/docs/en/hooks-guide#re-inject-context-after-compaction" rel="noopener noreferrer"&gt;hooks guide&lt;/a&gt; shows a &lt;code&gt;SessionStart&lt;/code&gt; hook with &lt;code&gt;"matcher": "compact"&lt;/code&gt; whose stdout is added to the compacted context:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"SessionStart"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"matcher"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"compact"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"hooks"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"command"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"git log --oneline -5"&lt;/span&gt;&lt;span class="w"&gt;
          &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The guide suggests &lt;code&gt;git log --oneline -5&lt;/code&gt; as a dynamic replacement for a static &lt;code&gt;echo&lt;/code&gt;. Whatever this hook prints, you pay for it on every turn until the next compaction, so keep it short. &lt;code&gt;PreCompact&lt;/code&gt; and &lt;code&gt;PostCompact&lt;/code&gt; hooks also exist, with &lt;code&gt;manual&lt;/code&gt; and &lt;code&gt;auto&lt;/code&gt; matchers, if you want to log or react to each compaction. Hooks are one of several levers listed in our guide to &lt;a href="https://tokenade.net/en/articles/reduce-claude-code-token-usage" rel="noopener noreferrer"&gt;reducing Claude Code token usage&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measuring what compaction did to your session
&lt;/h2&gt;

&lt;p&gt;Claude Code reports cache behaviour directly. Since v2.1.251, &lt;code&gt;/usage&lt;/code&gt; adds a &lt;code&gt;Prompt cache (main)&lt;/code&gt; line with the request count, the share of input served from cache, misses, and "expected rebuilds", which the &lt;a href="https://code.claude.com/docs/en/costs#prompt-cache-statistics" rel="noopener noreferrer"&gt;costs page&lt;/a&gt; defines as misses caused by Claude Code itself rewriting the conversation "by compaction or by clearing old tool results". The example line in the docs reads &lt;code&gt;1 expected rebuild (compaction or tool-result clearing)&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;On a Pro, Max, Team or Enterprise plan, the &lt;code&gt;/usage&lt;/code&gt; breakdown also flags behaviours such as long context or cache misses when one accounts for 10% or more of recent usage. If compaction keeps showing up there, the fix is usually timing (compact earlier, while warm) or scope (clear between tasks).&lt;/p&gt;

&lt;p&gt;&lt;code&gt;/context&lt;/code&gt; gives a live breakdown of what fills the window by category, including which CLAUDE.md and memory files loaded, per the &lt;a href="https://code.claude.com/docs/en/context-window#check-your-own-session" rel="noopener noreferrer"&gt;context window page&lt;/a&gt;. Run it before and after a compaction to see what came back. For a tool-independent way to count tokens across sessions, see &lt;a href="https://tokenade.net/en/articles/measure-agent-token-usage" rel="noopener noreferrer"&gt;how to measure AI agent token usage&lt;/a&gt; and our &lt;a href="https://tokenade.net/en/stats/claude-code-token-usage-statistics" rel="noopener noreferrer"&gt;Claude Code token usage statistics&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Compacting right after resuming an old session.&lt;/strong&gt; The cache has expired, so the summarization request pays full input on the whole history. Use the "resume from a summary" offer on Pro or Max, or &lt;code&gt;/clear&lt;/code&gt; with a short brief.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Using &lt;code&gt;/compact&lt;/code&gt; to switch tasks.&lt;/strong&gt; You pay for a summary of work you no longer need, and the summary carries it into the new task. &lt;code&gt;/clear&lt;/code&gt; is free and cleaner.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Correcting a failed attempt instead of rewinding.&lt;/strong&gt; "That didn't work, try X" keeps the failed attempt in context. &lt;code&gt;/rewind&lt;/code&gt; drops it and hits a cache that already exists.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Relying on path-scoped rules across a long session.&lt;/strong&gt; They disappear at compaction until a matching file is read again. Move critical ones to the project-root CLAUDE.md.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Burying key instructions at the bottom of a skill.&lt;/strong&gt; Re-injected skills are truncated from the end once they pass 5,000 tokens.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Letting auto-compact pick the moment.&lt;/strong&gt; It fires mid-task, when context rot is at its worst, and summarizes without knowing where you are going next.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What to do this week
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Add a &lt;code&gt;# Compact instructions&lt;/code&gt; section to your project-root CLAUDE.md.&lt;/strong&gt; Two lines naming what the summary must keep in this repo (test output, the files under active change). Expected result: fewer "it forgot X" moments after auto-compact, at a few dozen tokens per turn.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lower your auto-compact window if you work on a 1M model.&lt;/strong&gt; &lt;code&gt;/autocompact 500k&lt;/code&gt; is the example the docs use. Expected result: compaction runs earlier, on a smaller and less rotted context, so the summarization request is cheaper and better.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run &lt;code&gt;/usage&lt;/code&gt; at the end of a long session.&lt;/strong&gt; Look at the &lt;code&gt;Prompt cache (main)&lt;/code&gt; line: misses versus expected rebuilds. If misses dominate, the cache is expiring between your turns; compact before breaks, not after.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make &lt;code&gt;/clear&lt;/code&gt; your default between tasks.&lt;/strong&gt; Keep &lt;code&gt;/compact&lt;/code&gt; for mid-task cleanup while the cache is warm, and &lt;code&gt;/rewind&lt;/code&gt; for dead ends.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What does /compact do in Claude Code?&lt;/strong&gt; It replaces your conversation history with a summary the model writes. Claude Code sends a separate request with your full history and a summarization instruction, swaps the history for the result, then reloads CLAUDE.md, auto memory, the plan and a fresh git status from disk. Up to five recently modified files are re-read, and invoked skills are re-injected within a 5,000-token-per-skill and 25,000-token total budget, per the &lt;a href="https://code.claude.com/docs/en/context-window#what-survives-compaction" rel="noopener noreferrer"&gt;context window docs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does /compact cost tokens?&lt;/strong&gt; Yes. The summarization request carries your whole conversation. While the cache is warm it reads that history at cache-hit price, which on Opus 5.5 is $0.20 per million tokens against $4 for uncached input (&lt;a href="https://platform.claude.com/docs/en/build-with-claude/prompt-caching#pricing" rel="noopener noreferrer"&gt;pricing as of October 1, 2026&lt;/a&gt;). After the cache expires, it pays full input price on the whole history. The summary's output tokens come on top.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is /clear cheaper than /compact?&lt;/strong&gt; Yes. The &lt;a href="https://code.claude.com/docs/en/costs#why-usage-climbs-in-a-long-session" rel="noopener noreferrer"&gt;costs page&lt;/a&gt; states that &lt;code&gt;/clear&lt;/code&gt; costs nothing. The trade-off is continuity: you write the brief for the next session yourself, while &lt;code&gt;/compact&lt;/code&gt; writes it for you. For unrelated work, &lt;code&gt;/clear&lt;/code&gt; is the better choice on both cost and quality.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When does auto-compact trigger?&lt;/strong&gt; On models with a native 1M window, at about 967K tokens by default. On 200K-window setups, at the 200K boundary. An unrecognized model ID compacts at the window Claude Code assumes for it. You can change the point with &lt;code&gt;/autocompact&lt;/code&gt;, the &lt;code&gt;--autocompact&lt;/code&gt; flag or &lt;code&gt;CLAUDE_CODE_AUTO_COMPACT_WINDOW&lt;/code&gt;, between 100K and 1M tokens (&lt;a href="https://code.claude.com/docs/en/model-config#set-the-auto-compact-window" rel="noopener noreferrer"&gt;model configuration docs&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why did Claude forget something after compaction?&lt;/strong&gt; Either the summary dropped it, or it came from a mechanism that does not survive: path-scoped rules, nested CLAUDE.md files, context injected by hooks, or the content of a file over 5,000 tokens. Anthropic notes that bad compactions happen when the model cannot predict where the work is going, so passing instructions to &lt;code&gt;/compact&lt;/code&gt; helps.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does editing CLAUDE.md mid-session take effect after /compact?&lt;/strong&gt; Yes. Project-root and user-level CLAUDE.md files are read once at session start and held in memory; a new version loads on the next &lt;code&gt;/clear&lt;/code&gt;, &lt;code&gt;/compact&lt;/code&gt; or restart, according to the &lt;a href="https://code.claude.com/docs/en/prompt-caching#editing-claude-md-mid-session" rel="noopener noreferrer"&gt;prompt caching docs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can I keep important context across compactions?&lt;/strong&gt; Put it in the project-root CLAUDE.md (re-read from disk every time), in a &lt;code&gt;# Compact instructions&lt;/code&gt; section, or in a &lt;code&gt;SessionStart&lt;/code&gt; hook with the &lt;code&gt;compact&lt;/code&gt; matcher, whose output is added after each compaction. Each of these adds tokens to every turn, so keep them short.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is the difference between /compact and /recap?&lt;/strong&gt; &lt;code&gt;/compact&lt;/code&gt; replaces your history with a summary and frees context. &lt;code&gt;/recap&lt;/code&gt; prints a summary in your terminal and appends it as command output, leaving the history and the cached prefix untouched. Use &lt;code&gt;/recap&lt;/code&gt; to reorient, &lt;code&gt;/compact&lt;/code&gt; to make room.&lt;/p&gt;

&lt;h2&gt;
  
  
  Related reads
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://tokenade.net/en/articles/reduce-tokens-long-sessions" rel="noopener noreferrer"&gt;How to Reduce Tokens on Long Agent Sessions&lt;/a&gt;: the session-level habits compaction belongs to.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tokenade.net/en/articles/prompt-caching-cut-input-cost" rel="noopener noreferrer"&gt;Prompt Caching: How to Cut Your Input Bill&lt;/a&gt;: why the warm/cold gap exists in the first place.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tokenade.net/en/articles/claude-code-token-limit" rel="noopener noreferrer"&gt;Claude Code Limits: How to Stay Under Them&lt;/a&gt;: where compaction fits when you are close to a plan limit.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tokenade.net/en/articles/claude-md-token-bloat" rel="noopener noreferrer"&gt;CLAUDE.md: How a Bloated File Inflates Your Bill&lt;/a&gt;: the cost of moving rules into the file that survives compaction.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tokenade.net/en/articles/reduce-claude-code-token-usage" rel="noopener noreferrer"&gt;How to Reduce Claude Code Token Usage&lt;/a&gt;: the full list of levers beyond compaction.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tokenade.net/en/glossary/context-rot" rel="noopener noreferrer"&gt;Context Rot&lt;/a&gt;: why a late compaction produces a worse summary.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tokenade.net/en/stats/prompt-caching-savings-data" rel="noopener noreferrer"&gt;Prompt Caching Savings: The Real Numbers&lt;/a&gt;: measured cache hit rates to compare against your &lt;code&gt;/usage&lt;/code&gt; line.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Tokenade is free and open source: &lt;a href="https://github.com/pi-infected/tokenade" rel="noopener noreferrer"&gt;https://github.com/pi-infected/tokenade&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>claude</category>
      <category>llm</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Claude Code Hooks: Which Ones Add Tokens, Which Cut Them</title>
      <dc:creator>Paul Irolla</dc:creator>
      <pubDate>Mon, 26 Oct 2026 01:00:05 +0000</pubDate>
      <link>https://dev.to/paul_irolla_6b5ae261d0224/claude-code-hooks-which-ones-add-tokens-which-cut-them-dpc</link>
      <guid>https://dev.to/paul_irolla_6b5ae261d0224/claude-code-hooks-which-ones-add-tokens-which-cut-them-dpc</guid>
      <description>&lt;p&gt;The Claude Code hooks reference now lists 33 events, from &lt;code&gt;SessionStart&lt;/code&gt; to &lt;code&gt;ElicitationResult&lt;/code&gt; (&lt;a href="https://code.claude.com/docs/en/hooks" rel="noopener noreferrer"&gt;Anthropic hooks reference&lt;/a&gt;, read 2026-09-24). Most people meet hooks through a list of ten copy-paste examples: a linter after every edit, a desktop ping, a guard on &lt;code&gt;rm -rf&lt;/code&gt;. Then they read that a hook cut someone's token usage by 42% or 90% and wonder whether their own hooks help or hurt. Both happen. A hook that prints to stdout on &lt;code&gt;UserPromptSubmit&lt;/code&gt; adds its text to the conversation on every prompt you send. A hook that rewrites a tool call before it runs can stop a 3,000-line log from ever reaching the model. The difference sits in two details the example lists skip: which event the hook listens to, and which JSON field it returns. This article maps every token-relevant event to what it adds or removes, using only the official reference, and lists the traps that leave a hook silently doing nothing.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Four events add plain stdout to Claude's context: &lt;code&gt;UserPromptSubmit&lt;/code&gt;, &lt;code&gt;UserPromptExpansion&lt;/code&gt;, &lt;code&gt;SessionStart&lt;/code&gt; and &lt;code&gt;PostModelSwitch&lt;/code&gt;. On every other event, stdout from a successful hook goes to the debug log and costs nothing.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;additionalContext&lt;/code&gt; is a token cost by design: Claude Code wraps it in a system reminder and inserts it where the hook fired, and it stays in the conversation after that.&lt;/li&gt;
&lt;li&gt;Two fields remove tokens: &lt;code&gt;updatedInput&lt;/code&gt; on &lt;code&gt;PreToolUse&lt;/code&gt; (rewrite the call before it runs) and &lt;code&gt;updatedToolOutput&lt;/code&gt; on &lt;code&gt;PostToolUse&lt;/code&gt; (replace the result before Claude reads it).&lt;/li&gt;
&lt;li&gt;Every injected string is capped at 10,000 characters; past that, Claude gets a file path and a 2,000-character preview.&lt;/li&gt;
&lt;li&gt;Exit 1 does not block, a timed-out &lt;code&gt;PreToolUse&lt;/code&gt; hook lets the call through, and a mistyped script path disables a gate without stopping anything.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What a hook is, in cost terms
&lt;/h2&gt;

&lt;p&gt;A hook is a handler that Claude Code runs at a fixed point of a session: a shell command, an HTTP endpoint, a tool on a connected MCP server, an LLM prompt or a subagent (&lt;a href="https://code.claude.com/docs/en/hooks" rel="noopener noreferrer"&gt;reference&lt;/a&gt;). The reference groups the events by cadence. &lt;code&gt;SessionStart&lt;/code&gt; and &lt;code&gt;SessionEnd&lt;/code&gt; fire once per session. &lt;code&gt;UserPromptSubmit&lt;/code&gt;, &lt;code&gt;Stop&lt;/code&gt; and &lt;code&gt;StopFailure&lt;/code&gt; fire once per turn. &lt;code&gt;PreToolUse&lt;/code&gt; and &lt;code&gt;PostToolUse&lt;/code&gt; fire on every tool call inside the agentic loop, so their count grows with every file read, search and command the agent runs.&lt;/p&gt;

&lt;p&gt;That cadence is the first half of the cost question. A handler that fires once per session and injects 400 characters costs you those characters once, plus their re-reading on each later request. The same 400 characters on &lt;code&gt;PreToolUse&lt;/code&gt; land next to every tool result in the session. Anything that enters the conversation is re-sent with the rest of the history on each following model request, which is why &lt;a href="https://tokenade.net/en/articles/prompt-caching-cut-input-cost" rel="noopener noreferrer"&gt;prompt caching&lt;/a&gt; matters so much for agents: cached re-reads are cheaper than fresh input, but they are never free.&lt;/p&gt;

&lt;p&gt;The second half is what the handler returns. A hook can do four things with tokens:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Nothing. It runs, exits 0, and its stdout goes to the debug log. Most formatting, notification and logging hooks live here, and they have zero token cost.&lt;/li&gt;
&lt;li&gt;Add context: plain stdout on the four events that accept it, or &lt;code&gt;additionalContext&lt;/code&gt; in JSON.&lt;/li&gt;
&lt;li&gt;Remove context before it exists: rewrite a tool's arguments with &lt;code&gt;updatedInput&lt;/code&gt;, or replace its result with &lt;code&gt;updatedToolOutput&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Call a model: prompt-based and agent-based hooks send the hook input to Claude, which is a separate billed request.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The rest of this article sorts the events into those four buckets. If you have never measured where your session's tokens go, do that first; &lt;a href="https://tokenade.net/en/articles/measure-agent-token-usage" rel="noopener noreferrer"&gt;measuring agent token usage&lt;/a&gt; shows how to read the usage fields in the session transcript.&lt;/p&gt;

&lt;h2&gt;
  
  
  The hooks that add tokens
&lt;/h2&gt;

&lt;p&gt;Claude Code's rule for plain stdout is short. On exit 0, "for most events, Claude Code writes stdout to the debug log and doesn't show it in the transcript. The exceptions are &lt;code&gt;UserPromptSubmit&lt;/code&gt;, &lt;code&gt;UserPromptExpansion&lt;/code&gt;, &lt;code&gt;SessionStart&lt;/code&gt;, and &lt;code&gt;PostModelSwitch&lt;/code&gt;, where Claude Code adds plain-text stdout as context that Claude can see and act on" (&lt;a href="https://code.claude.com/docs/en/hooks#exit-code-0" rel="noopener noreferrer"&gt;reference, exit code 0&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;So an &lt;code&gt;echo&lt;/code&gt; in a &lt;code&gt;SessionStart&lt;/code&gt; hook is a small, one-time addition. The same &lt;code&gt;echo&lt;/code&gt; in a &lt;code&gt;UserPromptSubmit&lt;/code&gt; hook is an addition on every prompt. The reference also notes that neither plain stdout nor &lt;code&gt;additionalContext&lt;/code&gt; on &lt;code&gt;UserPromptSubmit&lt;/code&gt; produces a visible transcript entry: each is injected as a system reminder that starts with the hook's name. You pay for text you never see on screen, which is the most common way a hook setup grows a bill without anyone noticing.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;additionalContext&lt;/code&gt; is the structured version, and it works on more events. For &lt;code&gt;PreToolUse&lt;/code&gt; and &lt;code&gt;PostToolUse&lt;/code&gt; it is a "string added to Claude's context alongside the tool result." For &lt;code&gt;SessionStart&lt;/code&gt; it is added "at the start of the conversation, before the first prompt." For &lt;code&gt;SubagentStart&lt;/code&gt; and &lt;code&gt;PostModelSwitch&lt;/code&gt; it is the only thing the hook can do: context, with no blocking (&lt;a href="https://code.claude.com/docs/en/hooks#decision-control" rel="noopener noreferrer"&gt;reference, decision control&lt;/a&gt;). When several hooks return &lt;code&gt;additionalContext&lt;/code&gt; for the same event, Claude receives all of the values.&lt;/p&gt;

&lt;p&gt;A third path is less obvious. On &lt;code&gt;PostToolUse&lt;/code&gt; and &lt;code&gt;PostToolUseFailure&lt;/code&gt;, exiting 2 "shows stderr to Claude; the tool already ran." The reference recommends it as the way to surface a warning from those events. Every warning is text in the conversation, so a linter hook that exits 2 with 80 lines of findings on each edit adds 80 lines per edit.&lt;/p&gt;

&lt;p&gt;Stop hooks cost differently. Exit 2 on &lt;code&gt;Stop&lt;/code&gt; "prevents Claude from stopping, continues the conversation." That is a whole new model turn, with the full history re-sent. A check that fails on every turn keeps the session going until you intervene. The prompt-based variant has a guard for that: when the model returns &lt;code&gt;impossible&lt;/code&gt; with &lt;code&gt;ok: false&lt;/code&gt;, Claude Code lets the turn end instead of feeding the reason back. Command hooks have no such guard; the loop is yours to bound.&lt;/p&gt;

&lt;p&gt;The pattern to keep: context injection is fine when the text is short, changes the model's next move, and fires at the lowest cadence that still does the job. A branch name and the open issue at &lt;code&gt;SessionStart&lt;/code&gt; pass that test. A 2,000-character style guide on every &lt;code&gt;UserPromptSubmit&lt;/code&gt; belongs in &lt;a href="https://tokenade.net/en/articles/claude-md-token-bloat" rel="noopener noreferrer"&gt;CLAUDE.md&lt;/a&gt;, where it is at least part of the cached prefix.&lt;/p&gt;

&lt;h2&gt;
  
  
  The hooks that cut tokens
&lt;/h2&gt;

&lt;p&gt;Two fields let a hook shrink what the model reads, and they act at opposite ends of a tool call.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;updatedInput&lt;/code&gt; on &lt;code&gt;PreToolUse&lt;/code&gt;&lt;/strong&gt; "modifies the tool's input parameters before execution. Replaces the entire input object, so include unchanged fields alongside modified ones" (&lt;a href="https://code.claude.com/docs/en/hooks#pretooluse-decision-control" rel="noopener noreferrer"&gt;reference, PreToolUse decision control&lt;/a&gt;). This is where most token-saving hooks work. A &lt;code&gt;Bash&lt;/code&gt; call to &lt;code&gt;npm test&lt;/code&gt; can be rewritten to pipe through a filter that keeps failures only; a &lt;code&gt;Read&lt;/code&gt; of a 5,000-line file can be narrowed with &lt;code&gt;offset&lt;/code&gt; and &lt;code&gt;limit&lt;/code&gt;; a &lt;code&gt;Grep&lt;/code&gt; without a path can be scoped to &lt;code&gt;src/&lt;/code&gt;. The model only ever reads the trimmed result, and nothing extra enters the context. Two details from the reference matter here. Permission rules are evaluated "against the input your hook returns, not the input Claude sent," so a rewrite cannot smuggle a command past a deny rule. And the replacement is whole-object: forget a field and the tool runs without it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;updatedToolOutput&lt;/code&gt; on &lt;code&gt;PostToolUse&lt;/code&gt;&lt;/strong&gt; "replaces the tool's output with the provided value before it is sent to Claude. The value must match the tool's output shape." The reference now recommends it over the older &lt;code&gt;updatedMCPToolOutput&lt;/code&gt;, which works on MCP tools only. This is the field to use when you cannot know in advance how large a result will be: let the call run, then keep the error lines of a build log, drop the progress bars, or cut a JSON response down to the keys the model needs. The reference example replaces a Bash result's &lt;code&gt;stdout&lt;/code&gt; with a redacted string, which shows the shape.&lt;/p&gt;

&lt;p&gt;Note what &lt;code&gt;decision: "block"&lt;/code&gt; on &lt;code&gt;PostToolUse&lt;/code&gt; does and does not do: it "adds the &lt;code&gt;reason&lt;/code&gt; next to the tool result. Claude still sees the original output; to replace it, use &lt;code&gt;updatedToolOutput&lt;/code&gt;." A blocking PostToolUse hook meant to hide a huge output adds text and removes nothing.&lt;/p&gt;

&lt;p&gt;The published results for this approach are single-team benchmarks, so read them as orders of magnitude. SitePoint reported on 2026-08-20 that Graft, a hook-based framework, cut mean token usage from 8,070 to 4,650 per task on its authors' internal SWE-bench Verified runs, a 42% drop (&lt;a href="https://www.sitepoint.com/graft-claude-code-hooks-token-optimization/" rel="noopener noreferrer"&gt;SitePoint&lt;/a&gt;). Spotify Engineering published an engineer's account in September 2026 titled "Portal by Spotify cut my Claude Code token usage by 90%," which argues that most of what a coding agent does is I/O, such as reading five files to answer a question about one method (&lt;a href="https://engineering.atspotify.com/2026/9/portal-by-spotify-cut-my-claude-code-token-usage-by-90" rel="noopener noreferrer"&gt;Spotify Engineering&lt;/a&gt;). Neither is a controlled test on your repository. The mechanism behind both is the one described above, and the general technique has its own page: &lt;a href="https://tokenade.net/en/articles/output-filtering-command-logs" rel="noopener noreferrer"&gt;output filtering for command logs&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The 10,000-character ceiling
&lt;/h2&gt;

&lt;p&gt;Every string a hook injects has a hard limit. The reference: "A hook's &lt;code&gt;additionalContext&lt;/code&gt;, &lt;code&gt;systemMessage&lt;/code&gt;, and &lt;code&gt;initialUserMessage&lt;/code&gt; strings, and its plain stdout, are capped at 10,000 characters." Each JSON field is measured separately, plain stdout is measured whole, and several hooks on one event are each measured on their own (&lt;a href="https://code.claude.com/docs/en/hooks#json-output" rel="noopener noreferrer"&gt;reference, JSON output&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Over the limit, Claude Code does not truncate. It "saves the output to a file in the session directory and replaces it with the file path and a preview of up to the first 2,000 characters." Claude can read that file, but Claude Code doesn't ask it to. Large valid Bash results are handled the same way. Unlike the Bash ceiling, the hook cap "has no setting or environment variable to raise it."&lt;/p&gt;

&lt;p&gt;Two consequences for cost:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The cap is a ceiling per string, and nothing stops you from sending 9,999 characters on every prompt. It protects against runaway hooks, and a hook that stays under it can still be the largest single item in your context.&lt;/li&gt;
&lt;li&gt;Crossing the cap can make things worse. If the model decides it needs the full text, it reads the file with a tool call, and you pay for the preview, the tool call and the full content.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If a hook regularly produces more than a few hundred characters, the better design is usually to write the details to a file yourself and inject one line pointing to it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Hooks that call a model
&lt;/h2&gt;

&lt;p&gt;Prompt-based hooks (&lt;code&gt;type: "prompt"&lt;/code&gt;) "send the hook input and your prompt to a Claude model, Haiku by default"; the &lt;code&gt;model&lt;/code&gt; field overrides it (&lt;a href="https://code.claude.com/docs/en/hooks#prompt-based-hooks" rel="noopener noreferrer"&gt;reference, prompt-based hooks&lt;/a&gt;). Agent-based hooks go further and run a subagent that can use tools before deciding. Both are billed requests on top of your main session.&lt;/p&gt;

&lt;p&gt;That changes the arithmetic for high-cadence events. A prompt hook on &lt;code&gt;Stop&lt;/code&gt; runs once per turn, which is usually tolerable. A prompt hook on &lt;code&gt;PreToolUse&lt;/code&gt; runs a model request for every tool call, and each one carries the hook input, including the full tool arguments. For a check that a regular expression or &lt;code&gt;jq&lt;/code&gt; can do, a command hook costs nothing in tokens and answers in milliseconds.&lt;/p&gt;

&lt;p&gt;Use prompt and agent hooks where judgment is the point: deciding whether a task is really finished before letting Claude stop, or whether a diff touches something a rule forbids. Keep them off the per-tool-call path unless you have measured the extra requests. &lt;a href="https://tokenade.net/en/articles/agentic-coding" rel="noopener noreferrer"&gt;Agentic coding costs&lt;/a&gt; follow the same logic: every fresh model context starts with its own overhead.&lt;/p&gt;

&lt;h2&gt;
  
  
  PreModelSwitch: the first native cost signal in a hook
&lt;/h2&gt;

&lt;p&gt;For a long time, the complaint in &lt;a href="https://github.com/anthropics/claude-code/issues/11008" rel="noopener noreferrer"&gt;GitHub issue #11008&lt;/a&gt;, opened in November 2025, held: hooks received no token or cost data, so a budget hook had to parse the transcript itself. &lt;code&gt;PreModelSwitch&lt;/code&gt; changes that for one expensive moment. Its input includes &lt;code&gt;context_tokens&lt;/code&gt; (the tokens the next request re-sends as its prompt), &lt;code&gt;prompt_cache_warm&lt;/code&gt;, &lt;code&gt;cache_ttl&lt;/code&gt;, and &lt;code&gt;estimated_cache_write_usd&lt;/code&gt;, the estimated cost of writing that context to the new model's cache (&lt;a href="https://code.claude.com/docs/en/hooks#premodelswitch-input" rel="noopener noreferrer"&gt;reference, PreModelSwitch input&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Why it matters: a model switch forfeits a warm prompt cache. The reference's own example shows a &lt;code&gt;/model opus&lt;/code&gt; request from a Sonnet 5 session with 182,340 context tokens and an estimated cache write of $1.14 at list price. A hook can return &lt;code&gt;permissionDecision: "ask"&lt;/code&gt; with that figure in the reason, so the switch happens with the price in front of you. The default timeout for this event is 30 seconds, and unlike &lt;code&gt;PreToolUse&lt;/code&gt;, a PreModelSwitch hook that times out blocks the switch.&lt;/p&gt;

&lt;p&gt;For every other event, the transcript remains the source. Each hook receives &lt;code&gt;transcript_path&lt;/code&gt;, and the reference warns that the file "is written asynchronously and may lag the in-memory conversation." A cost hook reading it should expect the latest turn to be missing. For per-session numbers without writing a hook, see &lt;a href="https://tokenade.net/en/articles/reduce-claude-code-token-usage" rel="noopener noreferrer"&gt;how to reduce Claude Code token usage&lt;/a&gt;, which covers the existing counters.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Using exit 1 to block.&lt;/strong&gt; "Without valid JSON on stdout, Claude Code treats exit code 1 as a non-blocking error and proceeds with the action." Policy hooks must exit 2, or return a JSON decision.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Trusting a slow gate.&lt;/strong&gt; A &lt;code&gt;command&lt;/code&gt;, &lt;code&gt;http&lt;/code&gt; or &lt;code&gt;mcp_tool&lt;/code&gt; hook on &lt;code&gt;PreToolUse&lt;/code&gt; that reaches its timeout "doesn't block the tool call." If your filter shells out to something slow, the unfiltered call goes through.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A typo in the script path.&lt;/strong&gt; The shell exits 127, Claude Code shows a non-blocking notice, and "a mistyped path in &lt;code&gt;settings.json&lt;/code&gt; leaves the gate silently disabled." Watch the first run.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Matching MCP tools with a bare prefix.&lt;/strong&gt; &lt;code&gt;mcp__memory&lt;/code&gt; is compared as an exact string and matches no tool; &lt;code&gt;mcp__memory__.*&lt;/code&gt; matches all of that server's tools.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Printing a banner from the shell profile.&lt;/strong&gt; Stdout must contain only the JSON object. A profile that echoes on startup breaks parsing, and the JSON fields are ignored.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Expecting &lt;code&gt;suppressOutput&lt;/code&gt; to save anything.&lt;/strong&gt; The reference says it "has no effect": Claude Code accepts the field and does not act on it. Successful hook stdout already stays out of the transcript on most events.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What to do this week
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;List your hooks by event.&lt;/strong&gt; Open &lt;code&gt;/hooks&lt;/code&gt; and write down every handler on &lt;code&gt;UserPromptSubmit&lt;/code&gt;, &lt;code&gt;SessionStart&lt;/code&gt;, &lt;code&gt;PreToolUse&lt;/code&gt; and &lt;code&gt;PostToolUse&lt;/code&gt;. For each, note whether it prints plain stdout, returns &lt;code&gt;additionalContext&lt;/code&gt;, or exits 2 with stderr. Those are your token-adding hooks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Move per-prompt text to a lower cadence.&lt;/strong&gt; Anything on &lt;code&gt;UserPromptSubmit&lt;/code&gt; that does not change between prompts goes to &lt;code&gt;SessionStart&lt;/code&gt; or to CLAUDE.md. Expected outcome: the same guidance, paid once instead of per prompt.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Add one output-shrinking hook to your noisiest tool.&lt;/strong&gt; Check the transcript for the tool whose results are largest (usually &lt;code&gt;Bash&lt;/code&gt; running tests or builds) and add a &lt;code&gt;PostToolUse&lt;/code&gt; hook that returns &lt;code&gt;updatedToolOutput&lt;/code&gt; with errors and the summary line only. Compare total input tokens over two similar sessions before and after.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make every policy hook exit 2 and test it.&lt;/strong&gt; Run one command it should block and confirm the block appears. A gate you have not seen fire is not a gate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Add a PreModelSwitch hook with &lt;code&gt;"ask"&lt;/code&gt;.&lt;/strong&gt; Quote &lt;code&gt;context_tokens&lt;/code&gt; and &lt;code&gt;estimated_cache_write_usd&lt;/code&gt; in the reason, so a mid-session model switch shows its price before it happens.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What are Claude Code hooks?&lt;/strong&gt; Hooks are handlers Claude Code runs automatically at fixed points of a session: before and after tool calls, when you submit a prompt, when a session starts or ends, before compaction, and about thirty other events. A handler can be a shell command, an HTTP endpoint, an MCP tool, an LLM prompt or a subagent. It receives the event as JSON (on stdin for commands) and can return a decision, extra context, or a rewritten tool input or output. You configure them in settings files or through the &lt;code&gt;/hooks&lt;/code&gt; menu.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do Claude Code hooks use tokens?&lt;/strong&gt; Only when their output enters the conversation or when they call a model. On most events, stdout from a successful hook goes to the debug log and costs nothing. Plain stdout on &lt;code&gt;UserPromptSubmit&lt;/code&gt;, &lt;code&gt;UserPromptExpansion&lt;/code&gt;, &lt;code&gt;SessionStart&lt;/code&gt; and &lt;code&gt;PostModelSwitch&lt;/code&gt; is added to context, &lt;code&gt;additionalContext&lt;/code&gt; is added wherever it is supported, and stderr from an exit-2 &lt;code&gt;PostToolUse&lt;/code&gt; hook is shown to Claude. Prompt and agent hooks are separate model requests, Haiku by default for prompt hooks.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can a hook reduce Claude Code token usage?&lt;/strong&gt; Yes, through two fields. &lt;code&gt;updatedInput&lt;/code&gt; on &lt;code&gt;PreToolUse&lt;/code&gt; rewrites a tool call before it runs, for example narrowing a file read or piping a test command through a filter. &lt;code&gt;updatedToolOutput&lt;/code&gt; on &lt;code&gt;PostToolUse&lt;/code&gt; replaces a tool's result before Claude reads it. Published results come from single-team benchmarks: SitePoint reported a 42% drop per task for Graft on its authors' own SWE-bench runs in August 2026. Measure on your own sessions before trusting a figure.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is the difference between PreToolUse and PostToolUse?&lt;/strong&gt; &lt;code&gt;PreToolUse&lt;/code&gt; fires before a tool call executes and can block it, ask for confirmation, or rewrite its arguments with &lt;code&gt;updatedInput&lt;/code&gt;. &lt;code&gt;PostToolUse&lt;/code&gt; fires after a call succeeds; it cannot undo the call, but it can add context, show a warning via exit 2, or replace the result with &lt;code&gt;updatedToolOutput&lt;/code&gt;. For token savings, &lt;code&gt;PreToolUse&lt;/code&gt; avoids producing a large output at all, and &lt;code&gt;PostToolUse&lt;/code&gt; handles output whose size you cannot predict.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why does my hook not block anything?&lt;/strong&gt; The usual causes are exit code 1 instead of 2, a script path that does not exist, a matcher that matches no tool (an MCP prefix without &lt;code&gt;.*&lt;/code&gt;), text printed before the JSON on stdout, or a &lt;code&gt;PreToolUse&lt;/code&gt; hook that timed out. The reference is explicit that a timed-out command hook on &lt;code&gt;PreToolUse&lt;/code&gt; lets the tool call continue. Enable debug logging to see the parse or validation message, and test each gate with a call it should stop.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is there a size limit on hook output?&lt;/strong&gt; Yes. &lt;code&gt;additionalContext&lt;/code&gt;, &lt;code&gt;systemMessage&lt;/code&gt;, &lt;code&gt;initialUserMessage&lt;/code&gt; and plain stdout are each capped at 10,000 characters. Above that, Claude Code writes the text to a file in the session directory and gives Claude the path plus a preview of up to 2,000 characters. No setting or environment variable raises this cap. The notes a hook attaches for the auto mode classifier have a separate 2,000-character cap per tool call.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can a hook see how many tokens the session has used?&lt;/strong&gt; Not directly on most events: GitHub issue #11008 asked for token and cost data in hook inputs. Every hook receives &lt;code&gt;transcript_path&lt;/code&gt;, and the transcript's usage fields can be summed, keeping in mind that the file is written asynchronously and may lag the latest turn. &lt;code&gt;PreModelSwitch&lt;/code&gt; is the exception: its input carries &lt;code&gt;context_tokens&lt;/code&gt; and &lt;code&gt;estimated_cache_write_usd&lt;/code&gt; for the switch it is about to allow or block.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Should I use prompt-based hooks?&lt;/strong&gt; Use them where a judgment call is the point, such as checking before &lt;code&gt;Stop&lt;/code&gt; whether the task is really done. Avoid them on &lt;code&gt;PreToolUse&lt;/code&gt; or &lt;code&gt;PostToolUse&lt;/code&gt; unless you have measured the cost, because they add one model request per tool call. Anything a regular expression, &lt;code&gt;jq&lt;/code&gt; or a short script can decide belongs in a command hook, which costs no tokens.&lt;/p&gt;

&lt;h2&gt;
  
  
  Related reads
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://tokenade.net/en/articles/output-filtering-command-logs" rel="noopener noreferrer"&gt;Output filtering for command logs&lt;/a&gt;: the technique most token-saving &lt;code&gt;PostToolUse&lt;/code&gt; hooks implement.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tokenade.net/en/articles/reduce-claude-code-token-usage" rel="noopener noreferrer"&gt;How to reduce Claude Code token usage&lt;/a&gt;: the wider list of levers, hooks included.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tokenade.net/en/articles/claude-md-token-bloat" rel="noopener noreferrer"&gt;CLAUDE.md token bloat&lt;/a&gt;: where static guidance belongs instead of a per-prompt hook.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tokenade.net/en/articles/prompt-caching-cut-input-cost" rel="noopener noreferrer"&gt;Prompt caching and your input bill&lt;/a&gt;: why injected context keeps costing after it lands.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tokenade.net/en/articles/measure-agent-token-usage" rel="noopener noreferrer"&gt;How to measure agent token usage&lt;/a&gt;: read the transcript before and after adding a hook.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tokenade.net/en/articles/claude-code-skills" rel="noopener noreferrer"&gt;Claude Code skills and their cost&lt;/a&gt;: the other way to load instructions only when needed.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tokenade.net/en/articles/lazy-mcp-loading" rel="noopener noreferrer"&gt;Lazy MCP loading&lt;/a&gt;: the same idle-cost problem, on the tool-definition side.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tokenade.net/en/articles/best-claude-code-token-optimizers" rel="noopener noreferrer"&gt;Best Claude Code token optimizers&lt;/a&gt;: tools that package these hooks for you.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Tokenade is free and open source: &lt;a href="https://github.com/pi-infected/tokenade" rel="noopener noreferrer"&gt;https://github.com/pi-infected/tokenade&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>claude</category>
      <category>llm</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Claude Code Subagents Token Usage: What They Really Cost</title>
      <dc:creator>Paul Irolla</dc:creator>
      <pubDate>Sun, 25 Oct 2026 01:00:06 +0000</pubDate>
      <link>https://dev.to/paul_irolla_6b5ae261d0224/claude-code-subagents-token-usage-what-they-really-cost-fp0</link>
      <guid>https://dev.to/paul_irolla_6b5ae261d0224/claude-code-subagents-token-usage-what-they-really-cost-fp0</guid>
      <description>&lt;p&gt;Search "Claude Code subagents token usage" and the first page argues with itself. One writer &lt;a href="https://www.makeuseof.com/claude-codes-grunt-work-to-subagents-reduce-token-billing-usage/" rel="noopener noreferrer"&gt;cut their usage billing by 40%&lt;/a&gt; by sending grunt work to subagents. Another watched Claude Code &lt;a href="https://dev.to/onlineeric/claude-code-sub-agents-burn-out-your-tokens-4cd8"&gt;spin up five subagents in parallel and hit the Pro limit in about 15 minutes&lt;/a&gt;. A third &lt;a href="https://aditlal.dev/tame-claude-tokens/" rel="noopener noreferrer"&gt;counted 66K to 84K tokens per subagent&lt;/a&gt; (July 18, 2026) before any code was written. All three can be right at once, because a subagent trades two costs against each other: a fixed startup bill it pays every time, and the context it keeps out of your main session. Which side wins depends on the task, and you can read both sides for your own sessions. In this article I show what a fresh subagent loads before it does anything, how to pull the real token count of each subagent out of the transcript files Claude Code already writes, and the rule I use to decide whether a task deserves one.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;A non-fork subagent starts with an empty conversation but a full startup payload: its own system prompt, the task message, your CLAUDE.md hierarchy (Explore and Plan skip it), git status and any preloaded skills (&lt;a href="https://code.claude.com/docs/en/sub-agents" rel="noopener noreferrer"&gt;Claude Code docs&lt;/a&gt;).&lt;/li&gt;
&lt;li&gt;That payload is written to the prompt cache from scratch. On one of my sessions in September 2026, 19 subagents each wrote between 12,427 and 40,763 tokens on their first request, with zero cache read.&lt;/li&gt;
&lt;li&gt;Per-subagent usage sits in &lt;code&gt;~/.claude/projects/&amp;lt;project&amp;gt;/&amp;lt;session&amp;gt;/subagents/agent-&amp;lt;id&amp;gt;.jsonl&lt;/code&gt;. Deduplicate by message ID before summing, or you will count the same request two or three times.&lt;/li&gt;
&lt;li&gt;Delegate when the work would pour far more tokens into your main context than the startup bill, and the result comes back as a short summary. Keep small, sequential edits in the main session.&lt;/li&gt;
&lt;li&gt;Forks (&lt;code&gt;/subtask&lt;/code&gt;) reuse the parent's prompt cache, so they cost less to start than a fresh subagent for work that needs the same context.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What a subagent is, in token terms
&lt;/h2&gt;

&lt;p&gt;The official definition is short. A subagent is "an isolated Claude instance with its own context window. It takes a task, does the work, and returns only the result," in Anthropic's &lt;a href="https://claude.com/blog/subagents-in-claude-code" rel="noopener noreferrer"&gt;guide to subagents&lt;/a&gt; (April 7, 2026). The same post is candid about the price: "subagents carry overhead. Each one spins up its own context, consumes tokens, and adds a layer of indirection between the developer and the work."&lt;/p&gt;

&lt;p&gt;For your bill, three consequences follow from "own context window."&lt;/p&gt;

&lt;p&gt;First, the subagent re-reads nothing from your conversation. The &lt;a href="https://code.claude.com/docs/en/sub-agents" rel="noopener noreferrer"&gt;docs on what loads at startup&lt;/a&gt; say it "doesn't see your conversation history, the skills you've already invoked, or the files Claude has already read." Claude writes a delegation message that summarizes the task, and the subagent starts from there. If the answer depends on something you established twenty turns ago, the subagent will either miss it or go find it again, and finding it again costs tokens.&lt;/p&gt;

&lt;p&gt;Second, everything the subagent reads stays in its own context. A grep that returns 3,000 lines, a test log, twelve files opened to find one function: the main session never sees them, only the summary. That is the saving people report, and it compounds, because every later turn of your main session re-sends the whole &lt;a href="https://tokenade.net/en/glossary/context-window" rel="noopener noreferrer"&gt;context window&lt;/a&gt; as input.&lt;/p&gt;

&lt;p&gt;Third, the subagent is a separate &lt;a href="https://tokenade.net/en/glossary/agent-loop" rel="noopener noreferrer"&gt;agent loop&lt;/a&gt; with its own turns. Each of its tool calls sends its growing context back to the model, exactly like the main session does. A subagent that wanders through forty tool calls is a small long session of its own.&lt;/p&gt;

&lt;p&gt;Anthropic's own numbers for multi-agent work set the scale. In its write-up of the &lt;a href="https://www.anthropic.com/engineering/multi-agent-research-system" rel="noopener noreferrer"&gt;Research multi-agent system&lt;/a&gt; (June 13, 2025), agents used about 4× more tokens than chat interactions and multi-agent systems about 15× more. The &lt;a href="https://code.claude.com/docs/en/costs" rel="noopener noreferrer"&gt;Claude Code cost docs&lt;/a&gt; give a similar warning for agent teams, which "use approximately 7x more tokens than standard sessions when teammates run in plan mode." Agent teams are a different, experimental feature from ordinary subagents, but the mechanism is the same: each instance keeps its own context.&lt;/p&gt;

&lt;h2&gt;
  
  
  The startup bill: what loads before the first tool call
&lt;/h2&gt;

&lt;p&gt;The docs list what a non-fork subagent's initial context contains. Here is that list with the part that matters for cost:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Loaded at start&lt;/th&gt;
&lt;th&gt;Size driver&lt;/th&gt;
&lt;th&gt;Who skips it&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;System prompt&lt;/td&gt;
&lt;td&gt;The agent's own prompt plus environment details Claude Code appends&lt;/td&gt;
&lt;td&gt;Nobody&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Task message&lt;/td&gt;
&lt;td&gt;The delegation prompt Claude writes&lt;/td&gt;
&lt;td&gt;Nobody&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;CLAUDE.md files&lt;/td&gt;
&lt;td&gt;Every level the main session loads, including &lt;code&gt;~/.claude/CLAUDE.md&lt;/code&gt; and project rules&lt;/td&gt;
&lt;td&gt;Explore and Plan; any agent with &lt;code&gt;omitClaudeMd: true&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Git status&lt;/td&gt;
&lt;td&gt;Snapshot taken at the start of the parent session&lt;/td&gt;
&lt;td&gt;Explore and Plan&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Preloaded skills&lt;/td&gt;
&lt;td&gt;Full content of skills named in the agent's &lt;code&gt;skills&lt;/code&gt; field&lt;/td&gt;
&lt;td&gt;Built-in agents&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Tool definitions&lt;/td&gt;
&lt;td&gt;The tools the agent is allowed to use, MCP tools included&lt;/td&gt;
&lt;td&gt;Restricted by &lt;code&gt;tools&lt;/code&gt; / &lt;code&gt;disallowedTools&lt;/code&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Source: &lt;a href="https://code.claude.com/docs/en/sub-agents" rel="noopener noreferrer"&gt;Create custom subagents, "What loads at startup"&lt;/a&gt;, read September 17, 2026. The tool definitions row is my addition: they are part of every request to the model, so a subagent that inherits forty MCP tools carries their schemas too.&lt;/p&gt;

&lt;p&gt;The line that surprises most people is CLAUDE.md. If your global and project CLAUDE.md files add up to 8,000 tokens, every general-purpose or custom subagent you spawn carries those 8,000 tokens on every one of its requests. Five parallel subagents carry them five times. The &lt;a href="https://tokenade.net/en/articles/claude-md-token-bloat" rel="noopener noreferrer"&gt;CLAUDE.md bloat problem&lt;/a&gt; gets multiplied by delegation.&lt;/p&gt;

&lt;p&gt;The other thing that surprises people is caching. A fresh subagent has a different system prompt from your main session, so it cannot read the prompt cache your session has already warmed. Its first request writes its startup payload to the cache. Forks behave differently: the docs note that "because a fork's system prompt and tool definitions are identical to the parent, its first request reuses the parent's prompt cache," which "makes forking cheaper than spawning a fresh subagent for tasks that need the same context." If you want the mechanics of cache reads versus writes, the &lt;a href="https://tokenade.net/en/glossary/prompt-caching" rel="noopener noreferrer"&gt;prompt caching glossary entry&lt;/a&gt; covers them, and &lt;a href="https://tokenade.net/en/articles/prompt-caching-cut-input-cost" rel="noopener noreferrer"&gt;how prompt caching cuts input cost&lt;/a&gt; shows the effect on a bill.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I measured on my own sessions
&lt;/h2&gt;

&lt;p&gt;Claude Code writes one transcript per subagent. The docs give the location: &lt;code&gt;~/.claude/projects/{project}/{sessionId}/subagents/&lt;/code&gt;, one &lt;code&gt;agent-{agentId}.jsonl&lt;/code&gt; file per subagent. Each assistant message in those files carries a &lt;code&gt;usage&lt;/code&gt; object with &lt;code&gt;input_tokens&lt;/code&gt;, &lt;code&gt;cache_creation_input_tokens&lt;/code&gt;, &lt;code&gt;cache_read_input_tokens&lt;/code&gt; and &lt;code&gt;output_tokens&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;I opened the subagent transcripts of one Claude Code session on my machine in September 2026 (model &lt;code&gt;claude-opus-5&lt;/code&gt;) and read the first request of each subagent. For the 19 subagents I checked:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;every first request had &lt;code&gt;cache_read_input_tokens&lt;/code&gt; at 0;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;cache_creation_input_tokens&lt;/code&gt; on that first request ranged from 12,427 to 40,763;&lt;/li&gt;
&lt;li&gt;the values fell into two groups, about 12,400 to 15,600 and about 37,000 to 40,800. I did not check which agent types sit in which group, so I will not claim a cause, though the CLAUDE.md row in the table above is the obvious suspect.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One long-running subagent in the same session also had a request deep into its run (line 481 of its transcript) that wrote 253,567 tokens to the cache with nothing read. I have not confirmed why the cache missed there. The lesson I take from it is narrower: a subagent that runs long enough can pay for its whole context a second time, and you will only see it if you look at the transcript.&lt;/p&gt;

&lt;p&gt;This is one session on one machine, so read it as an order of magnitude, not a benchmark. It agrees with the direction of the public reports above: the startup bill of a fresh subagent is in the tens of thousands of tokens, before it reads a single file. The broader &lt;a href="https://tokenade.net/en/stats/claude-code-token-usage-statistics" rel="noopener noreferrer"&gt;Claude Code token usage statistics&lt;/a&gt; page collects other published measurements.&lt;/p&gt;

&lt;h2&gt;
  
  
  How to measure the token cost of each subagent
&lt;/h2&gt;

&lt;p&gt;In February 2026 a user opened &lt;a href="https://github.com/anthropics/claude-code/issues/22625" rel="noopener noreferrer"&gt;a feature request for per-subagent token tracking&lt;/a&gt;, explaining that "there's no way to measure how many tokens each agent consumed." The issue was later closed as stale. You do not need the feature: the per-agent transcript files already hold the numbers.&lt;/p&gt;

&lt;p&gt;There is one trap. Claude Code writes a streamed response as several lines, and those lines repeat the same message ID with the same &lt;code&gt;usage&lt;/code&gt; object. In the transcript I checked, one request appeared on three separate lines with identical usage. Sum the lines naively and you triple-count. Deduplicate by &lt;code&gt;message.id&lt;/code&gt; first.&lt;/p&gt;

&lt;p&gt;With &lt;code&gt;jq&lt;/code&gt; installed, this prints one line per subagent of a session:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="k"&gt;for &lt;/span&gt;f &lt;span class="k"&gt;in&lt;/span&gt; ~/.claude/projects/&lt;span class="k"&gt;*&lt;/span&gt;/SESSION_ID/subagents/agent-&lt;span class="k"&gt;*&lt;/span&gt;.jsonl&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="k"&gt;do
  &lt;/span&gt;jq &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="nt"&gt;-c&lt;/span&gt; &lt;span class="nt"&gt;--arg&lt;/span&gt; f &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;$(&lt;/span&gt;&lt;span class="nb"&gt;basename&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$f&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;)&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt; &lt;span class="s1"&gt;'
    map(select(.message.usage)) | unique_by(.message.id) | map(.message.usage)
    | {agent: $f,
       requests: length,
       input: (map(.input_tokens) | add),
       cache_write: (map(.cache_creation_input_tokens) | add),
       cache_read: (map(.cache_read_input_tokens) | add),
       output: (map(.output_tokens) | add)}'&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="nv"&gt;$f&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;
&lt;span class="k"&gt;done&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;code&gt;SESSION_ID&lt;/code&gt; with the session you want (the folder names under your project are session IDs). Read the output with three questions:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Is &lt;code&gt;cache_write&lt;/code&gt; on the first request close to the total &lt;code&gt;cache_write&lt;/code&gt;?&lt;/strong&gt; Then most of what you paid was startup, and the task was probably too small to delegate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Is &lt;code&gt;requests&lt;/code&gt; high?&lt;/strong&gt; Forty requests means forty round trips, each re-sending the subagent's context. A tighter delegation prompt or a &lt;code&gt;maxTurns&lt;/code&gt; limit helps.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Is one agent far above its siblings?&lt;/strong&gt; That is the one to open. Usually it went exploring outside the scope you gave it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For the session-level picture, &lt;code&gt;/usage&lt;/code&gt; and the other tools in &lt;a href="https://tokenade.net/en/articles/measure-agent-token-usage" rel="noopener noreferrer"&gt;how to measure agent token usage&lt;/a&gt; remain the right starting point. The per-agent loop above answers the narrower question of which delegation was worth it.&lt;/p&gt;

&lt;p&gt;On a subscription, these are not dollars but they still count: Pro and Max limits are consumed by subagent tokens like any others, which is how a parallel fan-out can end a five-hour window early. The &lt;a href="https://tokenade.net/en/articles/claude-usage-limits-explained" rel="noopener noreferrer"&gt;Claude usage limits explainer&lt;/a&gt; covers how those windows work.&lt;/p&gt;

&lt;h2&gt;
  
  
  When a subagent saves tokens, and when it burns them
&lt;/h2&gt;

&lt;p&gt;Anthropic's guide names the cases where delegation pays: research-heavy tasks, independent sub-tasks that can run in parallel, and reviews that should not inherit the main session's assumptions. It also says that "for smaller or tightly sequential tasks, sticking to the main conversation is usually simpler."&lt;/p&gt;

&lt;p&gt;In token terms, the break-even is simple to state. A subagent saves tokens when:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;(tokens the work would add to your main context) × (turns left in your main session)&lt;/strong&gt; is larger than &lt;strong&gt;(startup bill) + (the subagent's own work) + (the summary it returns)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;The first term is what makes the difference. Tokens that land in your main context are re-sent on every later turn. A 30,000-token log read at turn 10 of a 60-turn session gets processed again on each of the 50 remaining turns, mostly as cheap cache reads but never free, and it pushes the session toward compaction sooner. The same log read inside a subagent is paid once, inside a context that disappears when the subagent returns.&lt;/p&gt;

&lt;p&gt;That gives a practical split.&lt;/p&gt;

&lt;p&gt;Delegate:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Wide searches.&lt;/strong&gt; "Find every place we call the payments client and tell me which ones pass a retry option." The raw search output is large, the answer is a list.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Log and test triage.&lt;/strong&gt; "Run the suite and report only failing tests with their error messages," as the &lt;a href="https://code.claude.com/docs/en/sub-agents" rel="noopener noreferrer"&gt;docs suggest&lt;/a&gt;. Test output is one of the largest sources of wasted context; &lt;a href="https://tokenade.net/en/articles/output-filtering-command-logs" rel="noopener noreferrer"&gt;output filtering&lt;/a&gt; is the other fix.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Independent parallel work&lt;/strong&gt; across packages, when nothing depends on the order.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A clean-slate review&lt;/strong&gt; before you commit, where not seeing your conversation is the point.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keep in the main session:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Edits to one or two files you already have open.&lt;/strong&gt; The subagent would re-read them.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Chains where step two depends on the detail of step one.&lt;/strong&gt; The summary loses exactly the detail you need.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Questions about things already in your context.&lt;/strong&gt; The docs point to &lt;code&gt;/btw&lt;/code&gt; for this: it "sees your full context but has no tool access, and the answer isn't added to history."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Anything short.&lt;/strong&gt; If the work itself is a few thousand tokens, the startup bill alone is larger.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Settings that shrink the bill
&lt;/h2&gt;

&lt;p&gt;Once you know which subagents you keep, a few settings from the docs change what each one costs.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;omitClaudeMd: true&lt;/code&gt; on custom agents.&lt;/strong&gt; It launches the subagent without the user, project and local CLAUDE.md files (managed policy files still load). The docs point out that "the main conversation still has your full CLAUDE.md when it reads these subagents' results, so most rules don't need to reach the subagent itself." If a rule must reach it, write that rule into the delegation prompt. This setting requires Claude Code v2.1.271 or later.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A tight &lt;code&gt;tools&lt;/code&gt; list.&lt;/strong&gt; A read-only research agent does not need write tools or every MCP server. Fewer tools means smaller tool schemas on every request and fewer ways to wander. If MCP schemas are the bulk of your payload, &lt;a href="https://tokenade.net/en/articles/lazy-mcp-loading" rel="noopener noreferrer"&gt;lazy MCP loading&lt;/a&gt; addresses that at the source.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The &lt;code&gt;model&lt;/code&gt; field.&lt;/strong&gt; Accepted values are &lt;code&gt;sonnet&lt;/code&gt;, &lt;code&gt;opus&lt;/code&gt;, &lt;code&gt;haiku&lt;/code&gt;, &lt;code&gt;fable&lt;/code&gt;, a full model ID, or &lt;code&gt;inherit&lt;/code&gt;. A search-and-summarize agent rarely needs the model you chose for the main session. Two caveats from the docs: a subagent's context window "is sized by its own model, not the parent's," and &lt;code&gt;CLAUDE_CODE_SUBAGENT_MODEL&lt;/code&gt; can force one model onto every subagent, which overrides the per-agent choice.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;code&gt;maxTurns&lt;/code&gt;.&lt;/strong&gt; It caps the agentic turns before the subagent stops and returns partial output. It is a blunt tool, but it turns a runaway exploration into a bounded one, and a resumable subagent can be told to continue.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Forks for context-heavy side tasks.&lt;/strong&gt; When the side task needs what your session already knows, &lt;code&gt;/subtask&lt;/code&gt; starts a fork that reuses the parent's cache instead of paying a fresh startup bill.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The concurrency ceiling.&lt;/strong&gt; By default Claude Code refuses to spawn another subagent while 20 are running (&lt;code&gt;CLAUDE_CODE_MAX_CONCURRENT_SUBAGENTS&lt;/code&gt; changes it). That is a safety limit, not a budget. If you run agents unattended, the controls in &lt;a href="https://tokenade.net/en/articles/overnight-agent-budget-safety" rel="noopener noreferrer"&gt;overnight agent budget safety&lt;/a&gt; matter more.&lt;/p&gt;

&lt;h2&gt;
  
  
  Common mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Summing transcript lines without deduplicating.&lt;/strong&gt; Streamed responses repeat the same &lt;code&gt;usage&lt;/code&gt; on several lines. Per-agent totals come out two or three times too high, and the "subagents are expensive" conclusion gets exaggerated.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Delegating a task that needs the conversation.&lt;/strong&gt; The subagent does not see your history. It either guesses or re-reads, and re-reading is the expensive path.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Heavy CLAUDE.md plus many custom agents.&lt;/strong&gt; Every general-purpose or custom subagent carries the whole hierarchy. Trim CLAUDE.md or set &lt;code&gt;omitClaudeMd&lt;/code&gt; on agents that get their instructions from the prompt.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Asking for "a full report."&lt;/strong&gt; The return value lands in your main context. Ask for the list, the failing tests, the three files: the output format is part of the saving.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Judging from one anecdote.&lt;/strong&gt; The 40% saving and the 15-minute Pro limit are both real reports from different workloads. Measure your own before changing your habits.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Assuming parallel means cheaper.&lt;/strong&gt; Parallel subagents finish sooner. The token total is the sum of every agent's startup bill and work, whatever the wall-clock time.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What to do this week
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Read one session's subagent bill.&lt;/strong&gt; Pick a recent session where Claude Code delegated, run the &lt;code&gt;jq&lt;/code&gt; loop above, and note the first-request &lt;code&gt;cache_write&lt;/code&gt; for each agent. You need &lt;code&gt;jq&lt;/code&gt; and five minutes. You will know your own startup bill instead of borrowing someone else's.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Find the delegations that did not pay.&lt;/strong&gt; Any agent whose total &lt;code&gt;cache_write&lt;/code&gt; is mostly its first request, with a handful of requests, did too little work to justify spawning. Write one line in your CLAUDE.md telling Claude which kinds of tasks to keep in the main session.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Trim what every subagent carries.&lt;/strong&gt; Measure your CLAUDE.md files, then add &lt;code&gt;omitClaudeMd: true&lt;/code&gt; and a narrow &lt;code&gt;tools&lt;/code&gt; list to the custom agents that do search or triage. Re-run the loop on a comparable session and compare first-request &lt;code&gt;cache_write&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Move one noisy job into a subagent on purpose.&lt;/strong&gt; Test runs or wide searches are the usual candidates. Ask for a short, fixed output format and compare the main session's context before and after with &lt;code&gt;/context&lt;/code&gt;.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Do Claude Code subagents use more tokens than a single session?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In total, usually yes. Each fresh subagent pays a startup bill (system prompt, CLAUDE.md, git status, tool definitions) and runs its own loop. Anthropic measured multi-agent systems at about 15× the tokens of chat interactions in its &lt;a href="https://www.anthropic.com/engineering/multi-agent-research-system" rel="noopener noreferrer"&gt;Research system write-up&lt;/a&gt;. What subagents can reduce is the size of your main context, and with it the cost of every later turn. Whether the total goes down depends on how much raw material the subagent kept out of the main session and how many turns that session still had to run.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How many tokens does a subagent use just to start?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It depends on your CLAUDE.md files, the agent's prompt, its tools and preloaded skills. On one of my sessions in September 2026, 19 subagents each wrote between 12,427 and 40,763 tokens to the cache on their first request, with nothing read from cache. A public report from July 2026 &lt;a href="https://aditlal.dev/tame-claude-tokens/" rel="noopener noreferrer"&gt;measured 66K to 84K tokens per subagent&lt;/a&gt; over whole runs. Measure yours with the transcript loop in this article.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do subagents load my CLAUDE.md?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;General-purpose and custom subagents load every level of the CLAUDE.md hierarchy the main session loads, according to the &lt;a href="https://code.claude.com/docs/en/sub-agents" rel="noopener noreferrer"&gt;subagent docs&lt;/a&gt;. The built-in Explore and Plan agents skip it. A custom agent with &lt;code&gt;omitClaudeMd: true&lt;/code&gt; loads only managed policy files. If a rule must reach such an agent, put it in the delegation prompt.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How do I see token usage per subagent?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Claude Code stores one transcript per subagent at &lt;code&gt;~/.claude/projects/&amp;lt;project&amp;gt;/&amp;lt;session&amp;gt;/subagents/agent-&amp;lt;id&amp;gt;.jsonl&lt;/code&gt;. Each assistant message has a &lt;code&gt;usage&lt;/code&gt; object. Deduplicate by &lt;code&gt;message.id&lt;/code&gt;, because one streamed response appears on several lines, then sum input, cache write, cache read and output tokens. The &lt;code&gt;jq&lt;/code&gt; loop above does it per agent.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is the Explore subagent cheaper than general-purpose?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It starts lighter. Explore skips CLAUDE.md and git status and is limited to read-only tools. Its model inherits from the main conversation, capped at Opus on the Claude API, so it never runs on a more expensive model than the session. What it costs in total still depends on how much it searches. Explore is one-shot and cannot be resumed, so follow-up questions start a new instance and a new startup bill.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Are forks cheaper than subagents?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To start, yes, for work that needs the same context. A fork launched with &lt;code&gt;/subtask&lt;/code&gt; inherits the parent conversation, and its first request reuses the parent's prompt cache because its system prompt and tool definitions are identical. A fresh subagent writes its own cache from scratch. The trade-off: a fork carries your whole conversation, so it is a poor choice when the side task needs none of it.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why did parallel subagents burn through my Pro limit?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Subscription limits count every agent's tokens. Five parallel subagents pay five startup bills and run five loops at the same time, so usage arrives much faster than in a single session doing the same work sequentially. One developer reported &lt;a href="https://dev.to/onlineeric/claude-code-sub-agents-burn-out-your-tokens-4cd8"&gt;hitting the Pro limit in about 15 minutes&lt;/a&gt; that way, against roughly 30 minutes of sequential processing. If limits matter more than wall-clock time, ask Claude to run the sub-tasks one after another.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Should I set subagents to a smaller model?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For search, triage and summarizing, often yes, through the &lt;code&gt;model&lt;/code&gt; field of a custom agent. Keep two limits in mind: the subagent's context window is sized by its own model, and a smaller model that misreads the task can cost you a second delegation. Try it on one noisy agent, compare the transcript totals and the quality of the summaries, then decide.&lt;/p&gt;

&lt;h2&gt;
  
  
  Related reads
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://tokenade.net/en/articles/reduce-claude-code-token-usage" rel="noopener noreferrer"&gt;Reduce Claude Code token usage&lt;/a&gt;: the wider set of fixes, of which delegation is one.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tokenade.net/en/articles/claude-md-token-bloat" rel="noopener noreferrer"&gt;CLAUDE.md token bloat&lt;/a&gt;: the file every general-purpose subagent carries on each request.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tokenade.net/en/articles/measure-agent-token-usage" rel="noopener noreferrer"&gt;How to measure agent token usage&lt;/a&gt;: session-level measurement before you zoom into agents.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tokenade.net/en/articles/lazy-mcp-loading" rel="noopener noreferrer"&gt;Lazy MCP loading&lt;/a&gt;: shrinking the tool schemas each subagent inherits.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tokenade.net/en/articles/claude-code-skills" rel="noopener noreferrer"&gt;Claude Code skills&lt;/a&gt;: the alternative when you want a reusable workflow in the main context.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tokenade.net/en/articles/reduce-tokens-long-sessions" rel="noopener noreferrer"&gt;Reduce tokens in long sessions&lt;/a&gt;: why context kept out of the main session keeps paying off.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://tokenade.net/en/articles/overnight-agent-budget-safety" rel="noopener noreferrer"&gt;Overnight agent budget safety&lt;/a&gt;: limits for agents that run while nobody is watching.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Measurements in this article come from my own Claude Code sessions. More about who writes these pages: &lt;a href="https://tokenade.net/en/about" rel="noopener noreferrer"&gt;about&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Tokenade is free and open source: &lt;a href="https://github.com/pi-infected/tokenade" rel="noopener noreferrer"&gt;https://github.com/pi-infected/tokenade&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>agents</category>
      <category>ai</category>
      <category>claude</category>
      <category>llm</category>
    </item>
    <item>
      <title>I open-sourced Tokenade, my token optimizer for coding agents. Here is why the paid model did not hold</title>
      <dc:creator>Paul Irolla</dc:creator>
      <pubDate>Mon, 19 Oct 2026 22:50:54 +0000</pubDate>
      <link>https://dev.to/paul_irolla_6b5ae261d0224/i-open-sourced-tokenade-my-token-optimizer-for-coding-agents-here-is-why-the-paid-model-did-not-2ahc</link>
      <guid>https://dev.to/paul_irolla_6b5ae261d0224/i-open-sourced-tokenade-my-token-optimizer-for-coding-agents-here-is-why-the-paid-model-did-not-2ahc</guid>
      <description>&lt;p&gt;Tokenade is free and open source as of version 2.0, under MIT OR Apache-2.0. The code is on GitHub: &lt;a href="https://github.com/pi-infected/tokenade" rel="noopener noreferrer"&gt;https://github.com/pi-infected/tokenade&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I tried to sell it first. Here is why that did not hold, what Tokenade does, and how to check it on your own sessions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the paid model did not hold
&lt;/h2&gt;

&lt;p&gt;Most people run Claude Code, Cursor or Codex on a subscription. They never see a token bill, so a tool that shrinks the bill solves a problem they do not feel. The people who do pay per token call the API directly, and for them the useful version is a proxy in front of the provider. I do not want to run a proxy business.&lt;/p&gt;

&lt;p&gt;So the honest move was to give it away and let the code speak.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it does
&lt;/h2&gt;

&lt;p&gt;A coding agent pays for what it reads, and it reads the same things again with each turn: build logs, test output, whole files it opened once and kept in the history. Tokenade works on that layer, on your machine.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Command output.&lt;/strong&gt; When the agent runs a noisy command, Tokenade compacts what comes back before the model reads it. &lt;code&gt;tokenade raw &amp;lt;cmd&amp;gt;&lt;/code&gt; bypasses it when you want the full output.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Finding code without reading it.&lt;/strong&gt; &lt;code&gt;tokenade map&lt;/code&gt;, &lt;code&gt;query &amp;lt;symbol&amp;gt;&lt;/code&gt;, &lt;code&gt;skeleton &amp;lt;file&amp;gt;&lt;/code&gt; and &lt;code&gt;semantic "&amp;lt;question&amp;gt;"&lt;/code&gt; give the agent the structure it needs instead of whole files.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Documents and pages.&lt;/strong&gt; &lt;code&gt;tokenade read&lt;/code&gt; turns a PDF, a spreadsheet or a long file into the text that matters. &lt;code&gt;tokenade web&lt;/code&gt; and &lt;code&gt;tokenade search&lt;/code&gt; do the same for web pages and search results.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;API users.&lt;/strong&gt; &lt;code&gt;tokenade llm-proxy&lt;/code&gt; runs locally between the agent and the provider. It folds tool results already in the history and sends an identical tool output only once. Run it, or fork it.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;tokenade install&lt;/code&gt; detects the agents already on the machine and wires itself in. There is nothing to configure.&lt;/p&gt;

&lt;h2&gt;
  
  
  The number
&lt;/h2&gt;

&lt;p&gt;On THOL, a public benchmark of token-harness optimizers that I maintain, Tokenade reduces token costs by 39% on average on long sessions (over 200k tokens) with Claude Code, measured on 2026-09-14. That is an average, not a ceiling, and the raw runs are public: &lt;a href="https://pi-infected.github.io/token-harness-optimizer-leaderboard/" rel="noopener noreferrer"&gt;https://pi-infected.github.io/token-harness-optimizer-leaderboard/&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; @tokenade/cli
tokenade &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After a long session, &lt;code&gt;tokenade dashboard&lt;/code&gt; shows what it saved, graphed by token category and by model.&lt;/p&gt;

&lt;p&gt;If it saves you nothing, I want to know why: open an issue with the command or the setup. If it helps, a star on the repo is the quickest way to tell me.&lt;/p&gt;

</description>
      <category>agents</category>
      <category>github</category>
      <category>llm</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Anthropic admitted that Fable burned through their €200/month Claude Code plan in 1 hour instead of 5.</title>
      <dc:creator>Paul Irolla</dc:creator>
      <pubDate>Tue, 07 Jul 2026 11:30:24 +0000</pubDate>
      <link>https://dev.to/paul_irolla_6b5ae261d0224/anthropic-admitted-that-fable-burned-through-their-eu200month-claude-code-plan-in-1-hour-instead-of-329i</link>
      <guid>https://dev.to/paul_irolla_6b5ae261d0224/anthropic-admitted-that-fable-burned-through-their-eu200month-claude-code-plan-in-1-hour-instead-of-329i</guid>
      <description>&lt;p&gt;The community responded with an explosion of tools. Here are all the optimization techniques I've found. Ranked from C-Tier (meme) to S-Tier (serious engineering).&lt;/p&gt;

&lt;p&gt;⭐ C-Tier: Use /compact when you're at 60% of the conversation's max context. 60% is the sweet spot. Context tokens aren't all equal, and when you're near the limit, agents start drifting and follow instructions less reliably. Why meme-tier? Because nobody's going to do it manually. (It's done automatically by the S-Tier tool.)&lt;/p&gt;

&lt;p&gt;⭐⭐ B-Tier: Compress prompts before they reach the model. In any prompt, roughly half the words carry no real information, and agents are perfectly capable of filling in the blanks. That's why there's a whole category of specialized models for prompt compression with minimal quality loss: LLMLingua or Bear-2, for example. Why B-Tier? It's only really suitable for deterministic workflows (like n8n or similar), not for highly variable agentic environments. But it's excellent in those specific cases.&lt;/p&gt;

&lt;p&gt;⭐⭐ B-Tier: Always tell Claude to launch its exploration sub-agents with Haiku instead of Fable, Opus, or Sonnet. This can be up to 92% cheaper on exploratory searches. Haiku is great at digging, not at thinking.&lt;/p&gt;

&lt;p&gt;⭐⭐⭐ A-Tier: /effort default to xhigh. All the time. But 80% of what you ask Claude doesn't actually need that level of token waste. Switch to medium or high for most tasks — it cuts the amount of thinking required by 2x or 4x to reach the result.&lt;/p&gt;

&lt;p&gt;⭐⭐⭐⭐ S-Tier: Agent harness compaction tool. Why S-Tier? It's plug-and-play and the gains are immediate, no matter what you're doing with your agent. Tokenade, for example, automatically optimizes: the commands the model uses, file re-reads, code/web search, MCPs, the order of tool calls, etc. It currently ranks #1 on THOL (Token-Harness Optimizer Leaderboard), with -27% token cost on 200k+ token conversations and -40% on 400k+ token conversations (Opus &amp;amp; Fable).&lt;/p&gt;

&lt;p&gt;Do you use any of these techniques ? &lt;/p&gt;

&lt;p&gt;Tokenade : &lt;a href="https://tokenade.net/" rel="noopener noreferrer"&gt;https://tokenade.net/&lt;/a&gt;&lt;br&gt;
THOL : &lt;a href="https://pi-infected.github.io/token-harness-optimizer-leaderboard/" rel="noopener noreferrer"&gt;https://pi-infected.github.io/token-harness-optimizer-leaderboard/&lt;/a&gt;&lt;br&gt;
LLMLingua : &lt;a href="https://huggingface.co/spaces/microsoft/llmlingua-2" rel="noopener noreferrer"&gt;https://huggingface.co/spaces/microsoft/llmlingua-2&lt;/a&gt;&lt;br&gt;
Bear-2 : &lt;a href="https://thetokencompany.com/" rel="noopener noreferrer"&gt;https://thetokencompany.com/&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>programming</category>
      <category>devops</category>
      <category>automation</category>
    </item>
    <item>
      <title>Position-1 CTR isn't 30% anymore — what AI Overviews actually do to your clicks (+ a free calculator)</title>
      <dc:creator>Paul Irolla</dc:creator>
      <pubDate>Sat, 16 May 2026 08:48:29 +0000</pubDate>
      <link>https://dev.to/paul_irolla_6b5ae261d0224/position-1-ctr-isnt-30-anymore-what-ai-overviews-actually-do-to-your-clicks-a-free-57n</link>
      <guid>https://dev.to/paul_irolla_6b5ae261d0224/position-1-ctr-isnt-30-anymore-what-ai-overviews-actually-do-to-your-clicks-a-free-57n</guid>
      <description>&lt;p&gt;For years, the SEO planning template was the same spreadsheet trick: pull the keyword volume, multiply by an assumed CTR (the famous "31% for position 1"), and call that your traffic projection. In 2026, that math is broken.&lt;/p&gt;

&lt;p&gt;What changed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;AI Overviews&lt;/strong&gt; sit above the organic results on most informational queries. The user often gets their answer in the box and never scrolls.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Featured snippets&lt;/strong&gt; still steal the click on definitional / how-to queries.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;People Also Ask&lt;/strong&gt; clusters expand inline and burn 6-8 vertical inches of SERP real estate.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sponsored carousels&lt;/strong&gt; on commercial intent queries push the first organic result &lt;em&gt;below the fold&lt;/em&gt; on mobile.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The result: position 1 organic CTR for an informational keyword in 2026 is closer to &lt;strong&gt;8-15%&lt;/strong&gt; than to the legacy 30%. For commercial-intent keywords with a sponsored carousel and an AI Overview, position 1 organic CTR can drop to &lt;strong&gt;3-6%&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;If you're still planning content with a 30% assumption, your traffic forecasts are off by a factor of 3-10x. Which means the keyword you're killing for "low projected upside" might actually be the one worth shipping, and the keyword you're prioritizing for "30% × 12k searches" is going to disappoint.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I changed in my own planning
&lt;/h2&gt;

&lt;p&gt;I split CTR assumptions into 4 SERP archetypes:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;SERP type&lt;/th&gt;
&lt;th&gt;Position 1 CTR (2026)&lt;/th&gt;
&lt;th&gt;Position 2-3 CTR&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Plain organic (rare)&lt;/td&gt;
&lt;td&gt;28-35%&lt;/td&gt;
&lt;td&gt;12-18%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Organic + PAA only&lt;/td&gt;
&lt;td&gt;18-24%&lt;/td&gt;
&lt;td&gt;8-12%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Organic + AI Overview&lt;/td&gt;
&lt;td&gt;8-15%&lt;/td&gt;
&lt;td&gt;3-7%&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Organic + AI Overview + sponsored carousel&lt;/td&gt;
&lt;td&gt;3-6%&lt;/td&gt;
&lt;td&gt;1-3%&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Before committing to a topic, I run the SERP through a quick check: which archetype is it? Then I plug the right CTR into the volume math. That single change cut the gap between my projected and observed traffic by ~70%.&lt;/p&gt;

&lt;h2&gt;
  
  
  A free thing for the lazy version of you
&lt;/h2&gt;

&lt;p&gt;I built a free in-browser calculator that does this for you — paste the keyword + chosen position + SERP archetype, get a realistic click projection: &lt;a href="https://the-seo-autopilot.com/en/free-tools/serp-ctr-calculator" rel="noopener noreferrer"&gt;the-seo-autopilot.com/en/free-tools/serp-ctr-calculator&lt;/a&gt;. No signup, all client-side, no email gate. Use it when you're triaging a 200-keyword list and don't want to manually classify every SERP.&lt;/p&gt;

&lt;p&gt;There's also a related one I use a lot — a &lt;a href="https://the-seo-autopilot.com/en/free-tools/keyword-opportunity-calculator" rel="noopener noreferrer"&gt;keyword opportunity calculator&lt;/a&gt; that combines this CTR adjustment with difficulty / volume / business value to spit out a single ranked score per keyword. Useful when you have a backlog of 50 ideas and need to pick the next 5.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;The "30% for position 1" rule of thumb is a 2018 number. Don't plan with it in 2026.&lt;/li&gt;
&lt;li&gt;Classify each keyword's SERP into one of 4 archetypes before assigning a CTR.&lt;/li&gt;
&lt;li&gt;AI Overviews + sponsored carousels can drop your effective CTR by 5-10x.&lt;/li&gt;
&lt;li&gt;Recalibrate. Your "low-volume but high-intent" keywords are probably more valuable than your "high-volume informational" ones now.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Plan your content with the SERP you actually have, not the SERP you wish you had.&lt;/p&gt;

</description>
      <category>webdev</category>
    </item>
    <item>
      <title>What is /llms.txt? — the AI-crawler hint file (+ the free generator I built for it)</title>
      <dc:creator>Paul Irolla</dc:creator>
      <pubDate>Fri, 15 May 2026 17:38:46 +0000</pubDate>
      <link>https://dev.to/paul_irolla_6b5ae261d0224/what-is-llmstxt-the-ai-crawler-hint-file-the-free-generator-i-built-for-it-4e3p</link>
      <guid>https://dev.to/paul_irolla_6b5ae261d0224/what-is-llmstxt-the-ai-crawler-hint-file-the-free-generator-i-built-for-it-4e3p</guid>
      <description>&lt;p&gt;Last year a small RFC started making the rounds: &lt;strong&gt;&lt;code&gt;/llms.txt&lt;/code&gt;&lt;/strong&gt;. It's a single-file convention that tells AI assistants (ChatGPT, Claude, Perplexity, the Google AI Overview, Copilot…) which content on your site to surface and how to summarize it. Think &lt;code&gt;robots.txt&lt;/code&gt;, but for &lt;em&gt;meaning&lt;/em&gt; instead of &lt;em&gt;crawl rules&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;I've been running an autonomous SEO agent on a SaaS site, and &lt;code&gt;/llms.txt&lt;/code&gt; showed up as the cheapest-yield optimization I could ship: a single static file, written once, that materially changes how an LLM frames your brand when a user asks about your space.&lt;/p&gt;

&lt;p&gt;This post is what I wish I'd read before writing my first one.&lt;/p&gt;

&lt;h2&gt;
  
  
  What &lt;code&gt;/llms.txt&lt;/code&gt; actually contains
&lt;/h2&gt;

&lt;p&gt;The format is intentionally minimal — a markdown file at your domain root:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight markdown"&gt;&lt;code&gt;&lt;span class="gh"&gt;# Acme — autonomous test runners for SaaS&lt;/span&gt;
&lt;span class="gt"&gt;
&amp;gt; One-line description of the project, exactly the way you'd want an&lt;/span&gt;
&lt;span class="gt"&gt;&amp;gt; LLM to re-quote it.&lt;/span&gt;

&lt;span class="gu"&gt;## Docs&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;Getting started&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="sx"&gt;https://acme.dev/docs/start.md&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;API reference&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="sx"&gt;https://acme.dev/docs/api.md&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="gu"&gt;## Examples&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;End-to-end test for a Stripe checkout&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="sx"&gt;https://acme.dev/examples/stripe.md&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="gu"&gt;## Optional&lt;/span&gt;
&lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;Pricing&lt;/span&gt;&lt;span class="p"&gt;](&lt;/span&gt;&lt;span class="sx"&gt;https://acme.dev/pricing.md&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Three things matter:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;The summary line is the brand-positioning weapon.&lt;/strong&gt; If a user asks "what is Acme?", the LLM is statistically going to lift this line. Write it like the headline you'd put on a billboard, not like a feature list.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sections are signals.&lt;/strong&gt; "Docs" / "Examples" / "API" tell the LLM what surfaces are worth pulling into a citation. The order matters — what you list first gets weighted higher.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Optional vs required.&lt;/strong&gt; The &lt;code&gt;## Optional&lt;/code&gt; section is content you'd be happy to see referenced, but don't &lt;em&gt;need&lt;/em&gt; surfaced. Pricing, blog posts, careers — that kind of thing.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What it's NOT
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;It's NOT a robots.txt. AI crawlers will still hit your site without one.&lt;/li&gt;
&lt;li&gt;It's NOT a sitemap. It doesn't enumerate every URL — it picks the &lt;em&gt;important&lt;/em&gt; ones and tells the LLM how to frame them.&lt;/li&gt;
&lt;li&gt;It's NOT machine-validated. There's no "llms.txt parser" that errors out on bad syntax. The LLM does its best with whatever you write. So write it well.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How to validate yours
&lt;/h2&gt;

&lt;p&gt;I built a free in-browser generator that does the formatting + a sanity check on the structure: &lt;a href="https://the-seo-autopilot.com/en/free-tools/llms-txt-generator" rel="noopener noreferrer"&gt;the-seo-autopilot.com/en/free-tools/llms-txt-generator&lt;/a&gt;. No signup — it's all client-side. Paste your site description, your section URLs, hit generate, copy the markdown into your site root.&lt;/p&gt;

&lt;p&gt;If you want to see one in production, mine is at &lt;a href="https://the-seo-autopilot.com/llms.txt" rel="noopener noreferrer"&gt;the-seo-autopilot.com/llms.txt&lt;/a&gt;. It's also indexed in &lt;a href="https://github.com/SecretiveShell/Awesome-llms-txt" rel="noopener noreferrer"&gt;SecretiveShell/Awesome-llms-txt&lt;/a&gt; — a curated list of all the public &lt;code&gt;/llms.txt&lt;/code&gt; files in the wild, which is where I'd recommend looking before writing your own.&lt;/p&gt;

&lt;h2&gt;
  
  
  Does it actually move the needle?
&lt;/h2&gt;

&lt;p&gt;Honest answer: too early to say with high confidence in 2026, but the signal is positive. Sites with a well-written &lt;code&gt;/llms.txt&lt;/code&gt; get cited more often in ChatGPT and Perplexity answers in the niche I track (programmatic SEO + indie SaaS). The cost is roughly an hour, the upside is "free distribution surface that didn't exist 18 months ago."&lt;/p&gt;

&lt;p&gt;Worth shipping.&lt;/p&gt;

</description>
      <category>showdev</category>
    </item>
    <item>
      <title>I'm running an autonomous AI agent that publishes a fact-checked SEO article every day — here's the stack</title>
      <dc:creator>Paul Irolla</dc:creator>
      <pubDate>Fri, 15 May 2026 16:18:46 +0000</pubDate>
      <link>https://dev.to/paul_irolla_6b5ae261d0224/im-running-an-autonomous-ai-agent-that-publishes-a-fact-checked-seo-article-every-day-heres-the-1753</link>
      <guid>https://dev.to/paul_irolla_6b5ae261d0224/im-running-an-autonomous-ai-agent-that-publishes-a-fact-checked-seo-article-every-day-heres-the-1753</guid>
      <description>&lt;p&gt;For the past 60 days I've been running an experiment: an AI agent owns the entire SEO pipeline of one of my SaaS sites. Keyword research, drafting, fact-checking, internal linking, schema markup, scheduling — the agent does it all. Zero human touch on the content side.&lt;/p&gt;

&lt;p&gt;Results so far: &lt;strong&gt;0 → 400K+ Google impressions in 60 days. 46 articles live, 330+ scheduled. No backlinks bought, no paid promotion.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I'm sharing the stack because every "AI SEO" tool on the market today is either a glorified ChatGPT wrapper or charges $1k+/mo for marginal automation. The agent below runs on a small VPS in a Python loop and costs me less than $100/month in OpenRouter API credits.&lt;/p&gt;

&lt;h2&gt;
  
  
  The pipeline
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Keyword pipeline&lt;/strong&gt; — a daily cron pulls the SERPs of ~300 seed queries via DataForSEO, scores by intent × difficulty, picks the next batch.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Drafting&lt;/strong&gt; — a frontier model writes a first draft against a structured outline. Cost: ~$0.10 per article.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fact-check pass&lt;/strong&gt; — a smaller, cheaper model re-reads the draft with a &lt;em&gt;"find every factual claim and verify it has a credible source"&lt;/em&gt; prompt. Anything dubious gets flagged.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;On-page&lt;/strong&gt; — JSON-LD schema, internal links to existing articles via cosine similarity on embeddings, title/meta optimization.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Scheduling&lt;/strong&gt; — one article goes live per day at a fixed time. The cadence matters more than the volume of any single drop.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Monitoring&lt;/strong&gt; — a tiny script pings Google Search Console weekly and surfaces underperformers for the agent to refresh.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  What I've learned
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Quality from AI agents is fundamentally a context problem.&lt;/strong&gt; The agent gets the keyword + the SERP context + the existing internal-link graph + a brand voice guide. With those inputs, modern LLMs write better than most freelancers I've hired for the same money.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The fact-check pass is the unlock.&lt;/strong&gt; Without it, AI articles confidently hallucinate stats. With it, they're often more reliable than the median human content for the same niche.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Publishing daily compounds.&lt;/strong&gt; Google indexes a healthy domain quickly when the cadence is regular. The 60-day curve looked basically flat for the first three weeks, then bent up.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Most "AI tool" directories will reject you if you aren't actually a tool.&lt;/strong&gt; A playbook is not a tool. A free in-browser &lt;code&gt;/llms.txt&lt;/code&gt; generator IS a tool. Frame accordingly when you submit.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Tooling
&lt;/h2&gt;

&lt;p&gt;The site ships a free &lt;code&gt;/llms.txt&lt;/code&gt; generator plus 12 other one-shot SEO tools (JSON-LD schema generator, SERP CTR calculator, hreflang tag generator, etc.) at &lt;a href="https://the-seo-autopilot.com/en/free-tools/" rel="noopener noreferrer"&gt;the-seo-autopilot.com/en/free-tools&lt;/a&gt; — no signup, all client-side.&lt;/p&gt;

&lt;p&gt;The full architecture writeup, prompts, and scheduler code are documented at &lt;a href="https://the-seo-autopilot.com" rel="noopener noreferrer"&gt;the-seo-autopilot.com&lt;/a&gt; for indie SaaS founders who want to copy the setup. Happy to dig into specific bits in the comments — particularly the fact-check prompt, which is the part I had to iterate on the most.&lt;/p&gt;

</description>
      <category>indiehackers</category>
    </item>
    <item>
      <title>Dominate LinkedIn in just 5 minutes a day</title>
      <dc:creator>Paul Irolla</dc:creator>
      <pubDate>Sun, 10 Aug 2025 13:10:19 +0000</pubDate>
      <link>https://dev.to/paul_irolla_6b5ae261d0224/dominate-linkedin-in-just-5-minutes-a-day-536i</link>
      <guid>https://dev.to/paul_irolla_6b5ae261d0224/dominate-linkedin-in-just-5-minutes-a-day-536i</guid>
      <description>&lt;p&gt;That’s not clickbait.&lt;br&gt;
That’s exactly what Meet Lea was built for.&lt;/p&gt;

&lt;p&gt;Here’s the problem:&lt;/p&gt;

&lt;p&gt;You know you should post regularly… but blank page syndrome is real.&lt;/p&gt;

&lt;p&gt;You want to engage with your audience… but comment replies eat hours.&lt;/p&gt;

&lt;p&gt;You’d love to track what works… but analytics feel like a chore.&lt;/p&gt;

&lt;p&gt;Lea solves all of it.&lt;/p&gt;

&lt;p&gt;✅ Create posts that actually perform — Turn any idea, article, or file into a ready-to-publish LinkedIn post in seconds.&lt;br&gt;
✅ Engage without the burnout — Lea suggests smart, human-like replies to every comment.&lt;br&gt;
✅ Know exactly what to post next — Intelligent content analysis tells you what your audience truly cares about.&lt;br&gt;
✅ Grow with clarity — Engagement tracking, growth insights, and post ideas… all in one dashboard.&lt;/p&gt;

&lt;p&gt;Who’s already using it?&lt;br&gt;
Freelancers. Agencies. Marketing managers. Community builders.&lt;br&gt;
Over 500 people are on board — and in beta, Lea has already generated:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;107K sources of content&lt;/li&gt;
&lt;li&gt;17K post ideas&lt;/li&gt;
&lt;li&gt;3K full posts&lt;/li&gt;
&lt;li&gt;19K comments&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This is your unfair LinkedIn advantage.&lt;br&gt;
Access is limited. The waitlist is filling fast.&lt;/p&gt;

&lt;p&gt;🎁 Join now and get:&lt;/p&gt;

&lt;p&gt;Priority access&lt;/p&gt;

&lt;p&gt;7 days free&lt;/p&gt;

&lt;p&gt;Early adopter perks&lt;/p&gt;

&lt;p&gt;🚀 Stop overthinking. Start dominating.&lt;br&gt;
👉 Join the waitlist today.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://meet-lea.com" rel="noopener noreferrer"&gt;https://meet-lea.com&lt;/a&gt;&lt;/p&gt;

</description>
      <category>ai</category>
      <category>automation</category>
      <category>contentwriting</category>
    </item>
  </channel>
</rss>
