Skip to content

Commit 7723e69

Browse files
phase3devclaude
andauthored
Fix empty thinking on official VS Code extension (--max-thinking-tokens + process-wrapper convention) (#1)
The 2.1.16x VS Code extension signals the VS Code path with --max-thinking-tokens (not --thinking adaptive) and uses a process-wrapper convention (<wrapper> <REAL_CLAUDE> <args...>). The launcher now triggers on --max-thinking-tokens (nonzero) and strips the leading real-binary path (native claude, or node + cli.js). patch-extension.sh matches the minified array variable generically (B -> q). Docs cover claudeProcessWrapper (window-scoped, multi-root note) and the safe undo (clear the setting). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 3fac08c commit 7723e69

5 files changed

Lines changed: 212 additions & 61 deletions

File tree

‎README.md‎

Lines changed: 78 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,18 @@ No PATH changes are required.
4747

4848
1. Open the Command Palette with Ctrl/Cmd + Shift + P.
4949
2. Select "Preferences: Open User Settings (JSON)".
50-
3. Add this line, replacing `YOUR_USERNAME`:
50+
3. Add this line, replacing `YOUR_USERNAME`. This is the official "Claude Code" extension's setting (shown in the UI as "Claude Code: Claude Process Wrapper"):
5151

5252
```jsonc
53-
"claudeCodeChat.executable.path": "/home/YOUR_USERNAME/.local/bin/claudemax"
53+
"claudeCode.claudeProcessWrapper": "/home/YOUR_USERNAME/.local/bin/claudemax"
5454
```
5555

56-
You can also use the "Claude Code: Claude Process Wrapper" setting in the VS Code app and enter `/home/YOUR_USERNAME/.local/bin/claudemax`.
56+
If you use the third-party "Claude Code Chat" extension instead, set `"claudeCodeChat.executable.path"` to the same path.
5757

5858
4. Reload the VS Code window by opening the Command Palette and selecting "Developer: Reload Window".
59-
5. To undo the change, point the setting back to your normal `claude` binary and reload.
59+
5. To undo the change, clear or remove the `claudeCode.claudeProcessWrapper` setting, then reload. Do not point this setting at `claude` directly: under the process-wrapper convention the extension would launch `claude <REAL_CLAUDE> <args...>` and the real CLI would receive its own path as a stray argument. (If you used the third-party `claudeCodeChat.executable.path` instead, that one can simply be pointed back to your normal `claude` binary or removed.)
60+
61+
> Multi-root note: `claudeCode.claudeProcessWrapper` is window-scoped. In a single folder, User or Workspace settings both work. In a multi-root `.code-workspace`, set it in the `.code-workspace` file's `"settings"` block (or User settings); VS Code ignores it in a folder's `.vscode/settings.json`.
6062
6163
### Use it in a terminal
6264

@@ -73,14 +75,18 @@ Run `claudemax` in place of `claude`.
7375
# How it works: the VS Code extension and the headless CLI build the request
7476
# without thinking.display, so the API defaults to "omitted" and you get empty
7577
# thinking. This wrapper injects `--thinking-display summarized` into the launch
76-
# args. That is the one lever that is not interactivity-gated, so summaries
77-
# render again without editing Claude Code files. It covers the VS Code extension
78-
# and the headless CLI (`-p` / `--print` / SDK). The interactive terminal already
79-
# honors the showThinkingSummaries setting and needs no injection.
78+
# args (the one lever that is NOT interactivity-gated), so summaries render again
79+
# WITHOUT editing Claude's files, so it keeps working across Claude Code
80+
# updates. It covers the VS Code extension AND the headless CLI (`-p` / `--print`
81+
# / SDK). The interactive terminal already honors the showThinkingSummaries
82+
# setting and needs no injection.
8083
#
8184
# Use it:
82-
# - VS Code: set "claudeCodeChat.executable.path" to the full path of this
83-
# file, then reload the window.
85+
# - VS Code (official "Claude Code" extension): set "claudeCode.claudeProcessWrapper"
86+
# to the FULL path of this file, then reload the window. In a multi-root
87+
# .code-workspace this setting is window-scoped, so put it in the workspace
88+
# file's "settings" block (or User settings), not a folder .vscode/settings.json.
89+
# - VS Code (third-party "Claude Code Chat"): set "claudeCodeChat.executable.path".
8490
# - Terminal: run `claudemax` in place of `claude`.
8591
#
8692
# Toggle off:
@@ -89,15 +95,40 @@ Run `claudemax` in place of `claude`.
8995
# Default:
9096
# CC_THINKING_DISPLAY=summarized
9197
#
92-
# The real `claude` must be installed. This wrapper finds it automatically. If it
98+
# The real `claude` must be installed. This wrapper finds it automatically; if it
9399
# cannot, set CLAUDE_REAL_BIN to the full path of your real claude binary.
94100

95101
set -euo pipefail
96102

97103
# --- Locate the real claude binary -----------------------------------------
98104

99105
self="$(readlink -f "$0" 2>/dev/null || echo "$0")"
106+
107+
# Process-wrapper convention: the official VS Code extension invokes the wrapper
108+
# as <wrapper> <REAL_CLAUDE...> <args...>, passing the real CLI ahead of the
109+
# args. <REAL_CLAUDE...> is either a single native-binary path (".../claude") or
110+
# a node interpreter followed by the bundled cli.js (".../node .../cli.js").
111+
# Peel that off so it is not forwarded as a stray positional argument, and
112+
# prefer it as the real claude. (Plain "claudemax <args>" use is unaffected:
113+
# <args> never begins with an existing claude/node binary path.)
114+
wrapper_bin=""
115+
if [ "$#" -gt 0 ] \
116+
&& printf '%s' "$1" | grep -Eqi '/claude(\.exe|\.cmd|\.bat)?$' \
117+
&& [ -e "$1" ]; then
118+
wrapper_bin="$1"
119+
shift
120+
elif [ "$#" -ge 2 ] \
121+
&& printf '%s' "$1" | grep -Eqi '/node(\.exe)?$' && [ -e "$1" ] \
122+
&& printf '%s' "$2" | grep -Eqi '\.(c?js|mjs)$' && [ -e "$2" ]; then
123+
# node + cli.js: exec node directly and keep cli.js as the first forwarded arg.
124+
wrapper_bin="$1"
125+
shift
126+
fi
127+
100128
REAL_CLAUDE="${CLAUDE_REAL_BIN:-}"
129+
if [ -z "$REAL_CLAUDE" ] && [ -n "$wrapper_bin" ]; then
130+
REAL_CLAUDE="$wrapper_bin"
131+
fi
101132

102133
if [ -z "$REAL_CLAUDE" ]; then
103134
for c in \
@@ -127,34 +158,38 @@ DISPLAY_VALUE="${CC_THINKING_DISPLAY:-summarized}"
127158

128159
# --- Optional customizations ------------------------------------------------
129160
#
130-
# Raise reasoning effort. Longer summaries use more tokens:
161+
# Raise reasoning effort - longer, more detailed summaries. Uses more tokens:
131162
# export CLAUDE_CODE_EFFORT_LEVEL="${CLAUDE_CODE_EFFORT_LEVEL:-xhigh}"
132163
#
133-
# Auto mode lets a classifier choose the effort level per task. This is an
134-
# alternative to a fixed effort level. When auto mode is enabled, a fixed
135-
# CLAUDE_CODE_EFFORT_LEVEL may be ignored.
164+
# Auto mode - let a classifier pick the effort level per task. This is an
165+
# ALTERNATIVE to a fixed effort level above (when auto mode is on, a fixed
166+
# CLAUDE_CODE_EFFORT_LEVEL may be ignored). Another frequently-requested feature:
136167
# export CLAUDE_CODE_ENABLE_AUTO_MODE="${CLAUDE_CODE_ENABLE_AUTO_MODE:-1}"
137168
#
138169
# Longer network timeout for large requests:
139170
# export API_TIMEOUT_MS="${API_TIMEOUT_MS:-600000}"
140171

141172
# --- Inject the thinking-display fix into the launch args -------------------
142173
#
143-
# Fire on a real agent invocation. VS Code/SDK passes "--thinking adaptive"
144-
# or "--thinking enabled"; headless passes "-p" or "--print".
174+
# Fire on a real agent invocation. Surfaces signal a real run differently:
175+
# - the VS Code extension passes "--max-thinking-tokens N" (N > 0) plus the
176+
# stream-json I/O flags, and does NOT pass "--thinking adaptive" or "-p";
177+
# - the SDK / older extensions pass "--thinking adaptive" (or "enabled");
178+
# - headless passes "-p" / "--print".
145179
#
146180
# Skip injection when:
147181
# - thinking is explicitly disabled
148-
# - --thinking-display is already present
182+
# - --thinking-display is already present (no double-inject vs a patched extension)
149183
# - CC_THINKING_DISPLAY=omitted
150-
# - the command is a subcommand or probe such as mcp, config, or --version,
151-
# which carries neither marker
184+
# - the command is a subcommand/probe such as mcp, config, or --version,
185+
# which carries none of these markers
152186

153187
args=("$@")
154188
have_display=false
155189
thinking_adaptive=false
156190
thinking_disabled=false
157191
print_mode=false
192+
max_thinking_on=false
158193
prev=""
159194

160195
for a in "$@"; do
@@ -178,13 +213,17 @@ for a in "$@"; do
178213
esac
179214
fi
180215

216+
if [ "$prev" = "--max-thinking-tokens" ] && [ "$a" != "0" ]; then
217+
max_thinking_on=true
218+
fi
219+
181220
prev="$a"
182221
done
183222

184223
if [ "$have_display" = false ] \
185224
&& [ "$thinking_disabled" = false ] \
186225
&& [ "$DISPLAY_VALUE" != "omitted" ] \
187-
&& { [ "$thinking_adaptive" = true ] || [ "$print_mode" = true ]; }; then
226+
&& { [ "$thinking_adaptive" = true ] || [ "$print_mode" = true ] || [ "$max_thinking_on" = true ]; }; then
188227
args+=(--thinking-display "$DISPLAY_VALUE")
189228
fi
190229

@@ -202,12 +241,14 @@ The same result can be achieved by using a compiled `.exe` version of the wrappe
202241
1. Download `claudemax.exe` from this repository's [Releases](../../releases), or build it yourself by following [Building claudemax.exe](#building-claudemaxexe).
203242
2. Put `claudemax.exe` somewhere stable, such as `C:\Users\YOU\.local\bin\claudemax.exe`.
204243
3. Open the Command Palette and select "Preferences: Open User Settings (JSON)".
205-
4. Add the following setting. Use double backslashes in the path.
244+
4. Add the following setting (the official "Claude Code" extension setting). Use double backslashes in the path.
206245

207246
```jsonc
208-
"claudeCodeChat.executable.path": "C:\\Users\\YOU\\.local\\bin\\claudemax.exe"
247+
"claudeCode.claudeProcessWrapper": "C:\\Users\\YOU\\.local\\bin\\claudemax.exe"
209248
```
210249

250+
If you use the third-party "Claude Code Chat" extension instead, set `"claudeCodeChat.executable.path"` to the same path. In a multi-root `.code-workspace`, put `claudeCode.claudeProcessWrapper` in the workspace file's `"settings"` block or in User settings, not a folder's `.vscode/settings.json`.
251+
211252
5. Reload the VS Code window by opening the Command Palette and selecting "Developer: Reload Window".
212253
6. To use it in a terminal, run `claudemax.exe` in place of `claude`.
213254

@@ -222,13 +263,13 @@ The launcher reads one environment variable, `CC_THINKING_DISPLAY`:
222263
* unset or `summarized`: show thinking summaries, which is the default
223264
* `omitted`: hide thinking summaries
224265

225-
Set the variable in the same environment where Claude Code launches, such as your shell profile or the VS Code extension environment, then reload. To disable the launcher entirely, point the VS Code setting back to your normal `claude` binary.
266+
Set the variable in the same environment where Claude Code launches, such as your shell profile or the VS Code extension environment, then reload. To disable the launcher entirely, clear or remove the `claudeCode.claudeProcessWrapper` setting (do not point it at `claude`, for the reason in the undo note above); if you used `claudeCodeChat.executable.path`, point it back to `claude` or remove it.
226267

227268
### What the launcher does
228269

229-
Claude Code already puts `--thinking adaptive`, `-p`, or `--print` on the command line when it starts a real agent run. It does not add the matching `--thinking-display` flag, so the API defaults the display to `"omitted"` and the Thinking section comes back empty.
270+
When Claude Code starts a real agent run it puts one of these markers on the command line: `--max-thinking-tokens N` (the current VS Code extension's budget thinking mode), `--thinking adaptive` or `enabled` (the SDK and older extensions), or `-p` / `--print` (headless). It does not add the matching `--thinking-display` flag, so the API defaults the display to `"omitted"` and the Thinking section comes back empty.
230271

231-
The launcher inspects the arguments and, when it detects a real run, appends `--thinking-display summarized` before handing off to the real `claude` binary. See [Technical details](#technical-details) and [TECHNICAL.md](TECHNICAL.md) for more information.
272+
The launcher inspects the arguments and, when it detects a real run via any of those markers, appends `--thinking-display summarized` before handing off to the real `claude` binary. The official extension also launches the wrapper with the real CLI path as a leading argument (a "process wrapper" convention); the launcher detects and consumes that path so it is not forwarded as a stray positional. See [Technical details](#technical-details) and [TECHNICAL.md](TECHNICAL.md) for more information.
232273

233274
### Why Option 1 is recommended
234275

@@ -251,6 +292,8 @@ if(l.type!=="disabled"&&l.display)B.push("--thinking-display",l.display)
251292
if(l.type!=="disabled")B.push("--thinking-display",l.display||"summarized")
252293
```
253294

295+
> The extension is minified, so the array variable name varies by build (`B` in 2.0.x, `q` in 2.1.16x, and so on). Match the surrounding text and keep whatever variable name your build uses; `patch-extension.sh` does this automatically. This version fragility is one reason Option 1 is preferred.
296+
254297
### Automatic patching on Linux, macOS, WSL, or Git Bash
255298

256299
[`patch-extension.sh`](patch-extension.sh) finds every installed Claude Code extension, backs each one up, and applies the patch:
@@ -368,15 +411,17 @@ else if (!p6() && EK8()) // isInteractive && showThinkingSum
368411
pz.display = "summarized";
369412
```
370413
371-
The setting-to-display mapping is gated on `isInteractive`. The VS Code extension launches the CLI non-interactively with `--input-format stream-json`, so that branch never runs. The extension only forwards `--thinking-display` when its own `display` value is already set:
414+
The setting-to-display mapping is gated on `isInteractive`. The VS Code extension launches the CLI non-interactively with `--input-format stream-json`, so that branch never runs. The extension only forwards `--thinking-display` when its own `display` value is already set (the array variable is minified, shown here as `q`, as in extension 2.1.16x):
372415
373416
```js
374417
// extension.js, simplified:
375-
if (l.type !== "disabled" && l.display) B.push("--thinking-display", l.display);
418+
if (l.type !== "disabled" && l.display) q.push("--thinking-display", l.display);
376419
```
377420
378421
`l.display` is never populated from `showThinkingSummaries`; the literal string `"summarized"` appears zero times in `extension.js`. The result on the extension and headless paths is that `display` is never sent, the API omits summaries, and the Thinking section is empty even with `showThinkingSummaries: true`.
379422
423+
The current extension signals a real run on the VS Code path with `--max-thinking-tokens <budgetTokens>` (its budget thinking mode) rather than `--thinking adaptive`, and it launches a configured `claudeProcessWrapper` with the real CLI path as a leading argument. Both matter for the launcher: it triggers on `--max-thinking-tokens` and strips the leading binary path.
424+
380425
The ungated lever is the `--thinking-display summarized` CLI flag, which works headless. Each fix in this repository forces that flag, or the equivalent request field, to be present.
381426
382427
### Behavior matrix
@@ -387,14 +432,16 @@ The ungated lever is the `--thinking-display summarized` CLI flag, which works h
387432
| `claude -p` / headless / SDK | Ignored because it is non-interactive | Works |
388433
| VS Code extension | Ignored because it is non-interactive and never mapped | Works, but the extension does not send it by default |
389434
435+
> On the VS Code path the current extension signals a real run with `--max-thinking-tokens`, not `--thinking adaptive`, and launches the wrapper with the real CLI path as a leading argument. The launcher handles both.
436+
390437
### How each option applies the lever
391438
392-
* **Option 1: Launcher.** Appends `--thinking-display summarized` to the arguments before executing the real CLI. It operates outside the app, survives updates, and covers VS Code plus headless runs.
393-
* **Option 2: Patch.** Changes the extension so it always forwards the flag with `l.display || "summarized"`. It modifies the bundle, is wiped by updates, and fixes VS Code only.
439+
* **Option 1: Launcher.** Appends `--thinking-display summarized` to the arguments before executing the real CLI, triggering on `--max-thinking-tokens` (nonzero), `--thinking adaptive`/`enabled`, or `-p`/`--print`, and stripping the leading real-binary path the official extension passes. It operates outside the app, survives updates, and covers VS Code plus headless runs.
440+
* **Option 2: Patch.** Changes the extension so it always forwards the flag with `l.display || "summarized"`. It modifies the bundle, is wiped by updates, is fragile against the minified variable rename (`B`, `q`, ...), and fixes VS Code only.
394441
* **Option 3: Proxy.** Sets `body.thinking.display = "summarized"` on the wire for every `/v1/messages` request. It is surface-agnostic.
395442
396443
For the live A/B confirmation, deeper design notes, proxy security model, and notes on summary length versus effort level, see [TECHNICAL.md](TECHNICAL.md).
397444
398445
## Confirmation
399446
400-
Confirmed on Opus 4.7 and Opus 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. Behavior may change in future Claude Code releases.
447+
Confirmed on Opus 4.7 and Opus 4.8 with VS Code extension `2.1.169` (native-binary CLI), via the `claudeCode.claudeProcessWrapper` setting, on Windows 11 and Ubuntu 24.04. Earlier builds (`2.1.165` / `2.1.167`) signaled thinking with `--thinking adaptive`; `2.1.169` uses `--max-thinking-tokens` on the VS Code path. Behavior may change in future Claude Code releases.

0 commit comments

Comments
 (0)