# Useful but Little-Known Features of Claude Agent SDK
🌍 Need to change permissions mid-session? You can dynamically switch permission modes during streaming!
Claude Agent SDK lets you call `set_permission_mode()` to instantly change the permission mode while a session is running.
📌 Title: Dynamic Permission Mode Changes During Streaming
🔗 URL:
🧩 Overview
Using `set_permission_mode()` (Python) or `setPermissionMode()` (TypeScript), you can change the permission mode in real-time during an active session. The new mode takes effect immediately for all subsequent tool requests. This enables progressive trust workflows where you start restrictive and loosen permissions as confidence builds, for example switching from `default` to `acceptEdits` after reviewing Claude's initial approach.
🛠 How to Use
```python
# Python - progressively relaxing permissions
import asyncio
from claude_agent_sdk import ClaudeSDKClient, ClaudeAgentOptions
async def main():
async with ClaudeSDKClient(
options=ClaudeAgentOptions(
permission_mode="default", # Start in default mode
)
) as client:
await client.query("Refactor this code")
# After reviewing the approach, allow edits
await client.set_permission_mode("acceptEdits")
async for message in client.receive_response():
if hasattr(message, "result"):
print(message.result)
```
```typescript
// TypeScript
const q = query({
prompt: "Refactor this code",
options: { permissionMode: "default" }
});
// After reviewing the approach, allow edits
await q.setPermissionMode("acceptEdits");
for await (const message of q) {
if ("result" in message) console.log(message.result);
}
```
🏗 Integration into Production Systems
- Implement "plan, review, then acceptEdits" workflows for safe step-by-step automation
- Build interactive apps that progressively expand permissions based on user trust and task progress
- Use as a "fallback" pattern to tighten permissions when errors are detected
- Integrate with monitoring systems to automatically switch to restrictive modes on anomaly detection
💡 Use Cases
🔐 Interactive workflows that grant edit permissions only after code review approval
📈 Progressive automation that expands permissions as the task advances
🛡 Defensive agents that instantly switch to restrictive mode upon detecting anomalies
⚠️ Caveats
- The new mode takes effect immediately, so be careful about the timing of the switch
- Mode changes are only effective within the current session
- Switching to `bypassPermissions` or `auto` mode will be inherited by subagents
✨ Dynamic permission changes enable "start safe, flex as needed." Build progressive trust workflows to get the best of both safety and productivity!
#
ClaudeAgentSDK# #
AIAgent#