Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/claude_agent_sdk/_internal/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
)

from ..types import (
PermissionMode,
PermissionResultAllow,
PermissionResultDeny,
SDKControlPermissionRequest,
Expand Down Expand Up @@ -569,7 +570,7 @@ async def interrupt(self) -> None:
"""Send interrupt control request."""
await self._send_control_request({"subtype": "interrupt"})

async def set_permission_mode(self, mode: str) -> None:
async def set_permission_mode(self, mode: PermissionMode) -> None:
"""Change permission mode."""
await self._send_control_request(
{
Expand Down
5 changes: 4 additions & 1 deletion src/claude_agent_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
HookMatcher,
McpStatusResponse,
Message,
PermissionMode,
ResultMessage,
)

Expand Down Expand Up @@ -230,14 +231,16 @@ async def interrupt(self) -> None:
raise CLIConnectionError("Not connected. Call connect() first.")
await self._query.interrupt()

async def set_permission_mode(self, mode: str) -> None:
async def set_permission_mode(self, mode: PermissionMode) -> None:
"""Change permission mode during conversation (only works with streaming mode).

Args:
mode: The permission mode to set. Valid options:
- 'default': CLI prompts for dangerous tools
- 'acceptEdits': Auto-accept file edits
- 'plan': Plan-only mode (no tool execution)
- 'bypassPermissions': Allow all tools (use with caution)
- 'dontAsk': Allow all tools without prompting

Example:
```python
Expand Down
2 changes: 2 additions & 0 deletions src/claude_agent_sdk/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ async def query(
Set options.permission_mode to control tool execution:
- 'default': CLI prompts for dangerous tools
- 'acceptEdits': Auto-accept file edits
- 'plan': Plan-only mode (no tool execution)
- 'bypassPermissions': Allow all tools (use with caution)
- 'dontAsk': Allow all tools without prompting
Set options.cwd for working directory.
transport: Optional transport implementation. If provided, this will be used
instead of the default transport selection based on options.
Expand Down
7 changes: 4 additions & 3 deletions src/claude_agent_sdk/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
McpServer = Any

# Permission modes
PermissionMode = Literal["default", "acceptEdits", "plan", "bypassPermissions"]
PermissionMode = Literal[
"default", "acceptEdits", "plan", "bypassPermissions", "dontAsk"
]

# SDK Beta features - see https://docs.anthropic.com/en/api/beta-headers
SdkBeta = Literal["context-1m-2025-08-07"]
Expand Down Expand Up @@ -1146,8 +1148,7 @@ class SDKControlInitializeRequest(TypedDict):

class SDKControlSetPermissionModeRequest(TypedDict):
subtype: Literal["set_permission_mode"]
# TODO: Add PermissionMode
mode: str
mode: PermissionMode


class SDKHookCallbackRequest(TypedDict):
Expand Down
11 changes: 11 additions & 0 deletions tests/test_transport.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,17 @@ def test_build_command_with_options(self):
assert "--max-turns" in cmd
assert "5" in cmd

def test_build_command_with_dont_ask_permission_mode(self):
"""Test building CLI command with dontAsk permission mode."""
transport = SubprocessCLITransport(
prompt="test",
options=make_options(permission_mode="dontAsk"),
)

cmd = transport._build_command()
assert "--permission-mode" in cmd
assert "dontAsk" in cmd

def test_build_command_with_fallback_model(self):
"""Test building CLI command with fallback_model option."""
transport = SubprocessCLITransport(
Expand Down
3 changes: 3 additions & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ def test_claude_code_options_with_permission_mode(self):
options_accept = ClaudeAgentOptions(permission_mode="acceptEdits")
assert options_accept.permission_mode == "acceptEdits"

options_dont_ask = ClaudeAgentOptions(permission_mode="dontAsk")
assert options_dont_ask.permission_mode == "dontAsk"

def test_claude_code_options_with_system_prompt_string(self):
"""Test Options with system prompt as string."""
options = ClaudeAgentOptions(
Expand Down
Loading