Module 1, Lesson 4: Showing Reasoning (Anthropic)
Opt in to thinking summaries with display: summarized and print them next to the answer.
Published: 11/23/2026
Lesson 4: Showing the model's reasoning
In lesson 3 you turned on thinking: { type: "adaptive" }, but the program never showed any of it. Here you print it.
Neither Anthropic nor OpenAI exposes the raw chain of thought. Both return a summary of the reasoning, and you have to ask for it.
The change goes in a copy of lesson 3's file, src/anthropic/basic-chat-with-tools-reasoning.ts. The original stays as it is. Everything not shown here is identical to lesson 3.
1. Ask for summaries
const chat = async (messages: Anthropic.MessageParam[]) => { return client.messages.create({ model: model, max_tokens: 4000, messages, tools, thinking: { type: "adaptive", display: "summarized" }, system: basicTravelSystemPrompt, }); };
The only change is display: "summarized". On Claude 5 models display defaults to "omitted". The response still contains thinking blocks, but their thinking text is an empty string. Without this option your code has nothing to print.
2. Collect the thinking text
const getThinking = (message: Anthropic.Message) => message.content .flatMap((b) => (b.type === "thinking" && b.thinking ? [b.thinking] : [])) .join("\n\n");
Empty blocks are normal. With adaptive thinking the model may decide not to think at all, so skip them rather than printing blank lines.
3. Print it every turn
const runTurn = async (messages: Anthropic.MessageParam[]) => { while (true) { const response = await chat(messages); add_assistant_message(messages, response); const thinking = getThinking(response); if (thinking) console.log(`\n[thinking] ${thinking}\n`); if (response.stop_reason !== "tool_use") { return response; } add_user_message(messages, await runTools(response)); } };
The summary is printed after every response, including the ones that end in a tool call. That shows why the model chose a tool, not only what it finally said.
The history handling doesn't change. add_assistant_message still appends the whole message, so the thinking blocks go back to the API unchanged, which the API requires.
Try it
Run the new file, pick "Winter sun" and watch the [thinking] lines appear between the [tool] lines.
👉 The OpenAI version is in Module 2, Lesson 5