|
| 1 | +# Technical details: empty thinking summaries on Opus 4.7 / 4.8 |
| 2 | + |
| 3 | +Full root-cause analysis and design notes behind the workarounds in the [README](README.md). This expands on the README's "Technical details" section with the request-level mechanics, the live A/B confirmation, and the proxy design. |
| 4 | + |
| 5 | +## TL;DR |
| 6 | + |
| 7 | +The Messages API `thinking.display` field decides whether summarized thinking is returned. On Opus 4.7 / 4.8 it defaults to `"omitted"`, so unless the request explicitly carries `thinking: {type: "adaptive", display: "summarized"}`, the thinking block streams back with an empty `thinking` string. The setting meant to opt you in, `showThinkingSummaries`, is honored only in interactive (TUI) mode, and the VS Code extension and headless `-p`/SDK drive the CLI non-interactively, so the setting is silently skipped on exactly the surfaces people complain about. The `--thinking-display summarized` CLI flag is not interactivity-gated, so forcing it (or the equivalent wire field) fixes the problem. |
| 8 | + |
| 9 | +There is no raw/full thinking mode: the only valid `display` values are `"summarized"` and `"omitted"`. |
| 10 | + |
| 11 | +## Root cause (from the installed CLI) |
| 12 | + |
| 13 | +The request builder inside the CLI picks `display` like this (function names from a native-installer 2.1.x binary; logic is the same across install types): |
| 14 | + |
| 15 | +```js |
| 16 | +function p6(){ return !isInteractive } // p6() === "NOT interactive" |
| 17 | +function EK8(){ return settings.showThinkingSummaries ?? false } |
| 18 | + |
| 19 | +// request builder: |
| 20 | +if (thinkingDisplay === "summarized" || thinkingDisplay === "omitted") |
| 21 | + pz.display = thinkingDisplay; // <- the --thinking-display flag (ungated) |
| 22 | +else if (!p6() && EK8()) // <- (isInteractive && showThinkingSummaries) |
| 23 | + pz.display = "summarized"; |
| 24 | +// else: pz.display stays undefined -> server defaults to "omitted" |
| 25 | +``` |
| 26 | +
|
| 27 | +Two ways to set `display`: |
| 28 | +
|
| 29 | +1. The `--thinking-display` flag, always honored regardless of interactivity. |
| 30 | +2. The `showThinkingSummaries` setting, honored only when `isInteractive`. |
| 31 | +
|
| 32 | +The VS Code extension launches the CLI with `--input-format stream-json` (i.e. non-interactive), so path #2 never fires. That leaves path #1, the flag, as the only lever. But the extension builds the thinking args like this: |
| 33 | +
|
| 34 | +```js |
| 35 | +// extension.js, simplified: |
| 36 | +let B = ["--output-format","stream-json","--verbose","--input-format","stream-json"]; |
| 37 | +// ... pushes --thinking adaptive / enabled / disabled ... |
| 38 | +if (l.type !== "disabled" && l.display) B.push("--thinking-display", l.display); |
| 39 | +``` |
| 40 | +
|
| 41 | +`l.display` is only ever set if some upstream layer already set it, and nothing maps `showThinkingSummaries` onto it. The literal string `"summarized"` occurs 0 times in `extension.js`; `showThinkingSummaries` appears only in the settings *schema*, never in the request path. So `l.display` is always undefined, `--thinking-display` is never passed, the binary is non-interactive so the setting gate is also skipped, `display` stays undefined, the server defaults to `"omitted"`, and you get empty thinking even with `showThinkingSummaries: true`. |
| 42 | +
|
| 43 | +## Behavior matrix |
| 44 | +
|
| 45 | +| Surface | `showThinkingSummaries: true` | `--thinking-display summarized` | |
| 46 | +|---|:--:|:--:| |
| 47 | +| Interactive terminal (TUI) | Works (`isInteractive` true) | Works | |
| 48 | +| `claude -p` / headless / SDK | Ignored (`isInteractive` false) | Works | |
| 49 | +| VS Code extension | Ignored (non-interactive, never mapped) | Works (extension just never sends it) | |
| 50 | +
|
| 51 | +This is why the interactive terminal was never broken and needs no fix, while the extension and headless paths show empty thinking. |
| 52 | +
|
| 53 | +## Confirmation (live A/B, headless) |
| 54 | +
|
| 55 | +Same prompt, run twice through a logged-in account on Opus 4.8 with `claude -p ... --output-format stream-json --verbose`: |
| 56 | +
|
| 57 | +| Run | thinking block | |
| 58 | +|---|---| |
| 59 | +| `--thinking-display summarized` | populated (hundreds of chars) | |
| 60 | +| no flag, `showThinkingSummaries: true` | empty (0 chars) | |
| 61 | +
|
| 62 | +This proves three things: (1) `display: "summarized"` works end-to-end on 4.8, the server honors it; (2) the setting is ignored in non-interactive mode; (3) the flag is the lever. Reproduce it yourself with [`test-thinking-display.sh`](test-thinking-display.sh) (sends two small live requests; uses a few tokens). |
| 63 | +
|
| 64 | +VS Code UI was confirmed separately: after applying the Option 2 patch and reloading the window, thinking summaries render in the conversation on Opus 4.8. The fix has also been observed to survive an extension auto-update where `patch-extension.sh` had patched multiple installed versions. |
| 65 | +
|
| 66 | +## How each workaround applies the lever |
| 67 | +
|
| 68 | +### Option 1: launcher |
| 69 | +
|
| 70 | +Claude Code already places `--thinking adaptive` (VS Code/SDK) or `-p`/`--print` (headless) on the command line for real agent runs. The launcher inspects the args and, when it detects a real run, appends `--thinking-display summarized` before `exec`'ing the real `claude`. Because it lives *outside* the app: |
| 71 | +
|
| 72 | +- it survives extension/CLI updates (nothing in Claude's install is modified); |
| 73 | +- one wrapper covers both the VS Code extension and headless `-p`/SDK; |
| 74 | +- the injection is guarded so it only fires on real runs (never on `mcp`, `config`, `--version`, etc.), never when thinking is explicitly `disabled`, and never twice (so it coexists with a patched or updated extension); |
| 75 | +- `CC_THINKING_DISPLAY=omitted` flips it off without editing anything. |
| 76 | +
|
| 77 | +The launcher intentionally sets no environment of its own by default; it only adds the flag. Effort level, timeouts, and alternate-backend routing are available as commented, opt-in customizations in the script. |
| 78 | +
|
| 79 | +### Option 2: extension.js patch |
| 80 | +
|
| 81 | +A one-line change so the non-interactive spawn always forwards the flag: |
| 82 | +
|
| 83 | +```js |
| 84 | +// from: |
| 85 | +if(l.type!=="disabled"&&l.display)B.push("--thinking-display",l.display) |
| 86 | +// to: |
| 87 | +if(l.type!=="disabled")B.push("--thinking-display",l.display||"summarized") |
| 88 | +``` |
| 89 | +
|
| 90 | +[`patch-extension.sh`](patch-extension.sh) applies this idempotently across all installed Claude Code extensions (backing up each first), with `--revert` and `--dry-run`. It must be re-applied after every extension update (the install folder is replaced on upgrade), and it only fixes VS Code; headless/SDK still need Option 1. |
| 91 | +
|
| 92 | +Toggle idea (untested): changing the line to `l.display || (process.env.CC_THINKING_DISPLAY || "summarized")` would let a `CC_THINKING_DISPLAY=omitted` env var (e.g. in VS Code `settings.json`) hide thinking while unset/`summarized` shows it, a way to honor an on/off switch without a code change each time. Not tested. |
| 93 | +
|
| 94 | +### Option 3: local proxy (design) |
| 95 | +
|
| 96 | +The most thorough fix: a small localhost forward proxy that injects the field at the wire level, so it is surface-agnostic (VS Code + CLI + SDK), needs no install edits, and survives updates. It works because every Claude Code surface resolves the API host as: |
| 97 | +
|
| 98 | +``` |
| 99 | +... ?? process.env.ANTHROPIC_BASE_URL ?? "https://api.anthropic.com" |
| 100 | +``` |
| 101 | +
|
| 102 | +Point `ANTHROPIC_BASE_URL` at the proxy and every request flows through it. |
| 103 | +
|
| 104 | +What the proxy does ([`proxy.js`](proxy.js)): |
| 105 | +
|
| 106 | +1. Accept requests on `http://127.0.0.1:<port>`. |
| 107 | +2. For `POST /v1/messages`, parse the JSON body; if `body.thinking.type` is `"adaptive"` or `"enabled"` and `body.thinking.display` is unset, set it to the configured value (default `"summarized"`, or `"omitted"` to hide). |
| 108 | +3. Forward everything else to `https://api.anthropic.com` unchanged: headers (incl. `x-api-key` / `Authorization: Bearer`, `anthropic-version`, `anthropic-beta`), query string, and the streaming SSE response body. |
| 109 | +4. Stream the response straight back (no buffering, so `--output-format stream-json` and the UI keep working). |
| 110 | + |
| 111 | +This doubles as the toggle: the injected value is read from `CC_THINKING_DISPLAY`, so flipping between `summarized` and `omitted` is just a restart with a different env var. |
| 112 | + |
| 113 | +Security / trust notes (important): |
| 114 | + |
| 115 | +- The proxy sees your live auth token. Keep it bound to 127.0.0.1 only, never `0.0.0.0`. Don't log headers/bodies except when actively debugging, and never to a shared path. |
| 116 | +- Simplest TLS model: terminate plain HTTP locally and let the proxy make the upstream TLS call to api.anthropic.com (client to `http://127.0.0.1`, then on to the https upstream). Confirm your build accepts an `http://` localhost base URL; some builds may force https, in which case add a self-signed cert + `NODE_EXTRA_CA_CERTS`, or use a tool like `mitmproxy` with an addon that does the same body rewrite. |
| 117 | +- Fully reversible: unset `ANTHROPIC_BASE_URL` to talk to Anthropic directly again. |
| 118 | +
|
| 119 | +Status: provided as a working starting point but not extensively tested, so validate the localhost-base-URL behavior before relying on it. |
| 120 | +
|
| 121 | +## Notes |
| 122 | +
|
| 123 | +- Summary length tracks effort. The detail/length of the summaries corresponds to the reasoning effort level, and at high effort (e.g. `CLAUDE_CODE_EFFORT_LEVEL=xhigh`) the summaries are long and read almost like full reasoning. Higher effort uses more tokens. |
| 124 | +- Why hooks / plugins / MCP can't do this. None of them can modify the `/v1/messages` request body or the thinking config; they operate on tool/lifecycle events only, and the request is built inside the CLI. The only levers are: the `--thinking-display` flag, the (interactive-only) setting, an `extension.js`/binary patch, or a wire-level proxy. |
| 125 | + |
| 126 | +## Compatibility |
| 127 | + |
| 128 | +Confirmed on Opus 4.7 / 4.8 with native-installer CLI `2.1.166` and VS Code extension `2.1.165` / `2.1.167`, on Windows 11 and Ubuntu 24.04. The CLI flag and the request field are stable levers, but the exact minified strings used by [`patch-extension.sh`](patch-extension.sh) (Option 2) can change between extension releases. If the target string isn't found, the script skips and tells you to inspect manually. Options 1 and 3 don't depend on internal strings. |
0 commit comments