Repository navigation
Ask the user before Claude Code leaves Plan mode - #1260
Conversation
Claude calls ExitPlanMode with no blockedPath, no decisionReason and no permission suggestions. bb's approval gate reads exactly those three signals, so it classified the call as a request that needs no user decision and allowed it. The SDK then told the model "User has approved your plan" in the same millisecond, and Plan mode ended without the user ever seeing the plan. Route ExitPlanMode to a real pending interaction, above every auto-allow path, for the same reason AskUserQuestion already is: the tool call is the prompt, not a guard on one. The plan travels as a new `plan` approval subject rather than a new interaction kind, so it reuses the whole approval lifecycle: server routes, resolution delivery, the app banner, the CLI, and the SDK. A plan verdict grants no permission, so it offers allow_once and deny only. A rejection returns a message that sends the model to AskUserQuestion for feedback first. The SDK keeps the session in Plan mode after a denial, so a bare "denied" leaves the model free to re-propose the same plan in a loop. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
|
🚨 SLOP COP 🚨 · I’m SlopCop. I’m reviewing this pull request for security, code quality, architecture, performance, and end-to-end behavior. |
| } from "./local.js"; | ||
|
|
||
| export const HOST_DAEMON_PROTOCOL_VERSION = 89 as const; | ||
| export const HOST_DAEMON_PROTOCOL_VERSION = 90 as const; |
There was a problem hiding this comment.
🚨 slopcop/review — The protocol increase leaves the contract suite red.
The contract test still expects version 89 at packages/host-daemon-contract/test/contract.test.ts:1047.
The package test fails with “expected 90 to be 89.”
Update the test name, comment, and expected value to version 90.
| } | ||
| printRequestedPermissions(interaction.payload.subject.permissions); | ||
| break; | ||
| case "plan": |
There was a problem hiding this comment.
🚨 slopcop/review — The CLI describes a plan verdict as a permission scope.
This new plan branch later prints Decision: allow_once and Scope: turn.
A plan verdict grants no permission.
Print “Approved plan” or “Keep planning” without a scope.
| providerThreadId: threadSession.providerThreadId ?? threadIdRef.current, | ||
| toolName, | ||
| toolUseId: options.toolUseID, | ||
| input, |
There was a problem hiding this comment.
🚨 slopcop/review — Approval returns hidden Claude permission fields.
safeParse validates the plan, but this line forwards the original input.
The adapter shows only plan and planFilePath to the user.
Claude’s SDK also defines allowedPrompts on ExitPlanMode for implementation permissions.
After approval, line 935 returns the full original input to Claude.
Parse once and forward only the parsed plan fields.
`/plan` overrides the session permission mode at thread/start, and `turn/start` carries no mode, so nothing restored the user's preset once the plan was approved. A full-access thread kept Plan mode's gating for the rest of the session and asked the user to approve every edit their preset already allowed. Send the preset alongside the effective start mode as `approvedPlanPermissionMode`, and apply it when a plan approval resolves: update the mode bb's own canUseTool gate reads, and ask the SDK to leave Plan mode. The field is always explicit, and equals `permissionMode` whenever the session does not start in Plan mode. Fixes #1259 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
There was a problem hiding this comment.
🚨 SLOP COP 🚨 · review
ELI5: Claude now shows its plan and asks before it starts work. “Keep planning” asks the user what should change.
I found two blocking issues and one small CLI issue.
-
High — The host contract test still expects protocol version 89.
This pull request correctly increases the protocol to version 90. However, the contract test still requires version 89. The host contract suite now fails with 48 passing tests and one failure.
-
High — Plan approval returns fields that the user never saw.
The bridge validates the plan with
safeParse, but it forwards the original input. The UI shows onlyplanandplanFilePath. Claude’s SDK also definesallowedPromptsfor implementation permissions. Approval returns those hidden fields unchanged. Parse once and forward only the parsed plan fields. -
Low — The CLI uses permission terms for a plan verdict.
A resolved plan prints
Decision: allow_onceandScope: turn. A plan verdict grants no permission. Print “Approved plan” or “Keep planning” without a scope.
I found no other security, authorization, replay, performance, or cross-provider issue. I also found no duplicate plan-review path. The new shared interaction subject fits the current architecture.
The end-to-end browser test passed. Claude stopped at “Ready to code?” under Full Access. “Keep planning” kept Plan mode active and opened a feedback question. Claude did not create the test file.
Validation:
- All changed-package type checks passed.
- The app suite passed 2,451 tests.
- The server suite passed 1,379 tests.
- The Claude adapter and bridge passed 208 focused tests.
- The domain and core UI passed 142 tests.
git diff --checkpassed.- The agent runtime passed 848 tests. One unchanged process test failed twice.
- The host contract suite has the pull-request-specific version failure above.
I posted this as a comment only. I did not approve the pull request or request changes.
The contract test pins the protocol version and records why the last bump happened. Restate it for the plan-review approval subject. Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Plan mode never proposed the plan for confirmation. Claude calls ExitPlanMode with no blockedPath, no decisionReason and no permission suggestions, and bb's approval gate reads exactly those three signals, so it allowed the call. The SDK then told the model the user had approved a plan the user never saw. ExitPlanMode now raises a real approval interaction, above every auto-allow path, for the same reason AskUserQuestion already does: the tool call is the prompt, not a guard on one. The plan travels as a new `plan` approval subject, so it reuses the whole approval lifecycle across the server, the app, the CLI and the SDK. A rejection sends the model to AskUserQuestion for feedback first, because the SDK keeps the session in Plan mode after a denial. Approving a plan also returns the session to the user's permission preset. `/plan` overrode the session permission mode at thread/start, and turn/start carries no mode, so a full-access thread kept Plan mode's gating and asked to approve every edit it already allowed. Fixes get-bb#1259 Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
## What was wrong A `/plan` typed on a later turn of a Claude Code thread never entered Plan mode. Claude ran the task in the user's preset mode instead of writing a plan and proposing it through `ExitPlanMode`, so the "Approve plan / Keep planning" card never appeared. The first turn of a fresh thread worked. Root cause: since #1640 the runtime uses the generic bridge-protocol adapter, whose `classifyExecutionSettingsChange` always returns `"live"`, so a `claudeCodePermissionMode` change no longer triggers a `thread/resume` session rebuild. The Claude bridge applied `permissionMode` only at session construction. On `turn/start` and `turn/steer`, `buildClaudeTurnParams` read `providerOptions.claudeCodePermissionMode` solely to strip the `/plan` mention from the prompt, then pushed the prompt into the live SDK session still in the preset mode. Issue: #1712. Report: https://get-bb.github.io/reports/issues/1712.html ## What changed All in `plugins/provider-claude-code`: - `src/session-params.ts`: `buildClaudeTurnParams` forwards `claudeCodePermissionMode` from the providerOptions bag into the bridge's internal turn params. - `src/bridge/commands.ts`: `claudeTurnStartParamsSchema` and `claudeTurnSteerParamsSchema` accept `claudeCodePermissionMode: "plan"` (optional; undefined keeps the session's current mode, like the other per-turn knobs). - `src/bridge/bridge.ts`: new `enterPlanModeIfRequested()` awaits `session.setPermissionMode("plan")` and records `threadSession.permissionMode = "plan"` when the turn requests Plan mode and the session is not already in it. Called right after `applyLiveSessionSettings` in both `runTurnStart` and `runTurnSteer`, before the prompt is pushed. A failed control request fails the turn instead of running it in the preset mode. `approvedPlanPermissionMode` is untouched, so the existing approval path (#1260) restores the preset exactly as for a first-turn `/plan`. No wire change: the canonical server -> daemon -> bridge payload already carried `providerOptions.claudeCodePermissionMode` on `turn/start`; only the plugin's internal turn params change. No `HOST_DAEMON_PROTOCOL_VERSION` bump needed. This matches the report's proposed fix; the only deviation is that the bridge state is set after the SDK call succeeds, so a failed attempt does not make a retry a no-op. ## How you verified New test in `src/bridge/__tests__/bridge.test.ts`: "switches a live session into Plan mode when a later turn carries /plan". It starts an accept-edits session, sends a second `turn/start` with the `/plan` mention plus `claudeCodePermissionMode: "plan"`, and asserts the SDK query's `setPermissionMode("plan")` was called before the prompt was consumed, the mention was stripped, no session rebuild happened, and approving `ExitPlanMode` restores `acceptEdits`. Fails on origin/main: ``` AssertionError: expected "vi.fn()" to be called with arguments: [ 'plan' ] Number of calls: 0 ❯ src/bridge/__tests__/bridge.test.ts:1955:39 ``` Passes with the fix. From the committed tree: ``` pnpm exec turbo run typecheck test --filter=bb-plugin-provider-claude-code --force Tests 262 passed (262) Tasks: 7 successful, 7 total ``` Manual repro on my own dev instance (`scripts/bb-dev-app current`, claude-code, accept-edits): thread `thr_dsp7xxj6ai`, turn 1 "Reply only with ok.", turn 2 posted the composer's `/plan Create a file named hello.txt ...` input to `POST /api/v1/threads/:id/send`. With the fix the second turn wrote `~/.claude/plans/create-a-file-named-lovely-cray.md`, called `ToolSearch select:ExitPlanMode` then `ExitPlanMode`, and stopped with a pending plan approval (`pint_hmesjr2749`); `hello.txt` was not created. After `bb thread interactions approve`, the turn completed and created `hello.txt` without any further prompt (preset restored). Fixes #1712 > AGENT GENERATED: by Claude Opus 5 ## Independent verification Verified by a second agent on a fresh checkout of this branch (`3baa83934`, rebased on `origin/main`; `git merge-base --is-ancestor origin/main HEAD` holds). Root cause re-checked on `origin/main` before reading the PR: `packages/agent-runtime/src/bridge-protocol-adapter.ts:252` still returns `"live"` for every option change, `buildClaudeTurnParams` only read `claudeCodePermissionMode` to strip the mention, and the only `setPermissionMode` caller in `bridge.ts` was the post-approval restore. The fix sits in the right layer (the server still decides "this is a plan turn" per input in `toRuntimeExecutionOptions`; the plugin translates it), and nothing on the server/daemon wire changed, so no `HOST_DAEMON_PROTOCOL_VERSION` bump is needed. Commands: ``` git checkout origin/main -- plugins/provider-claude-code/src/bridge/bridge.ts plugins/provider-claude-code/src/bridge/commands.ts plugins/provider-claude-code/src/session-params.ts cd plugins/provider-claude-code && pnpm exec vitest run src/bridge/__tests__/bridge.test.ts -t "Plan mode when a later turn" # FAIL: AssertionError: expected "vi.fn()" to be called with arguments: [ 'plan' ] Number of calls: 0 (bridge.test.ts:1955) git checkout HEAD -- <same files> cd plugins/provider-claude-code && pnpm exec vitest run src/bridge/__tests__/bridge.test.ts -t "Plan mode when a later turn" # 1 passed pnpm exec turbo run typecheck test --filter=bb-plugin-provider-claude-code --force # Tests 262 passed (262); Tasks: 7 successful, 7 total ``` Repro on the fixed branch (own dev instance via `scripts/bb-dev-app current`, claude-code, accept-edits, thread `thr_x9kcmgk9ww`): turn 1 "Reply only with ok.", turn 2 posted the composer's `/plan Create a file named hello.txt ...` input to `POST /api/v1/threads/:id/send`. The second turn wrote `~/.claude/plans/create-a-file-named-wondrous-dongarra.md`, ran `ToolSearch select:ExitPlanMode`, then `ExitPlanMode`, and stopped on pending plan approval `pint_hbfk74c2p5` with the workspace untouched. After `bb thread interactions approve`, the turn completed, `hello.txt` contained `hello world`, and no further interaction was raised (preset restored). The bug no longer reproduces. CI: all required checks green (Checks, Tests x6, Package Smoke ubuntu + macOS, version check). Residual risks / notes: - The new test asserts `setPermissionMode("plan")` was called and that the prompt was stripped, but does not assert the ordering between the control request and the prompt push; the implementation does await the mode switch before `pushPromptInput`, and the live repro confirms the plan-mode reminder landed on the same turn. - A `turn/steer` that joins a running turn now flips the live session into Plan mode mid-turn (code path is symmetric with `turn/start`; only `turn/start` is unit-tested). - Plan mode persists until approval or `cancel-plan` when a later turn omits `/plan`, matching first-turn behavior. `cancel-plan` stops the thread, so the next turn rebuilds the session in the preset mode. > AGENT GENERATED: by Claude Opus 5 Co-authored-by: Claude <[email protected]>
Fixes #1259, and fixes the reported bug that Plan mode never asks for confirmation.
Problem 1 — Plan mode never proposes the plan
Claude calls
ExitPlanModewith noblockedPath, nodecisionReason, and no permission suggestions. bb's approval gate increateCanUseToolreads exactly those three signals, so it classified the call as a request that needs no user decision and allowed it. The SDK then returned "User has approved your plan" to the model, and Plan mode ended.In the reported thread the tool call started and completed in the same millisecond, with no interaction record between:
AskUserQuestionstartsExitPlanModestartsExitPlanModecompletes, "User has approved your plan"The agent in that thread even reported "plan mode turned off — Pass". The user never saw a prompt.
Problem 2 — Plan mode never gives the preset back (#1259)
/planoverrides the session permission mode atthread/start.turn/startcarries no permission mode, so nothing restored the user's preset once the plan was approved. A full-access thread kept Plan mode's gating for the rest of the session and asked the user to approve every edit their preset already allowed — the "Waiting for approval to edit test.md" prompt in the issue.Change
ExitPlanModenow raises a real approval interaction, placed above every auto-allow path — the same treatmentAskUserQuestionalready had, because in both cases the tool call is the prompt rather than a guard on one.The plan travels as a new
planapproval subject instead of a new interaction kind, so it reuses the entire approval lifecycle: server routes, resolution delivery, the app banner, the CLI, and the SDK.AskUserQuestionto learn what to change before re-proposing. The SDK keeps the session in Plan mode after a denial, so a bare "denied" lets the model re-propose the same plan in a loop.allow_onceanddenyonly.bb thread interactions approve|denywork;showprints the plan;listreports kindplan.Approving a plan restores the user's preset. The preset travels next to the effective start mode as
approvedPlanPermissionMode, and a plan approval applies it to both the mode bb's owncanUseToolgate reads and the live SDK session (Query.setPermissionMode). The field is always explicit and equalspermissionModewhenever the session does not start in Plan mode.HOST_DAEMON_PROTOCOL_VERSION89 → 90 (new approval subject on the wire).Tests
Added 4 bridge tests and 2 adapter tests. For each fix I removed it and confirmed the guards fail, then restored it:
ExitPlanModebranch: all three forwarding tests fail withExpected ExitPlanMode to request user approval;returns to the user's permission preset once a plan is approvedfails.One bridge case covers
bypassPermissionsso the blanket allow cannot auto-approve a plan either.Full repo typecheck passes (58/58).
@bb/agent-runtime850,@bb/cli374,@bb/domain126,@bb/core-ui16,@bb/app373,@bb/server1378 pass.@bb/serverinternal-skill-treesfails identically on a clean tree (file-mode 0664 vs 0644 umask artifact), so it is unrelated.Manual end-to-end
Plan review, in "Approve for me":
/planon Claude Code — the agent wrote a plan and calledExitPlanMode, which stayed pending instead of self-completing.hellotoHello, World!and re-proposed.hello.txtcontainingHello, World!, the revised content, which proves the feedback reached the work.#1259, in Full Access:
/plan, approved the plan, and the agent createdissue1259.mdwith no second approval prompt — no pending interaction and nowaiting_for_approvalon thefileChangeitem. The same flow under "Approve for me" still prompts, as that preset intends.