Open History to see the last commit
1import { query, type SDKMessage, type ThinkingConfig } from "@anthropic-ai/claude-agent-sdk";
2
3type ProbeCase =
4 | "default"
5 | "effort-low"
6 | "effort-high"
7 | "settings-off"
8 | "settings-on"
9 | "thinking-disabled"
10 | "thinking-enabled";
11
12function parseArgs(argv: ReadonlyArray<string>): {
13 readonly model: string;
14 readonly cwd?: string;
15 readonly prompt: string;
16 readonly cases: ReadonlyArray<ProbeCase>;
17} {
18 let model = "claude-haiku-4-5";
19 let cwd: string | undefined;
20 let prompt =
21 "Think step by step about this before answering: what is 27 multiplied by 43? Return the final number only.";
22 let cases: ReadonlyArray<ProbeCase> = [
23 "default",
24 "effort-low",
25 "effort-high",
26 "settings-off",
27 "settings-on",
28 "thinking-disabled",
29 "thinking-enabled",
30 ];
31
32 for (let index = 0; index < argv.length; index += 1) {
33 const value = argv[index];
34 if (!value) {
35 continue;
36 }
37 if (value === "--model") {
38 model = argv[index + 1] ?? model;
39 index += 1;
40 continue;
41 }
42 if (value === "--cwd") {
43 cwd = argv[index + 1] ?? cwd;
44 index += 1;
45 continue;
46 }
47 if (value === "--prompt") {
48 prompt = argv[index + 1] ?? prompt;
49 index += 1;
50 continue;
51 }
52 if (value === "--cases") {
53 const next = argv[index + 1];
54 if (next) {
55 const requested = next
56 .split(",")
57 .map((entry) => entry.trim())
58 .filter(
59 (entry): entry is ProbeCase =>
60 entry === "default" ||
61 entry === "effort-low" ||
62 entry === "effort-high" ||
63 entry === "settings-off" ||
64 entry === "settings-on" ||
65 entry === "thinking-disabled" ||
66 entry === "thinking-enabled",
67 );
68 if (requested.length > 0) {
69 cases = requested;
70 }
71 }
72 index += 1;
73 }
74 }
75
76 return {
77 model,
78 prompt,
79 ...(cwd ? { cwd } : {}),
80 cases,
81 };
82}
83
84function caseOptions(caseName: ProbeCase): {
85 readonly label: ProbeCase;
86 readonly effort?: "low" | "high";
87 readonly settings?: { alwaysThinkingEnabled: boolean };
88 readonly thinking?: ThinkingConfig;
89} {
90 switch (caseName) {
91 case "effort-low":
92 return {
93 label: caseName,
94 effort: "low",
95 };
96 case "effort-high":
97 return {
98 label: caseName,
99 effort: "high",
100 };
101 case "settings-off":
102 return {
103 label: caseName,
104 settings: {
105 alwaysThinkingEnabled: false,
106 },
107 };
108 case "settings-on":
109 return {
110 label: caseName,
111 settings: {
112 alwaysThinkingEnabled: true,
113 },
114 };
115 case "thinking-disabled":
116 return {
117 label: caseName,
118 thinking: {
119 type: "disabled",
120 },
121 };
122 case "thinking-enabled":
123 return {
124 label: caseName,
125 thinking: {
126 type: "enabled",
127 budgetTokens: 1024,
128 },
129 };
130 default:
131 return {
132 label: caseName,
133 };
134 }
135}
136
137type ProbeSummary = {
138 readonly case: ProbeCase;
139 readonly model: string;
140 initModelInfo: {
141 value: string | null;
142 supportsEffort: boolean | null;
143 supportsAdaptiveThinking: boolean | null;
144 supportedEffortLevels: ReadonlyArray<string> | null;
145 } | null;
146 resultSubtype: string | null;
147 resultText: string | null;
148 assistantThinkingBlockCount: number;
149 streamThinkingEventTypes: Record<string, number>;
150 error: string | null;
151};
152
153async function runCase(input: {
154 readonly caseName: ProbeCase;
155 readonly model: string;
156 readonly cwd?: string;
157 readonly prompt: string;
158}): Promise<ProbeSummary> {
159 const caseConfig = caseOptions(input.caseName);
160 const summary: ProbeSummary = {
161 case: input.caseName,
162 model: input.model,
163 initModelInfo: null,
164 resultSubtype: null,
165 resultText: null,
166 assistantThinkingBlockCount: 0,
167 streamThinkingEventTypes: {},
168 error: null,
169 };
170
171 try {
172 const messages = query({
173 prompt: input.prompt,
174 options: {
175 model: input.model,
176 ...(input.cwd ? { cwd: input.cwd } : {}),
177 persistSession: false,
178 tools: [],
179 permissionMode: "bypassPermissions",
180 includePartialMessages: true,
181 maxTurns: 1,
182 ...(caseConfig.effort ? { effort: caseConfig.effort } : {}),
183 ...(caseConfig.settings ? { settings: caseConfig.settings } : {}),
184 ...(caseConfig.thinking ? { thinking: caseConfig.thinking } : {}),
185 },
186 });
187
188 const initialization = await messages.initializationResult();
189 const initModel =
190 initialization.models.find((candidate) => candidate.value === input.model) ??
191 initialization.models.find((candidate) => candidate.value.includes("haiku")) ??
192 null;
193 summary.initModelInfo = initModel
194 ? {
195 value: initModel.value,
196 supportsEffort: initModel.supportsEffort ?? null,
197 supportsAdaptiveThinking: initModel.supportsAdaptiveThinking ?? null,
198 supportedEffortLevels: initModel.supportedEffortLevels ?? null,
199 }
200 : null;
201
202 for await (const message of messages) {
203 handleMessage(summary, message);
204 }
205 } catch (error) {
206 summary.error = error instanceof Error ? error.message : String(error);
207 }
208
209 return summary;
210}
211
212function handleMessage(summary: ProbeSummary, message: SDKMessage): void {
213 if (message.type === "stream_event") {
214 const event = message.event as {
215 type?: string;
216 delta?: {
217 type?: string;
218 };
219 };
220 const eventType = event.delta?.type ?? event.type;
221 if (typeof eventType === "string" && eventType.includes("thinking")) {
222 summary.streamThinkingEventTypes[eventType] =
223 (summary.streamThinkingEventTypes[eventType] ?? 0) + 1;
224 }
225 return;
226 }
227
228 if (message.type === "assistant") {
229 for (const block of message.message.content) {
230 if (typeof block?.type === "string" && block.type.includes("thinking")) {
231 summary.assistantThinkingBlockCount += 1;
232 }
233 }
234 return;
235 }
236
237 if (message.type === "result") {
238 summary.resultSubtype = message.subtype;
239 summary.resultText = message.subtype === "success" ? message.result : message.errors.join("\n");
240 }
241}
242
243async function main(): Promise<void> {
244 const args = parseArgs(process.argv.slice(2));
245 const results: ProbeSummary[] = [];
246
247 for (const caseName of args.cases) {
248 results.push(
249 await runCase({
250 caseName,
251 model: args.model,
252 ...(args.cwd ? { cwd: args.cwd } : {}),
253 prompt: args.prompt,
254 }),
255 );
256 }
257
258 console.log(JSON.stringify(results, null, 2));
259}
260
261await main();