EnterPlanModeTool: Enter Plan Mode
8/2/2026, 3:19:09 PM · Source
AI-translated on 8/2/2026, 3:20:10 PM · by Qwen3.6 35B (fast, default)
In-depth analysis of the underlying Agent tool in Claude Code — EnterPlanModeTool: It is not merely a simple prompt hint, but a runtime state transition (permission mode → plan), involving permission updates, context reconstruction, and main thread flow control.
Its essence is state switching, not prompt switching
The purpose of EnterPlanModeTool is not to "make the model think for a while," but to switch the current session to a new runtime state: plan.
This means the system simultaneously changes:
- Permission mode
- Session objective
- User interaction expectations
So it is essentially a runtime state switching tool.
Key source code
tools/EnterPlanModeTool/EnterPlanModeTool.ts:
import { handlePlanModeTransition } from '../../bootstrap/state.js'
import { applyPermissionUpdate } from '../../utils/permissions/PermissionUpdate.js'
import { prepareContextForPlanMode } from '../../utils/permissions/permissionSetup.js'
The actual core logic is in call():
context.setAppState(prev => ({
...prev,
toolPermissionContext: applyPermissionUpdate(
prepareContextForPlanMode(prev.toolPermissionContext),
{ type: 'setMode', mode: 'plan', destination: 'session' },
),
}))
Call chain
Model determines task is too large/complex > EnterPlanModeTool > update permission mode to plan > prepare Plan Mode context > main thread enters planning state
Why it cannot be used casually in an agent context
There is a hard constraint in the source code:
if (context.agentId) {
throw new Error('EnterPlanMode tool cannot be used in agent contexts')
}
This indicates that Anthropic does not want child agents to casually switch themselves into Plan Mode,
but rather leave this kind of workflow control to the main thread.
Its relationship with AskUserQuestionTool
Plan Mode is not about writing a plan in isolation.
If requirements are unclear, you still need to use AskUserQuestionTool to gather information first before proceeding with that plan.
Summary
The value of EnterPlanModeTool lies in:
It upgrades "plan first, code later" from a mere prompting habit into an official state machine transition within the Claude Code runtime.
Learning map
🗺️ Plan Mode Learning Roadmap
Stage 1 - Understanding the Agent State Machine
- What is Agent Context versus Session Context
- The significance of the
agentIdconstraint: sub-agents cannot arbitrarily switch states
Stage 2 - Mastering the Underlying Mechanics of Plan Mode
handlePlanModeTransition— Session goal transitionapplyPermissionUpdate+prepareContextForPlanMode— Permission & context reconstruction- The structural meaning of
toolPermissionContext.type: 'setMode'
Stage 3 - Learning to Use Plan Mode Within the Agent Lifecycle
- When to invoke EnterPlanMode (when tasks are too large or overly complex)
- When to fall back to AskUserQuestionTool to gather requirements
- Proper integration with the coding phase (planning → Code Action)
Stage 4 - Advanced: Custom Context Management
- Understanding the immutable update pattern of
context.setAppState - Monitoring permission changes (
toolPermissionContext.mode: 'plan') - Alternative approaches in sub-agent scenarios
Get hands-on — step by step
- Install the Claude Code CLI, open the terminal and enter
claude. - Initiate a multi-step task (e.g., create a to-do app + add styling + configure routing).
- After entering your requirements in the conversation, observe whether a Tool Call automatically enters Plan Mode.
- If it doesn't trigger automatically, manually execute the tool call
EnterPlanModeTool(via code layer or MCP plugin injection). - Check the returned
toolPermissionContextchanges: mode → 'plan'. - In plan state, describe your architecture design in text, and confirm that permissions have switched (read-only planning permissions take effect).
- If additional information is needed, call
AskUserQuestionToolto ask the user questions. - After the plan is complete, observe the main thread automatically switching from 'plan' back to 'agent' coding state.
- Compare Plan Mode: list differences in permission modes, updates to session objectives, and changes in interaction expectations (create a table or notes).
- Advanced attempt: Set sub-agent code as context with an
agentId, callEnterPlanModeToolagain, and observe the hard Error thrown.
Top 3 sources
- 1Anthropic Claude Code 官方文档
Claude Code Agent、工具系统、权限与上下文管理的官方权威说明。
https://docs.anthropic.com/en/docs/build-with-claude/claude-code-overview
- 2Anthropic AI 工程设计文章:Stateful Planning Agents
Anthropic 官方博客关于 Agent 规划、状态切换与多步骤任务管理的原理指南。
https://www.anthropic.com/engineering/building-effective-agents
- 3claude-code GitHub 仓库
Anthropic 官方开源的 Claude Code CLI — 可直接查看 EnterPlanModeTool、permissionUpdate 等方法的原厂实现源码。
https://github.com/anthropics/claude-code
Links are AI-suggested — worth a quick sanity check before diving in.