メインコンテンツへスキップ
見出し画像

Claude Codeのトークン節約術。賢さを落としすぎず、うまく節約する方法

    Claude Codeを使っていると、気になるのがトークン消費です。

    特に、

    • 普段の軽い修正

    • ちょっとした記事の下書き

    • README更新

    • 仕様書の整理

    のような作業では、毎回フルパワーで殴る必要はありません。
    高級な包丁で段ボールを開けるようなものです。切れるけど、少しもったいない。

    今回は、Anthropic公式の情報をもとに、Claude Codeで賢さを大きく落としすぎずに、トークンを節約する考え方を2つ紹介します。


    1. Sonnetをmedium effortで使い、必要な時だけOpus advisorに相談する

    Claude Codeには、通常モデルとは別に、難しい判断の時だけ相談役を呼ぶ advisor という仕組みがあります。
    チャットで「/advisor」と入力します。

    /advisor
    画像

    アドバイザーを選べます。

    画像

    このとき便利なのが、

    • 通常モデル: Sonnet

    • effort: Medium

    • advisor: Opus

    という組み合わせです。
    チャットで「/model」と入力すると通常使うモデルを選べます。

    /model


    画像
      Select model
      Switch between Claude models. Applies to this session and future Claude Code sessions. For other/previous model names,
      specify with --model.
    
      > 1. Default (recommended) √  Sonnet 4.6 · Best for everyday tasks
        2. Sonnet (1M context)      Sonnet 4.6 with 1M context · Billed as extra usage · $3/$15 per Mtok
        3. Opus                     Opus 4.6 · Most capable for complex work · ~2× usage vs Sonnet
        4. Opus (1M context)        Opus 4.6 with 1M context · ~2× usage vs Sonnet · Billed as extra usage · $5/$25 per Mtok
        5. Haiku                    Haiku 4.5 · Fastest for quick answers
    
      ◐ Medium effort (default) ← → to adjust

    ポイントは、普段は軽めに回しつつ、詰まった時だけ上位モデルの判断を借りることです。

    これなら、最初から常に重いモデルで走らせるよりも、全体の消費を抑えやすくなります。

    感覚としてはこうです。

    • 日常の作業はSonnetが担当

    • 難所だけOpus先輩を呼ぶ

    つまり、全部を社長決裁にしない運用です。現場がちゃんと回る会社っぽい。

    どういう時に向いているか

    この構成は、たとえばこんな作業に向いています。

    • 仕様書を読みながらの実装

    • 複数ファイルにまたがる修正

    • エラー原因が少し曖昧なデバッグ

    • GitHub Pages やブログ自動化の調整

    • 「軽すぎるモデルだと不安だけど、常時Opusは重い」と感じる作業

    逆に、完全に軽作業だけならHaikuでも足りることがあります。


    実際の使い分け

    私なら、こんな感じで分けます。

    軽作業

    • Haiku

    • advisorなし、または必要時のみ

    用途:

    • 文言修正

    • README更新

    • 単純な整形

    • 軽い調査メモ

    普段の開発

    • Sonnet

    • effort: Medium

    • advisor: Opus


    画像

    用途:

    • 普通の実装

    • リファクタ

    • 仕様確認しながらの修正

    • バグ調査

    重い作業

    • Opus

    • 必要に応じて1M context

    用途:

    • 大規模設計変更

    • かなり複雑な原因調査

    • 長い仕様書をまたぐ判断

    • 重要なレビュー


    大事なのは「全部を最強設定にしない」こと

    AIを使っていると、つい

    「どうせなら一番強いモデルを常に使ったほうがいいのでは?」

    と思いがちです。

    でも実際には、毎回最強設定にするよりも、

    • 普段は軽く回す

    • 難しい時だけ強い判断を借りる

    • 出力は必要十分に短くする

    という運用のほうが、ずっと現実的です。

    これはAIの節約術というより、むしろ仕事の回し方そのものに近いと思います。

    全部を重役会議にすると、たしかに立派ですが、昼までに何も終わらないんですよね。


    まとめ

    Claude Codeでトークンを節約したいなら、まず意識したいのはこの2つです。

    • Sonnetをmedium effortで動かし、必要な時だけOpus advisorに相談する

    これを知っておくだけでも、
    「賢さをなるべく保ちながら、無駄な消費を減らす」
    という運用がしやすくなります。

    Claude Codeは、ただ強いモデルを選ぶだけではなく、どう組み合わせるかでかなり使い勝手が変わります。

    節約はケチではなく、設計です。
    AI運用でもそこは同じだな、と感じます。

    実際にadviserが発動した例

    ● Advising using Opus 4.6
      ⎿  You're at the right point to get advice — spec read, approach chosen, no code written yet. Here's what matters:
    
         **Data file path is the #1  exe gotcha.** When PyInstaller bundles `--onefile`, `__file__` points inside a temp
         extraction dir. The JSON data file must live next to the exe, not next to the script. Use this pattern:
    
         ```python
         import sys, os
         if getattr(sys, 'frozen', False):
             APP_DIR = os.path.dirname(sys.executable)
         else:
             APP_DIR = os.path.dirname(os.path.abspath(__file__))
         DATA_FILE = os.path.join(APP_DIR, "alarms.json")
         ```
    
         **Threading + tkinter will crash if you touch widgets from the alarm thread.** The checker thread must not call
         any widget methods directly. Use `root.after(0, callback)` to schedule notification popups back on the main
         thread. Alternatively, skip threading entirely and use `root.after(1000, check_alarms)` as a recurring timer —
         simpler and avoids the problem altogether. For an app checking every 1-5 seconds, `after()` is the right tool.
    
         **Spec constraints to wire in explicitly:**
         - Daily alarms: track `last_triggered_date`, compare to `date.today()` before firing. This prevents double-fire.
         - One-time alarms: set `done=True` after firing, never fire again.
         - On startup: compare alarm time to `datetime.now()` — if already past, don't fire. For daily alarms this means:
         if `last_triggered_date` is already today, skip.
         - Notification window: `attributes('-topmost', True)` and no auto-dismiss. User clicks close.
    
         **PyInstaller command:**
         ```
         pip install pyinstaller
         pyinstaller --onefile --windowed --name "静かなアラーム時計" clock.py
         ```
         `--windowed` suppresses the console window. The exe lands in `dist/`.
    
         **One file is fine** for this scope. Don't split into modules — it complicates the PyInstaller build for no
         benefit.
    
         **Include the "minutes before" feature** (spec 4-1) — the spec calls it "かなり便利" and it's trivial to
         implement (subtract timedelta from the input time, format the message). It'll make the app feel complete.
    
                                                                                          12:42 PM claude-sonnet-4-6
    ● 良いアドバイスをもらいました。実装します。
     
     
    猫好きプログラマ。半導体会社の技術者 Q&AサイトのQuoraでフォロワー数6000人の「ChatGPT情報交換所」を主宰する程生成AI好き ポートフォリオ https://hantani-portfolio.pages.dev/

    あなたへのおすすめ