$ cat ./blog/claude-opus-4-7-breaking-changes.md
Claude Opus 4.7 の破壊的変更と adaptive thinking 実践
Anthropic から Claude Opus 4.7 がリリースされました。1M context をそのまま引き継ぎつつ、temperature / top_p / top_k / budget_tokens が API から削除されるなど破壊的変更が複数。新しい effort 値 xhigh、Task Budgets beta、thinking 表示の変更も含めて、既存コードの移行手順と実践的な使い分けをまとめます。
- author
- r43
- date
- (2026年4月23日)
- reading
- 4 min
- commit
- 719dc21
Anthropic から Claude Opus 4.7(モデル ID claude-opus-4-7)がリリースされました。1M トークン コンテキストはそのまま、価格も 4.6 と同等($5/1M input / $25/1M output)で据え置きですが、API 上の破壊的変更が複数含まれ、4.6 までのコードをそのままアップグレードすると実行時に 400 で落ちるケースがあります。本記事では、破壊的変更と新機能を整理し、移行と活用の実践手順をまとめます。
到達点
- Opus 4.7 でどのパラメータが削除されたか / 残っているかを把握
effort の xhigh と、既存の high / max の使い分け
- 既存の
budget_tokens 前提コードを adaptive thinking に書き換え
- thinking 表示のデフォルト変更と、ストリーミング UI 側の対応
- Task Budgets beta の位置づけと使いどころ
検証環境: 2026-04 時点、@anthropic-ai/sdk v0.90 系、Python SDK も同系列。
1. 破壊的変更 — 送ると 400 で返るもの
まず移行前に削る必要がある項目です。Opus 4.7 に送ると 400 になります(他モデルでは引き続き有効)。
temperature
top_p
top_k
thinking: { type: "enabled", budget_tokens: N }(enabled + 数値指定の形)
- 直前ターンが
assistant で終わる「prefill」(4.6 / Sonnet 4.6 でも 400)
sampling 系 3 つ(temperature / top_p / top_k)は丸ごと削除。budget_tokens はサーバ側で自動決定する adaptive thinking に一本化されました。
2. 置き換え先 — adaptive thinking + effort
Opus 4.7 の思考制御は 2 段で考えるのが素直です。
- adaptive thinking: 思考の「量」を Claude が自己調整する。
thinking: { type: "adaptive" } を指定するだけ
- effort: 応答全体のトークン消費・tool 呼び出し回数・前置きを「どれくらい丁寧に」するかの軸。
output_config: { effort: "..." } に入れる
effort の値は 4 段階から 5 段階 に拡張されました。
| effort | 用途 | Opus 4.7 での位置 |
|---|
low | サブエージェント / 単純タスク / 大量並列 | 既存 |
medium | 軽めの生成 | 既存 |
high | 通常の知的作業のスイートスポット | 既存 (既定値) |
xhigh | コーディング・エージェント実運用の推奨 | 4.7 で追加(Claude Code の既定) |
max | 正確性 > コスト、Opus 系のみ | 既存 |
筆者の運用感としては、コーディング伴走は xhigh 固定が 4.7 世代の基準点になります。max はレビュー・設計判断・バグの根本原因探索で正確性がコストに勝つとき。
3. 移行の具体手順
4.6 時代のコードから Opus 4.7 に乗せ替えるときの書き換え。
// Before (Opus 4.6 / Sonnet 4.6 時代)
await client.messages.create({
model: "claude-opus-4-6",
max_tokens: 16_000,
temperature: 0.3,
thinking: { type: "enabled", budget_tokens: 10_000 },
messages: [...],
});
// After (Opus 4.7)
await client.messages.create({
model: "claude-opus-4-7",
max_tokens: 16_000,
thinking: { type: "adaptive" },
output_config: { effort: "xhigh" },
messages: [...],
});
書き換えのチェックリスト:
temperature / top_p / top_k を削除(残すと 400)
thinking: { type: "enabled", budget_tokens: N } を thinking: { type: "adaptive" } に変更
- 必要に応じて
output_config.effort を指定(未指定なら high)
- 最終メッセージが assistant の prefill になっていないか確認。なっていたら user ターンに巻き直す
4. thinking 表示のデフォルト変更に注意
Opus 4.7 では thinking ブロックのテキストがデフォルトで空になりました(silent change、エラーは出ない)。ストリーミング UI に「考えている間のテキスト」を表示していた場合、アップグレード後に画面が長時間無音になるように見えます。
復旧するには display: "summarized" を明示する必要があります。
thinking: { type: "adaptive", display: "summarized" }
5. Task Budgets beta — 「予算」で agentic ループを自制させる
Opus 4.7 で追加された beta 機能。beta header task-budgets-2026-03-13 と output_config.task_budget を組み合わせます。
await client.beta.messages.create({
betas: ["task-budgets-2026-03-13"],
model: "claude-opus-4-7",
max_tokens: 64_000,
thinking: { type: "adaptive" },
output_config: {
effort: "xhigh",
task_budget: { type: "tokens", total: 100_000 }, // 最小 20_000
},
messages: [...],
});
重要なのは max_tokens との性質差です。max_tokens は「1 レスポンス最大」のハード制限で、Claude 自身はその値を知りません。task_budget は agentic ループ全体のソフト予算で、Claude が残量を見ながら自分で計画を調整します。長時間の tool 連打を自制させたいときに効きます。
6. 使い分けのメンタルモデル
普段使いの目安として、筆者は次のように使い分けています。
- デフォルトは
claude-opus-4-7 + adaptive + xhigh — Claude Code や自作エージェントの伴走
- サブエージェントは Haiku 4.5 +
low(main のキャッシュを守るため別モデル)
- 正確性命の場面 — レビュー・設計・重要バグの調査は
max
- 長時間 agentic ループ —
task_budget を 100K〜200K で明示
料金は Opus 4.6 / 4.7 とも同じ($5 / $25 per M tokens)なので、4.7 に寄せる上でコスト面の追加考慮はありません。移行コストは上記の API 書き換えのみです。
落とし穴
budget_tokens を 4.7 に送って 400 が返るのは移行漏れのサイン。Sonnet 4.6 / Opus 4.6 までは互換で動くので、モデルだけ上げてパラメータを整理しなかったケースで発生
temperature を CI のテストコード側に残す — fixture 系で temperature: 0 を送っていると 4.7 で落ちる。プロジェクト全体を grep しておく
- 思考の可視化が消えて UI が無言化 —
display: "summarized" を足す。エンドユーザー向けでない内部ツールなら "omitted"(デフォルト)のままで OK
- サブエージェントまで 4.7 にしない — main だけ 4.7、探索は Haiku 4.5 に寄せる構成がキャッシュ効率の上でも合理的
- Task Budgets の最小 20,000 トークン を満たさず指定して 400
まとめ
Opus 4.7 への移行は「削るべきパラメータを削り、adaptive + effort に寄せる」で大半が済みます。破壊的変更は sampling 系 3 つと budget_tokens、それと prefill の 4 種類が中心で、ドメインロジックに手を入れる必要はありません。新しい xhigh は Claude Code の既定でもあり、コーディング伴走の標準点として推奨されます。
次回以降、Anthropic のリリースが入るたびに同じ release notes タグで続報を出していきます。次は Claude Managed Agents ベータ を予定しています。
参考
$ tree ./repo/
記事で登場したコードをひとつの最小リポジトリとしてまとめました。ファイルツリーから切り替えて、全体の構造をそのまま確認できます。
┌─claude-opus-4-7-breaking-changes──────────files08──────────────────────●●●─┐$cat./package.jsonjson
# このファイルを .env にコピーして値を入れる
# https://console.anthropic.com/settings/keys
ANTHROPIC_API_KEY=
# opus-4-7-migration-starter
Claude Opus 4.6 / Sonnet 4.6 世代の API 呼び出しコードを **Claude Opus 4.7** に移行するための最小リファレンス集。
[記事本文](https://r43lab.com/blog/claude-opus-4-7-breaking-changes) と対になります。
## 含まれるもの
- `src/before.ts` — Opus 4.6 時代のコード(`temperature` / `budget_tokens` 入り)
- `src/after.ts` — Opus 4.7 向けに書き直した等価コード
- `src/with-task-budgets.ts` — Task Budgets beta(`task-budgets-2026-03-13`)を使う例
- `src/subagent-split.ts` — main は Opus 4.7 xhigh、探索は Haiku 4.5 low、という使い分け例
## Quick start
```bash
bun install
cp .env.example .env # ANTHROPIC_API_KEY を入れる
# 移行前後の差分を動かして usage を比較
bun run src/before.ts
bun run src/after.ts
# Task Budgets の動作確認
bun run src/with-task-budgets.ts
```
## チェックリスト(Opus 4.6 → 4.7)
- [ ] `temperature` / `top_p` / `top_k` を削除
- [ ] `thinking: { type: "enabled", budget_tokens }` → `thinking: { type: "adaptive" }`
- [ ] 既定 effort が `high` で問題ないか確認、エージェント伴走なら `xhigh` を検討
- [ ] ストリーミング UI は `thinking.display: "summarized"` を明示(何も表示されない問題の対処)
- [ ] fixture や CI テストに `temperature: 0` 等が埋まっていないか grep
- [ ] 最後のメッセージが assistant で終わる prefill 型の会話組み立てを改める
{
"name": "opus-4-7-migration-starter",
"private": true,
"type": "module",
"scripts": {
"before": "bun src/before.ts",
"after": "bun src/after.ts",
"budgets": "bun src/with-task-budgets.ts",
"subagent": "bun src/subagent-split.ts"
},
"dependencies": {
"@anthropic-ai/sdk": "^0.90.0"
},
"devDependencies": {
"@types/bun": "^1.3.0",
"typescript": "^6.0.3"
}
}
/**
* after.ts — Opus 4.7 向けに移行した等価コード
*
* 変更点:
* - model: claude-opus-4-6 → claude-opus-4-7
* - temperature / top_p を削除 (4.7 で 400)
* - thinking: "enabled" + budget_tokens → "adaptive" (4.7 では budget_tokens 不可)
* - output_config.effort で応答のきめ細かさを指定
* - 思考内容を UI に流すなら thinking.display: "summarized" を明示
*/
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
async function main() {
const res = await client.messages.create({
model: "claude-opus-4-7",
max_tokens: 8_000,
thinking: {
type: "adaptive",
// UI に思考経過を出したい場合のみ明示 (4.7 のデフォルトは "omitted")
display: "summarized",
},
output_config: {
// "xhigh" は Opus 4.7 で追加。Claude Code でも採用されている実装向け推奨値。
effort: "xhigh",
},
system: "You are a senior TypeScript reviewer. Reply in Japanese, 300 chars max.",
messages: [
{ role: "user", content: "次の型定義の是非を教えて: `type User = { id: any; name: string }`" },
],
});
for (const block of res.content) {
if (block.type === "text") console.log("[answer]", block.text);
if (block.type === "thinking") console.log("[thinking]", block.thinking);
}
console.log("\nusage:", res.usage);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
/**
* before.ts — Opus 4.6 / Sonnet 4.6 までの典型的な呼び出し
*
* このまま `model` だけ `claude-opus-4-7` に書き換えると、
* temperature / budget_tokens が 400 で弾かれる。
* 移行後の姿は src/after.ts を参照。
*/
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
async function main() {
const res = await client.messages.create({
model: "claude-opus-4-6",
max_tokens: 8_000,
// ↓ これらは Opus 4.7 ではすべて削除対象
temperature: 0.3,
top_p: 0.9,
thinking: { type: "enabled", budget_tokens: 10_000 },
// ──
system: "You are a senior TypeScript reviewer. Reply in Japanese, 300 chars max.",
messages: [
{ role: "user", content: "次の型定義の是非を教えて: `type User = { id: any; name: string }`" },
],
});
for (const block of res.content) {
if (block.type === "text") console.log(block.text);
}
console.log("\nusage:", res.usage);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
/**
* subagent-split.ts — main は Opus 4.7 xhigh、探索サブは Haiku 4.5 low
*
* 同じ main session に複数モデルの呼び出しが混ざると prompt cache が
* 割れるため、メインの会話は Opus 4.7 に固定し、並列探索やログ要約は
* 別 process (= ここでは別呼び出し) で Haiku 4.5 に逃がす。
*/
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
/** 並列に走らせる軽量リサーチ(Haiku 4.5 + low effort) */
async function quickScout(query: string) {
const res = await client.messages.create({
model: "claude-haiku-4-5",
max_tokens: 1_000,
output_config: { effort: "low" },
system: "You are a quick scout. Return 1-2 bullets, no preamble.",
messages: [{ role: "user", content: query }],
});
return res.content
.filter((b) => b.type === "text")
.map((b) => (b as { text: string }).text)
.join("\n");
}
/** 本番の判断は Opus 4.7 + xhigh */
async function plan(notes: string[]) {
const res = await client.messages.create({
model: "claude-opus-4-7",
max_tokens: 16_000,
thinking: { type: "adaptive" },
output_config: { effort: "xhigh" },
system:
"You are the senior engineer. Integrate the scout notes and propose a 1-paragraph plan.",
messages: [
{
role: "user",
content: `Scout notes:\n${notes.map((n, i) => `#${i + 1}\n${n}`).join("\n\n")}`,
},
],
});
return res.content
.filter((b) => b.type === "text")
.map((b) => (b as { text: string }).text)
.join("\n");
}
async function main() {
// 並列 Haiku で外観情報を集める
const scouts = await Promise.all([
quickScout("Cloudflare Workers で OAuth を組むのに向く OSS は?"),
quickScout("Hono + Cloudflare の代表的な認証テンプレ構成は?"),
quickScout("Better Auth と Clerk の棲み分けを 1 行で"),
]);
// 統合判断は Opus 4.7
const decision = await plan(scouts);
console.log("--- final plan ---\n" + decision);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
/**
* with-task-budgets.ts — Task Budgets beta の最小例
*
* Task Budget は max_tokens と違い、Claude 自身が残量を把握しながら
* agentic loop を自制する「予算」。長時間の tool 連打や検索マラソンを
* 計画的に打ち切らせたいときに効く。
*
* beta header: task-budgets-2026-03-13
* 最小 total: 20_000
*/
import Anthropic from "@anthropic-ai/sdk";
const client = new Anthropic();
async function main() {
const res = await client.beta.messages.create({
betas: ["task-budgets-2026-03-13"],
model: "claude-opus-4-7",
max_tokens: 64_000,
thinking: { type: "adaptive" },
output_config: {
effort: "xhigh",
task_budget: {
type: "tokens",
total: 100_000, // 最小 20_000
},
},
system:
"You are a research assistant. When unsure, say 'I don't know'. Keep final answer <= 400 chars.",
messages: [
{
role: "user",
content:
"Anthropic が最近公開した agent 関連 API のうち、beta のままのものを 3 つ、各 1 行で挙げて。",
},
],
});
for (const block of res.content) {
if (block.type === "text") console.log(block.text);
}
console.log("\nusage:", res.usage);
}
main().catch((err) => {
console.error(err);
process.exit(1);
});
{
"compilerOptions": {
"target": "ES2022",
"module": "ESNext",
"moduleResolution": "Bundler",
"lib": ["ES2022"],
"types": ["bun"],
"strict": true,
"noEmit": true,
"skipLibCheck": true,
"isolatedModules": true,
"verbatimModuleSyntax": true
},
"include": ["src/**/*"]
}