Skip to content

Commit 3fac08c

Browse files
phase3devclaude
andcommitted
Restore Opus 4.7/4.8 thinking summaries in Claude Code
Unofficial community workarounds for the empty extended-thinking summaries on Opus 4.7/4.8 (VS Code extension and headless -p/SDK paths): - Option 1: claudemax launcher (Linux/macOS + Windows) that injects --thinking-display summarized; survives updates, covers VS Code and the CLI. - Option 2: one-line extension.js patch (patch-extension.sh). - Option 3: local proxy (proxy.js, advanced/untested). See README.md and TECHNICAL.md. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
0 parents  commit 3fac08c

10 files changed

Lines changed: 1084 additions & 0 deletions

‎.gitignore‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Built binaries - large and reproducible from the .js via vercel/pkg.
2+
# Distribute via a GitHub Release instead of committing them to git.
3+
*.exe
4+
5+
# Node
6+
node_modules/
7+
8+
# Editor / OS noise
9+
*.bak.*
10+
*.orig
11+
.DS_Store
12+
Thumbs.db
13+
14+
# Editor "safe backup" copies
15+
*safeBackup*
16+
*safebackup*
17+
18+
# Session/handoff state - never publish
19+
.remember/

‎LICENSE‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2026 phase3dev
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

‎README.md‎

Lines changed: 400 additions & 0 deletions
Large diffs are not rendered by default.

‎TECHNICAL.md‎

Lines changed: 128 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
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.

‎claude-think.sh‎

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/usr/bin/env bash
2+
# claude-think.sh - minimal CLI-only variant of the launcher fix.
3+
#
4+
# Runs the real `claude` with `--thinking-display summarized` so headless / `-p`
5+
# / SDK invocations return populated thinking summaries on Opus 4.7 / 4.8. Unlike
6+
# `claudemax`, it sets NO environment of its own; it only adds the flag. The
7+
# interactive TUI already honors the showThinkingSummaries setting, so it needs
8+
# nothing.
9+
#
10+
# Most people should use `claudemax` instead (it covers VS Code too). This file
11+
# exists for pure CLI/SDK users who want the smallest possible wrapper.
12+
#
13+
# Install (optional): symlink onto PATH, e.g.
14+
# ln -s "$(pwd)/claude-think.sh" ~/.local/bin/claude-think
15+
# then use `claude-think -p "..."` exactly like `claude`.
16+
set -euo pipefail
17+
18+
# Resolve the real claude, never calling this wrapper if it's on PATH as claude.
19+
self="$(readlink -f "$0" 2>/dev/null || echo "$0")"
20+
REAL_CLAUDE="${CLAUDE_REAL_BIN:-}"
21+
if [ -z "$REAL_CLAUDE" ]; then
22+
for c in \
23+
"$HOME/.local/bin/claude" \
24+
/usr/local/bin/claude \
25+
/usr/bin/claude \
26+
/opt/homebrew/bin/claude \
27+
"$(command -v claude 2>/dev/null || true)"; do
28+
[ -n "$c" ] && [ -x "$c" ] || continue
29+
[ "$(readlink -f "$c" 2>/dev/null || echo "$c")" = "$self" ] && continue
30+
REAL_CLAUDE="$c"; break
31+
done
32+
fi
33+
[ -n "$REAL_CLAUDE" ] || { echo "could not locate the real 'claude' binary; set CLAUDE_REAL_BIN" >&2; exit 1; }
34+
35+
# Don't double-inject if the flag is already present.
36+
for a in "$@"; do
37+
[ "$a" = "--thinking-display" ] && exec "$REAL_CLAUDE" "$@"
38+
done
39+
40+
exec "$REAL_CLAUDE" --thinking-display summarized "$@"

‎claudemax‎

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
#!/usr/bin/env bash
2+
# claudemax - Claude Code launcher that restores extended-thinking summaries on
3+
# Opus 4.7 / 4.8, where the "Thinking" section otherwise renders empty.
4+
#
5+
# How it works: the VS Code extension and the headless CLI build the request
6+
# without thinking.display, so the API defaults to "omitted" and you get empty
7+
# thinking. This wrapper injects `--thinking-display summarized` into the launch
8+
# args (the one lever that is NOT interactivity-gated), so summaries render again
9+
# WITHOUT editing Claude's files, so it keeps working across Claude Code
10+
# updates. It covers the VS Code extension AND the headless CLI (`-p` / `--print`
11+
# / SDK). The interactive terminal already honors the showThinkingSummaries
12+
# setting and needs no injection.
13+
#
14+
# Use it:
15+
# - VS Code: set "claudeCodeChat.executable.path" to the FULL path of this
16+
# file, then reload the window.
17+
# - Terminal: run `claudemax` in place of `claude`.
18+
#
19+
# Toggle off:
20+
# export CC_THINKING_DISPLAY=omitted
21+
#
22+
# Default:
23+
# CC_THINKING_DISPLAY=summarized
24+
#
25+
# The real `claude` must be installed. This wrapper finds it automatically; if it
26+
# cannot, set CLAUDE_REAL_BIN to the full path of your real claude binary.
27+
28+
set -euo pipefail
29+
30+
# --- Locate the real claude binary -----------------------------------------
31+
32+
self="$(readlink -f "$0" 2>/dev/null || echo "$0")"
33+
REAL_CLAUDE="${CLAUDE_REAL_BIN:-}"
34+
35+
if [ -z "$REAL_CLAUDE" ]; then
36+
for c in \
37+
"$HOME/.local/bin/claude" \
38+
/usr/local/bin/claude \
39+
/usr/bin/claude \
40+
/opt/homebrew/bin/claude \
41+
"$(command -v claude 2>/dev/null || true)"; do
42+
43+
[ -n "$c" ] && [ -x "$c" ] || continue
44+
[ "$(readlink -f "$c" 2>/dev/null || echo "$c")" = "$self" ] && continue
45+
46+
REAL_CLAUDE="$c"
47+
break
48+
done
49+
fi
50+
51+
[ -n "$REAL_CLAUDE" ] || {
52+
echo "claudemax: could not find the real 'claude' binary; set CLAUDE_REAL_BIN" >&2
53+
exit 1
54+
}
55+
56+
# --- Behavior ---------------------------------------------------------------
57+
58+
# Set CC_THINKING_DISPLAY=omitted to hide thinking; default shows summaries.
59+
DISPLAY_VALUE="${CC_THINKING_DISPLAY:-summarized}"
60+
61+
# --- Optional customizations ------------------------------------------------
62+
#
63+
# Raise reasoning effort - longer, more detailed summaries. Uses more tokens:
64+
# export CLAUDE_CODE_EFFORT_LEVEL="${CLAUDE_CODE_EFFORT_LEVEL:-xhigh}"
65+
#
66+
# Auto mode - let a classifier pick the effort level per task. This is an
67+
# ALTERNATIVE to a fixed effort level above (when auto mode is on, a fixed
68+
# CLAUDE_CODE_EFFORT_LEVEL may be ignored). Another frequently-requested feature:
69+
# export CLAUDE_CODE_ENABLE_AUTO_MODE="${CLAUDE_CODE_ENABLE_AUTO_MODE:-1}"
70+
#
71+
# Longer network timeout for large requests:
72+
# export API_TIMEOUT_MS="${API_TIMEOUT_MS:-600000}"
73+
74+
# --- Inject the thinking-display fix into the launch args -------------------
75+
#
76+
# Fire on a real agent invocation: VS Code/SDK passes "--thinking adaptive"
77+
# or "--thinking enabled"; headless passes "-p" or "--print".
78+
#
79+
# Skip injection when:
80+
# - thinking is explicitly disabled
81+
# - --thinking-display is already present (no double-inject vs a patched extension)
82+
# - CC_THINKING_DISPLAY=omitted
83+
# - the command is a subcommand/probe such as mcp, config, or --version,
84+
# which carries neither marker
85+
86+
args=("$@")
87+
have_display=false
88+
thinking_adaptive=false
89+
thinking_disabled=false
90+
print_mode=false
91+
prev=""
92+
93+
for a in "$@"; do
94+
case "$a" in
95+
--thinking-display)
96+
have_display=true
97+
;;
98+
-p|--print)
99+
print_mode=true
100+
;;
101+
esac
102+
103+
if [ "$prev" = "--thinking" ]; then
104+
case "$a" in
105+
adaptive|enabled)
106+
thinking_adaptive=true
107+
;;
108+
disabled)
109+
thinking_disabled=true
110+
;;
111+
esac
112+
fi
113+
114+
prev="$a"
115+
done
116+
117+
if [ "$have_display" = false ] \
118+
&& [ "$thinking_disabled" = false ] \
119+
&& [ "$DISPLAY_VALUE" != "omitted" ] \
120+
&& { [ "$thinking_adaptive" = true ] || [ "$print_mode" = true ]; }; then
121+
args+=(--thinking-display "$DISPLAY_VALUE")
122+
fi
123+
124+
# The `${args[@]+...}` form guards the empty-array case under `set -u`,
125+
# including older Bash versions such as the default Bash on older macOS systems.
126+
exec "$REAL_CLAUDE" ${args[@]+"${args[@]}"}

0 commit comments

Comments
 (0)