Claude CodeでOpus 4、Sonnet 4以外の旧モデルを使う方法

Claude CodeでOpus 4、Sonnet 4以外の旧モデルを使う方法

Clock Icon2025.06.20

はじめに

最近はCursorからClaude Codeに移行して業務活用を進めています。
Claude Code内で指定できるモデルはOpus 4かSonnet 4だけだと思っていたのですが、旧モデルも指定することができたので設定方法をご紹介します。
公式ドキュメントにはalias for the latest model (sonnet or opus)の記載はあるものの、実際にはClaude 3.5 Haiku等もモデルも指定可能でした。

先に結論

  • CLIの--modelオプションか対話型REPLの/modelでモデルIDを指定すると変更可能
  • サブスクリプション(Pro/Max)利用、API利用のどちらでも設定可能

モデルの変更

モデルの選択は大きく二つの方法があります。
対話型REPLの場合は/modelのコマンドで使うモデルを選択でき、モデルのaliasかフルネームを指定することでCustomでモデルが設定できます。

https://docs.anthropic.com/en/docs/claude-code/slash-commands#built-in-slash-commands

claude --model claude-sonnet-4-20250514のようにCLIのオプションでも上記と同様に指定可能です。

https://docs.anthropic.com/en/docs/claude-code/cli-reference#cli-flags

対話型REPLの場合

/model <model-id>

## 実際の実行例
> /model claude-3-5-haiku-20241022
  ⎿  Set model to claude-3-5-haiku-20241022

> /model
╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                                                                                                                         │
│  Select Model                                                                                                                                                                                           │
│  Switch between Claude models. Applies to this session and future Claude Code sessions. For custom model names, specify with --model.                                                                   │
│                                                                                                                                                                                                         │
│     1. Default (recommended)      Use the default model (currently Sonnet 4) · $3/$15 per Mtok                                                                                                          │
│     2. Opus                       Opus 4 for complex tasks · $15/$75 per Mtok                                                                                                                           │
│   ❯ 3. claude-3-5-haiku-20241022  Custom model✔                                                                                                                                                         │
│                                                                                                                                                                                                         │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
 Enter to confirm · Esc to exit

CLIのオプションの場合

claude --model <model-id>

## 実際の実行例
claude --model claude-3-5-haiku-20241022      
╭───────────────────────────────────────────────────╮
│ ✻ Welcome to Claude Code!                         │
│                                                   │
│   /help for help, /status for your current setup  │
│                                                   │
│   cwd: /Users/user-name/claude-code      │
╰───────────────────────────────────────────────────╯

 ※ Tip: Create custom slash commands by adding .md files to .claude/commands/ in your project or ~/.claude/commands/ for commands that work in any project
╭─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│                                                                                                                                                                                                         │
│  Select Model                                                                                                                                                                                           │
│  Switch between Claude models. Applies to this session and future Claude Code sessions. For custom model names, specify with --model.                                                                   │
│                                                                                                                                                                                                         │
│     1. Default (recommended)      Use the default model (currently Sonnet 4) · $3/$15 per Mtok                                                                                                          │
│     2. Opus                       Opus 4 for complex tasks · $15/$75 per Mtok                                                                                                                           │
│   ❯ 3. claude-3-5-haiku-20241022  Custom model✔                                                                                                                                                         │
│                                                                                                                                                                                                         │
╰─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
 Enter to confirm · Esc to exit

API利用の場合に限りますが、/costコマンドで実際に指定モデルが使われたような記録が確認できます。

> /cost 
  ⎿  Total cost:            $0.0645
     Total duration (API):  9.7s
     Total duration (wall): 1m 55.1s
     Total code changes:    0 lines added, 0 lines removed
     Token usage by model:
         claude-3-5-haiku:  792 input, 95 output, 0 cache read, 0 cache write

試したけどダメだった例

ドキュメントに以下の記載があったので、それっぽいaliasを設定してみましたがAPI Errorになりました。

Sets the model for the current session with an alias for the latest model (sonnet or opus) or a model's full name
引用:https://docs.anthropic.com/en/docs/claude-code/cli-reference#cli-flags

> /model Haiku
  ⎿  Set model to Haiku (haiku)

> hello
  ⎿  API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"system: Invalid model name"}}

> /model 3.5 Haiku
  ⎿  Set model to 3.5 Haiku (3.5 haiku)

> hello
  ⎿  API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"system: Invalid model name"}}

上記補足ですが、OpusとSonnetはClaude 4系のモデルがaliasになっているようで問題なく動作しました。

> /model Opus
  ⎿  Set model to Opus (claude-opus-4-20250514)

> hello

⏺ Hello! How can I help you today?

> /model Sonnet
  ⎿  Set model to Sonnet (claude-sonnet-4-20250514)

> hello

⏺ Hello! How can I help you today?

まとめ

今回はClaude CodeでOpus4、Sonnet4以外の旧モデルを使用する方法をご紹介しました。
単純作業はHaiku等の安価なモデルを活用して、タスク内容に応じてモデルを切り替えましょう。
Claude 3.7 Sonnet等の旧モデルに最適化したプロンプトしか持ち合わせていない場合も有用かもしれませんね。
どなたかの参考になれば幸いです。

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.

OSZAR »