Skip to content

Ask the user before Claude Code leaves Plan mode - #1260

Merged
SawyerHood merged 3 commits into
mainfrom
bb/review-reported-thread-issue-thr_kxu5gf7ep6
Aug 10, 2026
Merged

SawyerHood merged 3 commits into
mainfrom
bb/review-reported-thread-issue-thr_kxu5gf7ep6

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Aug 10, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1259, and fixes the reported bug that Plan mode never asks for confirmation.

Problem 1 — Plan mode never proposes the plan

Claude calls ExitPlanMode with no blockedPath, no decisionReason, and no permission suggestions. bb's approval gate in createCanUseTool reads 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:

seq time (ms) event
17 1786371676974 AskUserQuestion starts
20 1786371684810 user answers — 7.8 s later, real interaction
31 1786371712750 ExitPlanMode starts
32 1786371712750 ExitPlanMode completes, "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)

/plan overrides the session permission mode at thread/start. turn/start carries 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

ExitPlanMode now raises a real approval interaction, placed above every auto-allow path — the same treatment AskUserQuestion already had, because in both cases the tool call is the prompt rather than a guard on one.

The plan travels as a new plan approval 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.

  • Approve — the agent leaves Plan mode and starts the work.
  • Reject — the model is told to use AskUserQuestion to 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.
  • A plan verdict grants no permission, so it offers allow_once and deny only.
  • App: the plan renders as Markdown with its plan-file path; buttons read Approve plan / Keep planning.
  • CLI: bb thread interactions approve|deny work; show prints the plan; list reports kind plan.

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 own canUseTool gate reads and the live SDK session (Query.setPermissionMode). The field is always explicit and equals permissionMode whenever the session does not start in Plan mode.

HOST_DAEMON_PROTOCOL_VERSION 89 → 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:

  • without the ExitPlanMode branch: all three forwarding tests fail with Expected ExitPlanMode to request user approval;
  • without the mode restore: returns to the user's permission preset once a plan is approved fails.

One bridge case covers bypassPermissions so the blanket allow cannot auto-approve a plan either.

Full repo typecheck passes (58/58). @bb/agent-runtime 850, @bb/cli 374, @bb/domain 126, @bb/core-ui 16, @bb/app 373, @bb/server 1378 pass. @bb/server internal-skill-trees fails 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":

  1. /plan on Claude Code — the agent wrote a plan and called ExitPlanMode, which stayed pending instead of self-completing.
  2. The plan card appeared with rendered Markdown and both buttons.
  3. Keep planning — the model received the rejection and asked what to change.
  4. Answered once through the app and once through the CLI — the model revised hello to Hello, World! and re-proposed.
  5. Approved through the CLI — the agent left Plan mode and wrote hello.txt containing Hello, World!, the revised content, which proves the feedback reached the work.

#1259, in Full Access: /plan, approved the plan, and the agent created issue1259.md with no second approval prompt — no pending interaction and no waiting_for_approval on the fileChange item. The same flow under "Approve for me" still prompts, as that preset intends.

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]>
@SawyerHood

SawyerHood commented Aug 10, 2026 •

Copy link
Copy Markdown
Collaborator Author

🚨 SLOP COP 🚨 · review

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;

@SawyerHood SawyerHood Aug 10, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 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":

@SawyerHood SawyerHood Aug 10, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 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,

@SawyerHood SawyerHood Aug 10, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 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]>

@SawyerHood SawyerHood left a comment •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 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.

  1. 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.

  2. 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 only plan and planFilePath. Claude’s SDK also defines allowedPrompts for implementation permissions. Approval returns those hidden fields unchanged. Parse once and forward only the parsed plan fields.

  3. Low — The CLI uses permission terms for a plan verdict.

    A resolved plan prints Decision: allow_once and Scope: 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 --check passed.
  • 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]>
@SawyerHood
SawyerHood merged commit a39314d into main Aug 10, 2026
10 checks passed
@SawyerHood
SawyerHood deleted the bb/review-reported-thread-issue-thr_kxu5gf7ep6 branch August 10, 2026 15:57
amadad pushed a commit to amadad/bb that referenced this pull request Aug 14, 2026
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]>
SawyerHood added a commit that referenced this pull request Aug 21, 2026
## 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Plan mode requests file edit approval after plan approval in full access mode

1 participant