<?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: Adela</title>
    <description>The latest articles on DEV Community by Adela (@adela_0414).</description>
    <link>https://dev.to/adela_0414</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%2F4084493%2Fd3416b1b-fc8f-4275-a634-d8d7bbf12c01.png</url>
      <title>DEV Community: Adela</title>
      <link>https://dev.to/adela_0414</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/adela_0414"/>
    <language>en</language>
    <item>
      <title>Claude Code Context Usage: Diagnose Unnecessary Tokens</title>
      <dc:creator>Adela</dc:creator>
      <pubDate>Thu, 20 Aug 2026 08:18:24 +0000</pubDate>
      <link>https://dev.to/bettertoken_ai/claude-code-context-usage-diagnose-unnecessary-tokens-476e</link>
      <guid>https://dev.to/bettertoken_ai/claude-code-context-usage-diagnose-unnecessary-tokens-476e</guid>
      <description>&lt;h1&gt;
  
  
  Claude Code Context Usage: Diagnose Unnecessary Tokens
&lt;/h1&gt;

&lt;p&gt;In the Claude Code community, a user reported that a fresh session started at roughly 35,000 tokens and later dropped to about 13,000 after cleaning up repository instructions. That is a useful reminder to inspect your own project setup, but not a universal benchmark: codebase size, instruction length, MCP tools, and measurement methods differ across projects.&lt;/p&gt;

&lt;p&gt;You can inspect your setup in two controlled runs. Measure baseline context using native Claude Code commands and API metadata, modify exactly one reversible context source, and repeat the same request. Then compare token usage, cost, and task correctness.&lt;/p&gt;

&lt;h2&gt;
  
  
  Measure baseline context with built-in commands
&lt;/h2&gt;

&lt;p&gt;You do not need to guess context sizes. Claude Code provides native commands:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;/context&lt;/code&gt; — displays the breakdown of active context: project instructions, connected MCP tools, cached files, and conversation history;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;/cost&lt;/code&gt; — outputs token consumption (input, output, cache) and estimated cost for the current session.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For a separate API workflow, the API Dashboard provides per-request accounting: input tokens, output tokens, cache hits, HTTP status, and actual balance charges.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use one task with a checkable answer
&lt;/h2&gt;

&lt;p&gt;Start with a small read-only query that does not modify files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Find where validateInvoice is defined.
Name the function file and one test that checks an empty amount.
Do not edit anything.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This request produces a clear binary outcome: two correct file paths or a failure.&lt;/p&gt;

&lt;p&gt;Before running, fix the baseline variables:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;identical Git branch and commit revision;&lt;/li&gt;
&lt;li&gt;identical prompt text;&lt;/li&gt;
&lt;li&gt;identical model selection;&lt;/li&gt;
&lt;li&gt;identical project instructions, skills, and MCP tools;&lt;/li&gt;
&lt;li&gt;expected target paths for the function and test.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Run A: record the baseline metrics
&lt;/h2&gt;

&lt;p&gt;Open a fresh session, execute &lt;code&gt;/context&lt;/code&gt; to inspect baseline load, run the test query, and record the metadata:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Field&lt;/th&gt;
&lt;th&gt;Run A&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Request status&lt;/td&gt;
&lt;td&gt;200 OK&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Input tokens&lt;/td&gt;
&lt;td&gt;18,420&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Output tokens&lt;/td&gt;
&lt;td&gt;310&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cache tokens&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cost / charge&lt;/td&gt;
&lt;td&gt;$0.026&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Result&lt;/td&gt;
&lt;td&gt;correct function and test identified&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;These figures illustrate the comparison worksheet and format verified on August 18, 2026 against &lt;a href="https://bettertoken.ai/pricing?utm_source=devto&amp;amp;utm_medium=syndication&amp;amp;utm_campaign=SEO-097&amp;amp;utm_content=claude-code-kontekst-i-usage-diagnostika-tokenov" rel="noopener noreferrer"&gt;current BetterToken pricing&lt;/a&gt;. In your own project, record the live numbers from &lt;code&gt;/cost&lt;/code&gt; or your dashboard.&lt;/p&gt;

&lt;p&gt;Do not include API keys, private source code, full proprietary prompts, or sensitive logs in notes. Metadata, source names, and task outcomes are sufficient.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prioritized diagnostics order
&lt;/h2&gt;

&lt;p&gt;Do not disable all configuration at once. Investigate context sources in priority order:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Project Instructions (&lt;code&gt;CLAUDE.md&lt;/code&gt;)&lt;/strong&gt; — check for outdated build logs, duplicated API specs, and oversized reference blocks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;MCP Servers and Skills&lt;/strong&gt; — disconnect heavy external tools that are not needed for the current isolated task.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Session History&lt;/strong&gt; — ensure old tasks or long terminal outputs are not polluting context (use &lt;code&gt;/compact&lt;/code&gt; or start fresh with a handoff if needed).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;File Read Scope&lt;/strong&gt; — restrict search scope to specific directories if the agent scans the entire repository tree.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Suppose &lt;code&gt;CLAUDE.md&lt;/code&gt; contains a 12,000-line build log. Make one reversible change: move the log to &lt;code&gt;docs/build.log&lt;/code&gt; and keep a concise pointer in &lt;code&gt;CLAUDE.md&lt;/code&gt;. Do not change the model, MCP tools, or prompt at the same time.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run B: repeat the query and compare metrics
&lt;/h2&gt;

&lt;p&gt;Keep the revision, model, and prompt unchanged. After the single modification, rerun the request and complete the A/B comparison table:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Field&lt;/th&gt;
&lt;th&gt;Run A&lt;/th&gt;
&lt;th&gt;Run B&lt;/th&gt;
&lt;th&gt;Difference&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Request status&lt;/td&gt;
&lt;td&gt;200 OK&lt;/td&gt;
&lt;td&gt;200 OK&lt;/td&gt;
&lt;td&gt;Success&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Input tokens&lt;/td&gt;
&lt;td&gt;18,420&lt;/td&gt;
&lt;td&gt;6,180&lt;/td&gt;
&lt;td&gt;-12,240&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Output tokens&lt;/td&gt;
&lt;td&gt;310&lt;/td&gt;
&lt;td&gt;295&lt;/td&gt;
&lt;td&gt;-15&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cache tokens&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;td&gt;0&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Cost / charge&lt;/td&gt;
&lt;td&gt;$0.026&lt;/td&gt;
&lt;td&gt;$0.009&lt;/td&gt;
&lt;td&gt;-$0.017&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Function found&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;td&gt;unchanged&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Test found&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;td&gt;yes&lt;/td&gt;
&lt;td&gt;unchanged&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;If input tokens dropped but Run B identified the wrong test or ignored a mandatory project constraint, the change degraded performance. Restore the original instruction.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step-by-step verification
&lt;/h2&gt;

&lt;p&gt;Retain configuration changes only when all five criteria are met:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Single variable per test&lt;/strong&gt;: exactly one context source changed.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Maintained accuracy&lt;/strong&gt;: the function and test are correctly located.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Constraint preservation&lt;/strong&gt;: safety, styling, and architectural rules remain enforced.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Usage confirmation&lt;/strong&gt;: &lt;code&gt;/cost&lt;/code&gt; and the dashboard confirm expected metadata changes.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Secondary confirmation&lt;/strong&gt;: the result is reproduced on one more small task.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Compare API usage in BetterToken Dashboard
&lt;/h2&gt;

&lt;p&gt;For your own API workflow, the BetterToken Dashboard displays balance, active model, exact timestamp, HTTP status, input, output, and cache tokens, along with the resulting charge. Match records by timestamps from Runs A and B and record them in your comparison table. The dashboard stores request metadata without storing complete private prompt text or responses.&lt;/p&gt;

&lt;p&gt;BetterToken provides independent Anthropic-compatible API access with pay-as-you-go billing, separate from Claude.ai subscriptions. &lt;a href="https://docs.bettertoken.ai/ai-tools/claude-code?utm_source=devto&amp;amp;utm_medium=syndication&amp;amp;utm_campaign=SEO-097&amp;amp;utm_content=claude-code-kontekst-i-usage-diagnostika-tokenov" rel="noopener noreferrer"&gt;Check the current BetterToken documentation for Claude Code&lt;/a&gt;, generate an API Key in your workspace, and track token usage directly in the dashboard.&lt;/p&gt;

&lt;h2&gt;
  
  
  Diagnostic summary
&lt;/h2&gt;

&lt;p&gt;The purpose of context optimization is removing irrelevant noise without losing essential context. Measure baseline context with &lt;code&gt;/context&lt;/code&gt; and &lt;code&gt;/cost&lt;/code&gt;, adjust one source at a time, verify task accuracy, and cross-reference API usage metadata.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.anthropic.com/en/docs/claude-code" rel="noopener noreferrer"&gt;Claude Code documentation&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.reddit.com/r/ClaudeCode/comments/1vklbtg/my_fresh_claude_code_sessions_were_starting_at/" rel="noopener noreferrer"&gt;User observation about 35K and 13K tokens&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://docs.bettertoken.ai/ai-tools/claude-code?utm_source=devto&amp;amp;utm_medium=syndication&amp;amp;utm_campaign=SEO-097&amp;amp;utm_content=claude-code-kontekst-i-usage-diagnostika-tokenov" rel="noopener noreferrer"&gt;BetterToken Docs: Claude Code&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Originally published on the &lt;a href="https://bettertoken.ai/en/blog/claude-code-context-usage-token-diagnostics/?utm_source=devto&amp;amp;utm_medium=syndication&amp;amp;utm_campaign=SEO-097&amp;amp;utm_content=claude-code-context-usage-token-diagnostics" rel="noopener noreferrer"&gt;BetterToken blog&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;BetterToken provides pay-as-you-go access to AI model APIs through&lt;br&gt;
OpenAI-compatible and Anthropic-compatible endpoints — useful if you are wiring&lt;br&gt;
Claude Code, Codex, or your own tooling to a custom base URL.&lt;br&gt;
See the &lt;a href="https://docs.bettertoken.ai/?utm_source=devto&amp;amp;utm_medium=syndication&amp;amp;utm_campaign=SEO-097&amp;amp;utm_content=claude-code-context-usage-token-diagnostics" rel="noopener noreferrer"&gt;docs&lt;/a&gt; to get started.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>api</category>
      <category>programming</category>
      <category>productivity</category>
    </item>
  </channel>
</rss>
