Repository navigation
Enter Plan mode when a later Claude turn carries /plan - #2157
Merged
Merged
Conversation
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
marked this pull request as ready for review
August 21, 2026 06:14
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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
A
/plantyped 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 throughExitPlanMode, 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
classifyExecutionSettingsChangealways returns"live", so aclaudeCodePermissionModechange no longer triggers athread/resumesession rebuild. The Claude bridge appliedpermissionModeonly at session construction. Onturn/startandturn/steer,buildClaudeTurnParamsreadproviderOptions.claudeCodePermissionModesolely to strip the/planmention 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:buildClaudeTurnParamsforwardsclaudeCodePermissionModefrom the providerOptions bag into the bridge's internal turn params.src/bridge/commands.ts:claudeTurnStartParamsSchemaandclaudeTurnSteerParamsSchemaacceptclaudeCodePermissionMode: "plan"(optional; undefined keeps the session's current mode, like the other per-turn knobs).src/bridge/bridge.ts: newenterPlanModeIfRequested()awaitssession.setPermissionMode("plan")and recordsthreadSession.permissionMode = "plan"when the turn requests Plan mode and the session is not already in it. Called right afterapplyLiveSessionSettingsin bothrunTurnStartandrunTurnSteer, before the prompt is pushed. A failed control request fails the turn instead of running it in the preset mode.approvedPlanPermissionModeis 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.claudeCodePermissionModeonturn/start; only the plugin's internal turn params change. NoHOST_DAEMON_PROTOCOL_VERSIONbump 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 secondturn/startwith the/planmention plusclaudeCodePermissionMode: "plan", and asserts the SDK query'ssetPermissionMode("plan")was called before the prompt was consumed, the mention was stripped, no session rebuild happened, and approvingExitPlanModerestoresacceptEdits.Fails on origin/main:
Passes with the fix. From the committed tree:
Manual repro on my own dev instance (
scripts/bb-dev-app current, claude-code, accept-edits): threadthr_dsp7xxj6ai, turn 1 "Reply only with ok.", turn 2 posted the composer's/plan Create a file named hello.txt ...input toPOST /api/v1/threads/:id/send. With the fix the second turn wrote~/.claude/plans/create-a-file-named-lovely-cray.md, calledToolSearch select:ExitPlanModethenExitPlanMode, and stopped with a pending plan approval (pint_hmesjr2749);hello.txtwas not created. Afterbb thread interactions approve, the turn completed and createdhello.txtwithout any further prompt (preset restored).Fixes #1712
Independent verification
Verified by a second agent on a fresh checkout of this branch (
3baa83934, rebased onorigin/main;git merge-base --is-ancestor origin/main HEADholds).Root cause re-checked on
origin/mainbefore reading the PR:packages/agent-runtime/src/bridge-protocol-adapter.ts:252still returns"live"for every option change,buildClaudeTurnParamsonly readclaudeCodePermissionModeto strip the mention, and the onlysetPermissionModecaller inbridge.tswas the post-approval restore. The fix sits in the right layer (the server still decides "this is a plan turn" per input intoRuntimeExecutionOptions; the plugin translates it), and nothing on the server/daemon wire changed, so noHOST_DAEMON_PROTOCOL_VERSIONbump is needed.Commands:
Repro on the fixed branch (own dev instance via
scripts/bb-dev-app current, claude-code, accept-edits, threadthr_x9kcmgk9ww): turn 1 "Reply only with ok.", turn 2 posted the composer's/plan Create a file named hello.txt ...input toPOST /api/v1/threads/:id/send. The second turn wrote~/.claude/plans/create-a-file-named-wondrous-dongarra.md, ranToolSearch select:ExitPlanMode, thenExitPlanMode, and stopped on pending plan approvalpint_hbfk74c2p5with the workspace untouched. Afterbb thread interactions approve, the turn completed,hello.txtcontainedhello 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:
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 beforepushPromptInput, and the live repro confirms the plan-mode reminder landed on the same turn.turn/steerthat joins a running turn now flips the live session into Plan mode mid-turn (code path is symmetric withturn/start; onlyturn/startis unit-tested).cancel-planwhen a later turn omits/plan, matching first-turn behavior.cancel-planstops the thread, so the next turn rebuilds the session in the preset mode.