# Useful but Little-Known Features of Claude Agent SDK
๐ Want Claude to plan changes without touching your code? Plan mode restricts the agent to read-only exploration!
Claude Agent SDK's plan mode lets Claude analyze your codebase and propose changes using only read-only tools, never editing source files.
๐ Title: Plan Mode (Read-Only Execution Only)
๐ URL:
๐งฉ Overview
Setting `permission_mode="plan"` restricts Claude to read-only tools such as Read, Grep, Glob, and read-only shell commands. Edit, Write, and write-mode Bash operations are blocked. Claude may use `AskUserQuestion` to clarify requirements before finalizing the plan. This mode is ideal for code review, architecture analysis, and change proposals where you want insights without side effects.
๐ How to Use
```python
# Python - plan mode for code review
import asyncio
from claude_agent_sdk import query, ClaudeAgentOptions
async def main():
async for message in query(
prompt="Analyze security issues in the auth module and propose a fix plan",
options=ClaudeAgentOptions(
permission_mode="plan", # Read-only analysis
),
):
if hasattr(message, "result"):
print(message.result)
```
```typescript
// TypeScript
for await (const message of query({
prompt: "Analyze security issues in the auth module and propose a fix plan",
options: {
permissionMode: "plan" // Read-only analysis
}
})) {
if ("result" in message) console.log(message.result);
}
```
๐ Integration into Production Systems
- Use for automated PR reviews that surface issues and suggestions without modifying code
- Safely explore and understand new codebases during onboarding or investigation phases
- Implement a "plan then execute" workflow: review the plan, then switch to `acceptEdits` mode
- Combine with `set_permission_mode()` to transition from planning to execution after human approval
๐ก Use Cases
๐ Generate change proposals in code reviews, leaving actual modifications to human judgment
๐ Safely analyze architecture of large codebases without risk of accidental changes
๐ Build refactoring plans for team consensus before execution
โ ๏ธ Caveats
- Read-only shell commands may still execute
- `AskUserQuestion` may be triggered, so for fully unattended operation, dontAsk mode is more appropriate
- To act on the plan, you need a new session or a dynamic permission mode change
โจ "Plan first, execute second" is a fundamental engineering practice. Use plan mode to safely analyze, then commit to changes only after you're confident in the approach!
#
ClaudeAgentSDK# #
AIAgent#