AIFCC
記事一覧へ
claude-setupclaude-workflowharness-design

Claude Codeのトークン無駄遣いを防ぐ全ガイド

34542
最近、Claudeのプランに大きな変化があるという声が多く、プランのコスパが悪くなったか、プランに影響する大きなバグがあるかのどちらかを指摘する人が増えている。 読み始める前に、このページをブックマークしておくといい。Claude使用コスト効率化戦略を完全に実装していく中で、何度か戻って読みたくなるはずだ。 トークンを無駄にせず、より多く作り、より多く生み出せるようになる。 なぜClaudeが突然プランユーザーに与えるトークンが少なくなったように感じるのか、その主な理由を特定するために多くの調査をした。 一部はプロンプトキャッシングのバグに関係しているかもしれないが、実際にトークンの無駄を防げる場所は多い。さらに、これらのシステムが実際にどのように機能するかについての基礎知識を持っている人はほとんどいない。 たとえば、この記事を調査中に、プロンプトに画像を追加するとキャッシュが壊れることがわかった。 多くの人がUIやUXにClaudeを使い、常に画像を提供しているが、それがプロンプトキャッシュを壊している。キャッシュされたプロンプトは通常、通常のプロンプトコストの10%しかかからない。 しかしキャッシュするには元のベース入力価格の25%かかる。 だから100万トークンが5ドルなら、キャッシュするために文字通り6.25ドル払い、0.5ドルで使えるようにする。しかしプロンプトキャッシングが壊れると、毎回また6.25ドルかかる。 プランを使っていても、プロンプトキャッシングは影響する。だから、プロンプトキャッシングを壊さない方法を知ることが本当に重要だ。 また、100万コンテキストウィンドウはメモリに関して助けよりも問題を増やした。この記事の残りでその点と、そちら側からの漏れも実際に解決できる方法について説明する。 このガイドは5つのレベルで構成されている。 --- TL;DR — 最も影響力の高い5つのヒント これだけ読むなら、この5つをやれ。最小限の努力で請求額を50%以上削減できる。 1. シンプルなタスクにはHaiku 4.5を使う(入力/出力 / per MTok。Sonnetの/と比べて)。ほとんどの分類、抽出、ルーティングタスクに大きなモデルは不要。 2. プロンプトキャッシングを有効にする。リクエストに "cache_control": {"type": "ephemeral"} を追加する。キャッシュ済み読み取りは標準入力価格の0.1倍。つまり90%オフ。 3. 急がない作業にはBatch APIを使う。全トークンに50%割引。キャッシングと組み合わせると最大95%の節約。 4. シンプルなタスクにはeffortパラメータをlowに設定する。Claudeは深い推論をスキップして少ないトークンで応答する。速くて安い。 5. タスク間でコンテキストをクリアする。フォローアップメッセージのたびに会話全体が再処理される。10回のやり取りで、気づかないうちにトークン消費が10倍になる可能性がある。 では、完全な解説へ。 --- レベル1:無料で得られる改善 実装に2分。ゼロ努力。一度やれば永久に節約できる。 ヒント1. まずHaikuを使え。本気で。 Haiku 4.5:/ per MTok。Sonnet 4.6:/。Opus 4.6:/。 分類、抽出、ルーティング、要約、シンプルなQ&Aには、Haikuで十分。3〜5倍節約できる。ほとんどの開発者は品質の違いに気づかずに、日常タスクの60〜70%でHaikuを使える。 ヒント2. effortパラメータを使う。 Claude Opus 4.6とSonnet 4.6はeffortレベル(low、medium、high、max)をサポートしている。effortが低いほど推論のトークンが少なくなる。シンプルなタスクにはlowでレイテンシとコストの両方が劇的に削減される。 json: { "thinking": {"type": "adaptive"}, "effort": "low" } ヒント3. 不要なときはextended thinkingを無効にする。 Extended thinkingのトークンは出力トークンとして課金される。デフォルトのバジェットはリクエストごとに数万トークンになる可能性がある。シンプルな検索、フォーマット、分類タスクなら、thinkingを完全にオフにする。 ヒント4. 複雑なタスクのthinkingバジェットに上限を設ける。 thinkingが必要なときは、budget_tokensを合理的な上限に設定する。多くのタスクには8,000〜16,000のthinkingトークンで十分。日付をフォーマットするために10万トークンの推論は必要ない。 ヒント5. thinkingブロックにdisplay: "omitted"を使う。 アプリがClaudeの推論をユーザーに表示しない場合、thinkingのdisplayをomittedに設定する。これにより出力品質に影響せずにfirst-tokenまでの時間が短縮される。thinkingトークンの費用は払うが、ストリーミングのオーバーヘッドをスキップできる。 ヒント6. プロンプトに単語数または行数の制限を設ける。 「50文字以内で答えて」や「最大3つの箇条書きで」は出力トークンを直接削減する。Claudeはこれらの制約を遵守する。長さについての短い指示=短い(安い)応答。 ヒント7. 出力形式を明示的に制限する。 「name、status、scoreをキーとするJSONオブジェクトを返して。説明不要。」は常に「これを分析してあなたの考えを聞かせて」より安い。オープンエンドなプロンプトはオープンエンドな(高い)応答を生む。 --- レベル2:プロンプトアーキテクチャ 構造化に5分。プロンプトの書き直しが必要だが、即座に効果がある。 ヒント8. 直接的に書く。丁寧な挨拶を省く。 「こんにちは、Claude!お元気ですか。ちょっとお聞きしたいことがあるんですが...」はゼロ価値の言葉にトークンを燃やしている。1単語いくらで書いていると思って書け。実際そうなんだから。 代わりに:このJSONをパースして、nameフィールドだけを返して。 ヒント9. 指示を先頭に置く。 最も重要な指示を最初に置く。実際のリクエストを3段落のコンテキストの下に埋めない。Claudeはプロンプトの冒頭部分にアテンションを重く置く。 ヒント10. XMLタグを使った構造化プロンプトを使う。 <instructions>、<context>、<output_format>などのタグがClaudeの意図の把握を速め、より焦点を絞った応答を生む。曖昧さが減ると、Claudeが何を望んでいるか「推測」するための無駄なトークンが減る。 ヒント11. 一度だけ言う。 指示を繰り返してもClaudeがより確実に従うようにはならない。トークンが余分にかかるだけだ。各指示を明確に、一度だけ述べる。 ヒント12. 関連するコンテキストだけを含める。 1つの関数を変更するだけなのに500行のファイルを貼り付けない。関連するセクションだけを貼る。ファイル構造が必要なら、全体をダンプする代わりに1文で説明する。 ヒント13. assistantのプリフィルテクニックを使う。 assistantターンをプリフィルしてClaudeの応答を始める。JSON出力が欲しいなら、{でプリフィルすればClaudeは前文や説明なしでそこから続ける。 json: { "role": "assistant", "content": "{" } ヒント14. JSONキーをプリフィルして前文を完全にスキップする。 これはヒント13の強化版だ。{だけでなく、{"result":でプリフィルするとClaudeは値に直接ジャンプする。毎回トークンを消費する「わかりました!JSONを作成します:」のような前文がなくなる。 ヒント15. 会話履歴からthinkingブロックを除去する。 APIは以前のターンのthinkingブロックを自動的に無視する。ただし、履歴を手動で管理している場合は、これらを戻さないようにする。ゼロ利益で入力トークン数が膨らむ。 ヒント16. 送信前にtoken counting APIを使う。 Anthropicには推論を実行せずにリクエストの正確なトークン数を返すエンドポイントがある。予想外に大きいプロンプトが高くつく前に発見するために使う。リクエストが突然高くなった理由のデバッグに最適。 --- レベル3:キャッシングのマスタリー 適切に設定するのに10分。これが本当に節約できる場所だ。 プロンプトキャッシングはClaude APIで最も強力なコスト削減機能の一つだ。キャッシュされた入力トークンは標準入力価格のわずか10%。正しく使う方法と、壊さない方法を説明する。 ヒント17. 自動キャッシングを有効にする。 最も簡単な出発点。リクエストレベルでcache_controlを追加するとシステムがブレークポイントを自動的に処理する。 json: { "model": "claude-sonnet-4-6", "max_tokens": 1024, "cache_control": {"type": "ephemeral"}, "system": "ここにシステムプロンプト...", "messages": [...] } ヒント18. キャッシュ可能なようにプロンプトを構造化する。 Claudeはコンテンツをこの順序で処理する:tools → system prompt → messages。最も安定した再利用可能なコンテンツを先に置く。システムプロンプトとtool定義はリクエスト間でほとんど変わらないため、完璧なキャッシュ候補だ。 ヒント19. 料金の計算を理解する。 キャッシュ書き込み:ベース入力価格の1.25倍(最初のリクエストのみ) キャッシュ読み取り:ベース入力価格の0.1倍(以降すべてのヒット) 1時間キャッシュ:書き込みコスト2倍、読み取りは同じ0.1倍 Sonnet 4.6(入力/MTok)では、キャッシュ読み取りの実質コストは/bin/zsh.30/MTok。同じ1万トークンのシステムプロンプトをすべてのリクエストで送っているなら、キャッシングは2回目の呼び出しで元が取れる。 ヒント20. 粒度の細かい制御のための明示的なキャッシュブレークポイントを使う。 異なる頻度で変わるセクションを持つ複雑なプロンプトには、個々のコンテンツブロックにcache_controlを配置する。最大4つのブレークポイントを使える。 ヒント21. 最小トークン閾値を満たす。 キャッシングはチェックポイントごとに最小トークン数が必要で、モデルによって異なる。 Opus 4.6/4.5:4,096トークン。Sonnet 4.6:2,048トークン。Sonnet 4.5/4:1,024トークン。Haiku 4.5:4,096トークン。 閾値以下だとリクエストは成功するがキャッシュされず、エラーも返らない。レスポンスのcache_creation_input_tokensフィールドを確認してキャッシングが実際に機能したか検証する。 ヒント22. キャッシュを温かく保つ。 デフォルトのTTLは5分で、ヒットのたびにリフレッシュされる。リクエスト間隔が5分を超えるとキャッシュが切れて再び書き込みコストを払う。間隔が長いワークロードには1時間オプションを使う(書き込み2倍、読み取りは引き続き0.1倍)。 定期的に5分を超えるextended thinkingタスクには、1時間キャッシュはほぼ常に元が取れる。 キャッシュを壊す方法(やってはいけないこと) このセクションだけで何時間ものデバッグを節約できる。 ヒント23. リクエストごとに変わるコンテンツにcache_controlを置かない。 これが最も一般的なキャッシングの間違いだ。タイムスタンプ、セッションID、またはユーザーのメッセージを含むブロックにキャッシュブレークポイントを置くと、毎回プレフィックスハッシュが変わり、読み取りゼロですべてのリクエストでキャッシュ書き込みが発生する。1.25倍の書き込みプレミアムを繰り返し払い、節約がない。 ヒント24. 画像を追加したり削除したりしない。 プロンプトのどこかに(キャッシュされたセクションだけでなく)画像を追加したり削除したりするとキャッシュが壊れる。ワークフローで画像がある場合とない場合があるなら、それらを別々のキャッシュライフサイクルを持つ別々のリクエストパターンとして扱う。 ヒント25. キャッシュブレークポイントより前のものを変更しない。 キャッシュは完全なプレフィックスでマッチする。システムプロンプト、tool定義、またはキャッシュされたブロックより前のメッセージの1文字でも変わると、完全なキャッシュミスと再書き込みが強制される。システムプロンプトは慎重にバージョン管理する。 ヒント26. thinkingパラメータを切り替えない。 リクエスト間でextended thinkingのオン/オフを切り替えたり、バジェット割り当てを変更したりすると、メッセージキャッシュブレークポイントが無効になる。キャッシュされたシステムプロンプトとtool定義はthinkingの変更に生き残るが、メッセージレベルのキャッシュは生き残らない。 クイックリファレンス:キャッシュ無効化 キャッシュを壊す:ブレークポイントより前のコンテンツ変更、tool_choiceの変更、画像の追加/削除、thinkingパラメータの変更、TTLの期限切れ キャッシュが生き残る:ブレークポイントより後のメッセージ変更、max_tokensの変更、最後への新規ユーザーメッセージ追加 ヒント27. 並行リクエストに注意する。 キャッシュエントリは最初のレスポンスがストリーミングを始めた後にのみ利用可能になる。同時に10個の並行リクエストを送ると、最初の1つだけがキャッシュに書き込む。他の9つはエントリがまだ存在しないのでキャッシュヒットしない。ファンアウトパターンには、最初のリクエストを送り、ストリーミングが始まるのを待ち、それから残りを送る。 --- レベル4:システム設計 設計に15分。これが趣味と本番チームを分ける決断だ。 ヒント28. モデルルーターを構築する。 すべてのリクエストを同じモデルに送らない。シンプルなタスクはHaikuに、中程度の複雑さはSonnetに、深い推論だけをOpusにエスカレートする。この単一のアーキテクチャ決定が、スケールでは通常最大のコストレバーだ。 ヒント29. 急がない作業にはBatch APIを使う。 全トークン価格に50%割引。24時間以内に結果が出る。バルクコード分析、コンテンツ生成、データ処理、リアルタイム応答が不要なワークロードに最適。プロンプトキャッシングと組み合わせると最大95%の節約。 ヒント30. トークン効率の高いtool useを使う。 Claude 4モデルはすべてデフォルトでトークン効率の高いtool useをサポートしており、出力トークンを平均14%節約できる(最大70%)。Claude 3.7 Sonnetにはベータヘッダーtoken-efficient-tools-2025-02-19を追加する。文字通り無料の節約だ。 ヒント31. 必要なtoolだけを含める。 すべてのtool定義はすべてのリクエストで送られる。15個のtoolが定義されているが特定のタスクに2個しか必要ない場合、毎回のAPIコールで13個の無用なtool定義を払っている。タスクに基づいて動的にtoolをロードする。 ヒント32. 関係ないタスク間でコンテキストをクリアする。 Claude Codeでは、トピックを切り替えるときに/clearを使う。API統合では新しい会話を始める。以前のタスクの古いコンテキストは以降のすべてのメッセージで再処理され、コストが指数関数的に複利で増大する。 ヒント33. 長い会話を要約する。 すべてのリクエストで完全な会話履歴を送る代わりに、定期的に以前のターンを要約に圧縮する。20往復のやり取りを200文字の要約に置き換える。トークン使用量が指数関数的から線形になる。 ヒント34. 関係ないターンを削除する。 マルチターンの会話のすべてのメッセージがコンテキストに残る必要はない。現在のタスクに関係なくなったターンは削除する。一貫性を維持するためにClaudeが必要なものだけを保持する。 ヒント35. 詳細な操作をサブエージェントに委任する。 テストの実行、ドキュメントの取得、ログファイルの処理はコンテキストをトークンで溢れさせる可能性がある。これらをサブエージェントに委任することで、冗長な出力はサブエージェントのコンテキストに留まり、簡潔な要約だけがメイン会話に返る。 Claude Codeでは、エージェントチームは標準セッションより約7倍多くのトークンを使うが、トークンの分離によりプライマリコンテキストがスリムで安いまま保たれる。 正直に言うと、100万コンテキストウィンドウはほとんどのユーザーが気づかないうちにコスト効率の問題を本当に生み出している。このパラドックスについてのClaudeの答えはこうだ: --- レベル5:監視と測定 継続的な規律。測定しないものは最適化できない。 ヒント36. Usage and Cost APIで監視する。 AnthropicのAPIはモデル別、キャッシュヒット/ミス別、トークンタイプ別の使用量を提供する。ダッシュボードを設定する。最もトークンを消費するエンドポイントを見つける。それを先に修正する。 Claude Codeでは、/costを使って現在のセッション使用量を確認するか、ステータスバーを設定して継続的に表示させる。チームにはConsoleでワークスペースの支出制限を設定する。 このオープンソースツールも使える: https://github.com/Maciek-roboblog/Claude-Code-Usage-Monitor --- 最後に: トークン最適化はケチになることではない。賢くなることだ。 最高の製品や自動化を出荷しているチームは、トークンを効率的に使うことを気にしている。本当に重要なことにトークンを使う。 まずレベル1から実装して、上に向かって進んでいこう。多少の作業が必要だが、やり終えれば自分を褒めることができ、創造性と夢の追求のためのトークンが残る。 P.S. この投稿を保存して、ステップバイステップで使い始めよう。
原文を表示 / Show original
Lately, a lot of people have been sharing about a drastic shift in Claude's plans, pointing to either Claude giving less for the buck or to a major bug affecting the plans. Before starting to read, make sure to bookmark this, as you'll wanna come back to this article a few times as you fully implement these Claude usage cost-efficiency strategies. This will help you build & create more and not waste your tokens. I did a lot of research to identify the main reasons why Claude suddenly started feeling like it was giving fewer tokens to plan users. Some of it may be related to a prompt-caching bug, but there are many places where we can actually prevent token waste. Plus, no one is too informed about the basics of how these systems actually work in practice. For example, while researching this article, I found that adding an image to your prompt breaks the cache. Since a lot of people use Claude for UI/UX too, and constantly give images, they are breaking prompt caches, and cached prompts normally cost only 10% of what a regular prompt costs. Yet, to cache it costs 25% of the original base input price. So if a million tokens cost $5, you are literally paying $6.25 to cache it to then use it at $0.5, but if prompt caching breaks, then it costs you again and again, $6.25 per million tokens. Even though you're using Plans, the prompt caching will affect you, too. So it's really important to know how to not break prompt caching. Also, the 1M context window added more problems than it helped with memory, which I will get into in the rest of the article, and how you can actually solve the leaks that is coming from that side too. This guide is organized into five levels: TL;DR -- The 5 Highest-Impact Tips If you read nothing else, do these five things. They'll cut your bill by 50%+ with minimal effort. 1. Use Haiku 4.5 for simple tasks ($1/$5 per MTok vs Sonnet's $3/$15). Most classification, extraction, and routing tasks don't need a bigger model. 2. Enable prompt caching. Add "cache_control": {"type": "ephemeral"} to your request. Cached reads cost 0.1x the standard input price. That's 90% off. 3. Use the Batch API for anything non-urgent. 50% discount on all tokens. Stack it with caching for up to 95% total savings. 4. Set the effort parameter to low for simple tasks. Claude skips deep reasoning and responds with fewer tokens. Faster and cheaper. 5. Clear context between tasks. Every follow-up message reprocesses your entire conversation. A 10-turn chat can silently 10x your token spend. Now, the full breakdown. Level 1: Free Wins 2 minutes to implement. Zero effort. Do these once and save forever. 0:01 / 0:10 Tip 1. Start with Haiku. Seriously. Haiku 4.5: $1/$5 per MTok. Sonnet 4.6: $3/$15. Opus 4.6: $5/$25. For classification, extraction, routing, summaries, and simple Q&A, Haiku handles it. You save 3-5x. Most developers can use Haiku for 60-70% of daily tasks without noticing a quality difference. Tip 2. Use the effort parameter. Claude Opus 4.6 and Sonnet 4.6 support effort levels: low, medium, high, max. Lower effort = fewer tokens on reasoning. For simple tasks, low dramatically cuts both latency and cost. json { "thinking": {"type": "adaptive"}, "effort": "low" } Tip 3. Disable extended thinking when you don't need it. Extended thinking tokens are billed as output tokens. Default budgets can be tens of thousands of tokens per request. If your task is a simple lookup, formatting job, or classification, turn thinking off entirely. Tip 4. Cap thinking budget for complex tasks. When you do need thinking, set budget_tokens to a reasonable limit. For many tasks, 8,000-16,000 thinking tokens is plenty. You don't need 100K tokens of reasoning to format a date. Tip 5. Use display: "omitted" on thinking blocks. If your app doesn't show Claude's reasoning to the user, set thinking display to omitted. This reduces time-to-first-token without affecting output quality. You still pay for thinking tokens, but skip the streaming overhead. Tip 6. Set word or line limits in your prompt. "Respond in under 50 words" or "Give me 3 bullet points max" directly reduces output tokens. Claude respects these constraints. Shorter instructions about length = shorter (cheaper) responses. Tip 7. Constrain output format explicitly. "Return a JSON object with keys: name, status, score. No explanations." will always be cheaper than "Can you analyze this and give me your thoughts?" Open-ended prompts produce open-ended (expensive) responses. Level 2: Prompt Architecture 5 minutes to restructure. Requires some rework on your prompts, but pays off immediately. Tip 8. Be direct. Kill the pleasantries. "Hi Claude! I hope you're doing well. I was wondering if you could possibly help me with..." is burning tokens on zero-value words. Write like you're paying per word. Because you are. Instead: Parse this JSON and return only the name field. Tip 9. Front-load your instructions. Put the most important instruction first. Don't bury your actual request under three paragraphs of context. Claude weights the beginning of the prompt more heavily in its attention. Tip 10. Use structured prompts with XML tags. Tags like <instructions>, <context>, and <output_format> help Claude parse your intent faster and produce more focused responses. Less ambiguity = fewer wasted tokens on Claude "guessing" what you want. Tip 11. Say it once. Repeating instructions doesn't make Claude follow them harder. It just costs you more tokens. State each instruction clearly, one time. Tip 12. Only include relevant context. Don't paste a 500-line file when you only need to modify one function. Paste only the relevant section. If Claude needs the file structure, describe it in a sentence instead of dumping the whole thing. Tip 13. Use the assistant prefill technique. Start Claude's response by pre-filling the assistant turn. If you want JSON output, prefill with { and Claude will continue from there without preamble or explanation. json { "role": "assistant", "content": "{" } Tip 14. Prefill JSON keys to skip preamble entirely. This is Tip 13 on steroids. Instead of just prefilling {, prefill {"result": and Claude will jump straight to the value. Eliminates the "Sure! Here's the JSON:" filler that costs tokens every single time. Tip 15. Strip thinking blocks from conversation history. The API automatically ignores thinking blocks from previous turns. But if you're managing history manually, don't pass them back. They inflate your input token count for zero benefit. Tip 16. Use the token counting API before sending. Anthropic has an endpoint that returns the exact token count of your request without running inference. Use it to catch unexpectedly large prompts before they cost you. Great for debugging why a request suddenly got expensive. Level 3: Caching Mastery 10 minutes to set up properly. This is where the real money is. Prompt caching is one of the most powerful cost-saving features in the Claude API. Cached input tokens cost just 10% of the standard input price. Here's how to use it properly and, critically, how to avoid breaking it. Tip 17. Enable automatic caching. The simplest starting point. Add cache_control at the request level and the system handles breakpoints automatically. json { "model": "claude-sonnet-4-6", "max_tokens": 1024, "cache_control": {"type": "ephemeral"}, "system": "Your system prompt here...", "messages": [...] } Tip 18. Structure prompts for cacheability. Claude processes content in this order: tools → system prompt → messages. Put your most stable, reusable content first. Your system prompt and tool definitions are perfect cache candidates because they rarely change between requests. Tip 19. Understand the pricing math. Cache write: 1.25x base input price (first request only) Cache read: 0.1x base input price (every subsequent hit) 1-hour cache: 2x write cost, same 0.1x read cost On Sonnet 4.6 ($3/MTok input), a cache read costs effectively $0.30/MTok. If you're sending the same 10K-token system prompt on every request, caching pays for itself after the second call. Tip 20. Use explicit cache breakpoints for granular control. For complex prompts with sections that change at different frequencies, place cache_control on individual content blocks. You can use up to 4 breakpoints. json { "role": "system", "content": [ { "type": "text", "text": "Your large static instructions...", "cache_control": {"type": "ephemeral"} } ] } Tip 21. Meet the minimum token threshold. Caching requires a minimum number of tokens per checkpoint, and it varies by model. Opus 4.6/4.5: 4,096 tokens. Sonnet 4.6: 2,048 tokens. Sonnet 4.5/4: 1,024 tokens. Haiku 4.5: 4,096 tokens. Below the threshold, the request succeeds but nothing gets cached and no error is returned. Check the cache_creation_input_tokens field in the response to verify caching actually worked. Tip 22. Keep your cache warm. Default TTL is 5 minutes, refreshed on every hit. If requests are spaced more than 5 minutes apart, the cache expires and you pay the write cost again. For workloads with longer gaps, use the 1-hour option (2x write, reads still 0.1x). For extended thinking tasks that routinely exceed 5 minutes, the 1-hour cache is almost always worth it. How to Break Your Cache (Don't Do These) This section alone will save you hours of debugging. Tip 23. Don't put cache_control on content that changes every request. This is the most common caching mistake. If you place the cache breakpoint on a block that includes a timestamp, session ID, or the user's message, the prefix hash changes every time and you'll get a cache write on every single request with zero reads. You'll pay the 1.25x write premium repeatedly and never see savings. Tip 24. Don't add or remove images. Adding or removing images anywhere in the prompt (not just the cached section) breaks the cache. If your workflow sometimes includes images and sometimes doesn't, treat those as separate request patterns with separate cache lifecycles. Tip 25. Don't modify anything before the cache breakpoint. The cache matches on exact prefix. Even a single character change in your system prompt, tool definitions, or any message before the cached block forces a full cache miss and rewrite. Version your system prompts carefully. Tip 26. Don't toggle thinking parameters. Switching extended thinking on/off or changing the budget allocation between requests invalidates message cache breakpoints. Cached system prompts and tool definitions survive thinking changes, but message-level caches don't. Quick Reference: Cache Invalidation Breaks cache: Changing content before breakpoint, modifying tool_choice, adding/removing images, changing thinking params, TTL expiring Cache survives: Changing messages after breakpoint, changing max_tokens, adding new user messages at the end Tip 27. Watch out for concurrent requests. A cache entry only becomes available after the first response begins streaming. If you fire 10 parallel requests at the same time, only the first one writes to the cache. The other 9 won't get cache hits because the entry doesn't exist yet. For fan-out patterns, send the first request, wait for it to start streaming, then fire the rest. Level 4: System Design 15 minutes to architect. These are the decisions that separate hobbyists from production teams. Tip 28. Build a model router. Don't send every request to the same model. Route simple tasks to Haiku, medium complexity to Sonnet, and only escalate to Opus for deep reasoning. This single architectural decision is usually the biggest cost lever at scale. Tip 29. Use the Batch API for non-urgent work. 50% discount on all token prices. Results within 24 hours. Perfect for bulk code analysis, content generation, data processing, and any workload that doesn't need real-time responses. Stacks with prompt caching for up to 95% total savings. Tip 30. Use token-efficient tool use. All Claude 4 models support token-efficient tool use by default, saving an average of 14% on output tokens (up to 70%). For Claude 3.7 Sonnet, add the beta header token-efficient-tools-2025-02-19. This is literally free savings. Tip 31. Only include the tools you need. Every tool definition gets sent with every request. If you have 15 tools defined but only need 2 for a given task, you're paying for 13 useless tool definitions on every single API call. Load tools dynamically based on the task. Tip 32. Clear context between unrelated tasks. In Claude Code, use /clear when switching topics. In API integrations, start a new conversation. Stale context from previous tasks gets re-processed on every subsequent message, compounding your costs exponentially. Tip 33. Summarize long conversations. Instead of sending the full conversation history with every request, periodically compress earlier turns into a summary. Replace 20 turns of back-and-forth with a 200-word summary. Your token usage goes from exponential to linear. Tip 34. Trim irrelevant turns. Not every message in a multi-turn conversation needs to stay in context. Drop turns that are no longer relevant to the current task. Keep only what Claude needs to maintain coherence. Tip 35. Delegate verbose operations to subagents. Running tests, fetching docs, or processing log files can flood your context with tokens. Delegate these to subagents so the verbose output stays in the subagent's context while only a concise summary returns to your main conversation. In Claude Code, agent teams use roughly 7x more tokens than standard sessions, but the token isolation means your primary context stays lean and cheap. Because let's be real, the 1M context window does really create cost-efficiency issues without most users realizing it. Here is what Claude's answer was about this paradox: Level 5: Monitoring and Measurement Ongoing discipline. You can't optimize what you don't measure. Tip 36. Monitor with the Usage and Cost API. Anthropic's API gives you usage broken down by model, cache hits/misses, and token type. Set up dashboards. Find the endpoints burning the most tokens. Fix those first. In Claude Code, use /cost to check current session usage, or configure your status bar to display it continuously. For teams, set workspace spend limits in the Console. You can use this tool too, which is open source: https://github.com/Maciek-roboblog/Claude-Code-Usage-Monitor Final Notes: Token optimization isn't about being cheap. It's about being smart. The teams shipping the best vibe coded products and automations do care about using their tokens efficiently. They spend tokens on what actually matters. Just start by implementing these from level 1, and work your way up. It will take some work, but once you do, you'll be thanking yourself and have more tokens left for creativity and chasing your dreams. P.S. save this post so you can start using these step by step.

AIFCC — AI Fluent CxO Club

読み書きそろばん、AI。経営者が AI を自分で動かせるようになるコミュニティ。

Claude Codeのトークン無駄遣いを防ぐ全ガイド | AIFCC