Skip to content

Enter Plan mode when a later Claude turn carries /plan - #2157

Merged
SawyerHood merged 1 commit into
mainfrom
bb/fix-1712-plan-mode-mid-thread
Aug 21, 2026
Merged

SawyerHood merged 1 commit into
mainfrom
bb/fix-1712-plan-mode-mid-thread

Conversation

@SawyerHood

@SawyerHood SawyerHood commented Aug 21, 2026 •

Copy link
Copy Markdown
Collaborator

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 (Ask the user before Claude Code leaves Plan mode #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

Since #1640 the runtime classifies every execution-option change as
"live", so a mid-conversation /plan no longer rebuilds the Claude SDK
session in plan mode. The bridge only applied the permission mode at
session construction and read providerOptions.claudeCodePermissionMode
on turn/start solely to strip the /plan mention, so the prompt was
pushed into a session still in the user's preset mode and Claude
executed the task instead of proposing a plan via ExitPlanMode.

Forward claudeCodePermissionMode into the bridge's internal turn params
and switch the live session into Plan mode (setPermissionMode) before
the prompt is pushed, on both turn/start and turn/steer. The existing
approval path still restores the preset through
approvedPlanPermissionMode.

Co-Authored-By: Claude <[email protected]>
@SawyerHood
SawyerHood marked this pull request as ready for review August 21, 2026 06:14
@SawyerHood
SawyerHood merged commit eec134d into main Aug 21, 2026
13 checks passed
@SawyerHood
SawyerHood deleted the bb/fix-1712-plan-mode-mid-thread branch August 21, 2026 14:38
SawyerHood added a commit that referenced this pull request Aug 21, 2026
Plan mode is keyed on the structured `/plan` command mention the composer
sends, which `bb thread tell`/`spawn` never produced, so the literal
`/plan` text reached the Claude CLI ("/plan isn't available in this
environment"). Add `--plan` to both commands, a shared
`createBuiltinPlanCommandTextInput` helper (exported from @bb/sdk), and
document the surfaces in the guide and bb-cli skill.

The Claude bridge half of #2019 (switching an already-loaded session
into Plan mode when a later turn carries `/plan`) landed in #2157. This
change adds the bridge coverage #2157 left out: the `turn/steer` path
(`--plan` on a busy thread), re-entry after an approved plan, a refused
`setPermissionMode` failing the turn, and `buildClaudeTurnParams`
forwarding the flag.

Co-Authored-By: Claude <[email protected]>
SawyerHood added a commit that referenced this pull request Aug 21, 2026
…on (#2156)

## What was wrong

Issue #2019 (report: https://get-bb.github.io/reports/issues/2019.html)
had two parts.

1. **`/plan` was ignored on an already-loaded Claude Code session.**
This half landed in #2157 (`eec134dc6`): `buildClaudeTurnParams`
forwards `claudeCodePermissionMode`, the bridge turn schemas accept it,
and `enterPlanModeIfRequested` switches the live SDK session into Plan
mode before the prompt is pushed on both `turn/start` and `turn/steer`.
This PR no longer touches that code.
2. **No CLI/SDK way into plan mode.** Plan mode is keyed on the
structured `/plan` command mention the composer sends
(`promptInputHasCommandMention`), and `bb thread tell`/`spawn` always
sent `mentions: []`, so a literal `/plan ...` reached the Claude CLI,
which answered "/plan isn't available in this environment." Agents
driving bb through the CLI or SDK had no parity path. This PR fixes
that.

## What changed

- `packages/domain/src/shared-types.ts`:
`createBuiltinPlanCommandTextInput(text)` builds the same `/plan`
command mention the composer's plan action produces. `@bb/sdk`
re-exports it (core/node/browser) so SDK callers pass it as `input` to
`threads.spawn`/`threads.send`.
- `apps/cli`: `--plan` on `bb thread tell` and `bb thread spawn` uses
that helper. Plain `/plan ...` text is deliberately not parsed (the
report's recommendation): that would silently change meaning for
providers where `/plan` is a real slash command.
- Docs: `packages/templates/src/templates/bb-guide-threads.md` and the
bb-cli `SKILL.md` document `--plan` and the SDK helper.
- Bridge tests only, covering what #2157 left untested (its verifier
noted "only `turn/start` is unit-tested"): `bridge.test.ts` gains a
`turn/steer` case (which is what `bb thread tell --plan` on a busy
thread becomes): entering Plan mode from a steer, a plain follow-up turn
and a repeated `/plan` steer not re-requesting it, re-entry after an
approved plan restored the preset; and a case where a refused
`setPermissionMode("plan")` fails the turn instead of running it in the
old mode. `session-params.test.ts` asserts `buildClaudeTurnParams`
forwards the flag and omits it otherwise. No bridge source changes.

No wire change between server and host daemon, no
`HOST_DAEMON_PROTOCOL_VERSION` or `PROVIDER_BRIDGE_PROTOCOL_VERSION`
bump, no new plugin API members.

## How you verified

Fail-before / pass-after on top of current `origin/main` (`git checkout
origin/main -- <the 7 non-test source files>`, run, restore):

- `apps/cli/src/__tests__/command-output/thread-tell.test.ts` "bb thread
tell --plan sends the composer's /plan command mention" and
`thread-spawn.test.ts` "bb thread spawn --plan opens the thread with the
composer's /plan command mention": on main `error: unknown option
'--plan'` (`Tests 2 failed | 35 skipped`); restored `37 passed (37)`.
- `packages/domain/test/shared-types.test.ts` "builds plan command input
the plan selector recognizes and strips": on main `TypeError:
createBuiltinPlanCommandTextInput is not a function`; restored `11
passed (11)`.
- `plugins/provider-claude-code`: bridge + session-params `84 passed
(84)` (the new bridge cases exercise code that is already on main via
#2157, so they pass on main too; they are coverage, not the proof).

From the committed tree (`git status --porcelain` empty):

- `pnpm exec turbo run typecheck --filter=@bb/domain --filter=@bb/sdk
--filter=@bb/cli --filter=@bb/templates
--filter=bb-plugin-provider-claude-code --filter=@bb/server
--filter=@bb/agent-runtime` -> `Tasks: 11 successful, 11 total`
- `pnpm exec turbo run test --filter=@bb/domain --filter=@bb/sdk
--filter=@bb/cli --filter=@bb/templates
--filter=bb-plugin-provider-claude-code` -> `Tasks: 11 successful, 11
total` (domain 151, sdk 96, cli 455, templates 41, claude plugin 326)
- `pnpm exec turbo run test --filter=@bb/provider-parity --force` ->
`Tasks: 2 successful, 2 total` (43 passed)
- `apps/server` skill tests (`builtin-skills-copy`, `injected-skills`,
`install-cli-skills`): 22 passed.

Manual (earlier revision of this branch, before #2157 merged; the CLI
path is unchanged): against my own dev instance with a real Claude Code
session (`claude-haiku-4-5`), spawned a claude-code thread in
accept-edits, let `Reply only with ok.` finish, then `bb thread tell
<thr> --plan "Create a file named hello.txt ..."` on the loaded session.
The DB `client/turn/requested` event carried the structured `/plan`
command mention, Claude entered Plan mode, `ExitPlanMode` produced a
pending `plan` interaction, no file was written; `bb thread interactions
approve` restored accept-edits and created the file.

Fixes #2019

> AGENT GENERATED: by Claude Opus 5

## Rebase

Rebased onto `origin/main` at `75d6fc4d4` (was 33 commits behind;
conflicted in `bridge.ts` and `bridge.test.ts`). #2157 (`eec134dc6`)
landed the same bridge fix this PR originally carried
(`enterRequestedPlanMode` here, `enterPlanModeIfRequested` there;
identical body, same call sites, same schema and `buildClaudeTurnParams`
hunks). Dropped every bridge source hunk (`bridge.ts`, `commands.ts`,
`session-params.ts`) and this PR's copy of the `turn/start` regression
test in favour of main's. Kept: the CLI `--plan` flag, the domain helper
and SDK export, guide/skill text, and the bridge test cases #2157 lacks
(steer path, plan re-entry, refused switch, turn-params forwarding).
Title, commit message, and this body were rewritten for the reduced
scope; the fail-before/pass-after proof is now the CLI flag and domain
helper.


## Independent verification (post-rebase)

Verified at `69f036642` (PR head) against `origin/main` `85eec4da6` (one
unrelated mobile-workflow commit past the rebase base `75d6fc4d4`; `gh`
reports MERGEABLE).

Root cause check: plan mode is keyed on a `/plan` command mention
(`resolvePromptMode` -> `promptInputHasCommandMention` in
`apps/server/src/services/threads/thread-commands.ts`); the plan
composer action's command is always `{trigger: "/", name: "plan"}`
(`plugin-provider-registration.ts`), so the hardcoded mention the helper
builds matches both Claude Code and Codex. The loaded-session half is on
main via #2157 (`enterPlanModeIfRequested` in `bridge.ts`); this PR adds
no bridge source.

Fail-before / pass-after (`git checkout origin/main -- <9 non-test
source files>`, run, `git checkout HEAD -- ...`):

- `apps/cli` thread-tell/thread-spawn `--plan` tests on main sources:
`error: unknown option '--plan'`, `Tests 2 failed | 35 skipped (37)`;
restored: pass.
- `packages/domain/test/shared-types.test.ts`: `TypeError:
createBuiltinPlanCommandTextInput is not a function`, `1 failed | 10
passed`; restored: pass.

From the committed tree (`git status --porcelain` empty), all with
`--force` (no turbo cache):

- `turbo run typecheck
--filter=@bb/domain,@bb/sdk,@bb/cli,@bb/templates,bb-plugin-provider-claude-code,@bb/server,@bb/agent-runtime`
-> `Tasks: 11 successful, 11 total`
- `turbo run test` for domain/sdk/cli/templates/claude plugin -> `Tasks:
11 successful, 11 total` (domain 151, sdk 96, cli 455, templates 41,
claude plugin 326)
- `turbo run test --filter=@bb/provider-parity --force` -> `Tasks: 2
successful, 2 total` (43 passed)
- `apps/server` skill tests (builtin-skills-copy, injected-skills,
install-cli-skills): 22 passed.

Live repro on the PR branch (own dev instance, real Claude Code,
`BB_CLI` unset so the worktree CLI runs instead of re-execing the
installed binary):

1. `bb thread spawn --provider claude-code --permission-mode
accept-edits --plan --prompt ...`: the `client/turn/requested` event
carries the structured `/plan` mention, the Claude session started in
Plan mode (its reasoning quotes the "Plan mode is active" reminder), the
literal `/plan` was stripped, and there was no "/plan isn't available in
this environment".
2. `bb thread stop`, a plain `bb thread tell ... "Reply only with ok."`
(session reloaded in accept-edits), then `bb thread tell <thr> "Add a
LICENSE file (MIT)..." --plan` on that loaded session: `bb thread
interactions list` shows `plan | pending | Plan ready for review`, no
file written. `bb thread tell --plan` and `--help` both show and accept
the flag.

CI: all checks green on `69f036642` (Checks, Package Smoke x2, Tests
app-1..3/integration/packages/server).

Residual notes (minor, not blocking): `--plan` on a provider that
declares no plan composer action (pi, ACP agents) is not rejected by the
server; the `/plan ...` text reaches the provider verbatim, same as
typing it in the composer. The helper tags the mention `origin:
"builtin"` while the composer's plan action uses `origin: "user"`;
nothing keys plan mode on `origin`.

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

Claude Plan mode can skip the proposal flow in a mid-conversation thread

1 participant