CLI: Auto-switch provider/model when LLM delegates to different modes #5356
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 This Does
When Claude uses the
switchModeornewTasktools to automatically delegate work to a different mode, the CLI now automatically switches to that mode's preferred AI provider and model.Previously, only manual
/modecommands would switch the provider/model. Now automatic mode switching works the same way.Why This Matters
If you configure modes with specific providers/models (e.g., use GPT-4 for planning, Claude for coding), the CLI will now respect those preferences even when the LLM switches modes automatically during a task.
Before: LLM switches to "planning" mode → CLI stays on current provider
After: LLM switches to "planning" mode → CLI switches to planning mode's preferred provider/model
Changes Made
File:
cli/src/state/hooks/useApprovalMonitor.tsAdded a new effect that:
switchModeandnewTasktool approvals (both auto and manual)preferredProviderIdandpreferredModelIdHow to Use
custom_modes.yaml:/providercommandTesting
Technical Details
The implementation uses a separate
useEffecthook that monitorslastAskMessagefor answered tool calls. This approach: