Skip to content
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

### Bug Fixes

- **List-form `system_prompt` validation**: Fast-failed invalid list-form `system_prompt` values with a clear `ValueError` at construction instead of a delayed transport-time crash.
- **Zombie CLI subprocess prevention**: Shielded subprocess cleanup from asyncio cancellation so `SIGTERM`/`SIGKILL` teardown always runs, preventing orphaned `claude` child processes when the parent task is cancelled (#1082)
- **Silent whitespace loss on large NDJSON lines**: Fixed the NDJSON parser silently dropping whitespace when a single line exceeded the 64 KiB stream buffer, which could corrupt tool output or assistant message content (#1083)
- **TypeError on non-dict message content**: Fixed an uncaught `TypeError` when the CLI emits a message whose `content` field is a plain string or other non-dict value instead of the expected list of content blocks (#1058)
Expand Down
18 changes: 18 additions & 0 deletions src/claude_agent_sdk/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1757,6 +1757,11 @@ class ClaudeAgentOptions:
system prompt.
- ``{"type": "preset", "preset": "claude_code", "append": "..."}`` — Default
prompt with appended instructions.

A list of Anthropic content blocks (the Messages API ``system`` list form)
is not accepted: the bundled CLI forwards the system prompt as plain text,
so per-block ``cache_control`` cannot pass through it. Passing a list
raises ``ValueError`` at construction rather than failing later.
"""

mcp_servers: dict[str, McpServerConfig] | str | Path = field(default_factory=dict)
Expand Down Expand Up @@ -2091,6 +2096,19 @@ class ClaudeAgentOptions:
header.
"""

def __post_init__(self) -> None:
if isinstance(self.system_prompt, list):
raise ValueError(
"system_prompt does not accept a list of content blocks. The "
"bundled Claude Code CLI forwards the system prompt as plain "
"text only, so per-block cache_control cannot be sent through "
"it; carrying the list form to the Messages API requires a "
"CLI-side flag that does not exist yet. Concatenate the blocks "
"into a single string (this merges the layers into one cache "
"prefix, losing layer-independent prompt caching), or pass a "
"preset/file system prompt instead."
)


# SDK Control Protocol
class SDKControlInterruptRequest(TypedDict):
Expand Down
12 changes: 12 additions & 0 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

from typing import get_args

import pytest

from claude_agent_sdk import (
AssistantMessage,
ClaudeAgentOptions,
Expand Down Expand Up @@ -228,6 +230,16 @@ def test_claude_code_options_with_system_prompt_file(self):
"path": "/path/to/prompt.md",
}

def test_claude_code_options_with_system_prompt_list_rejected(self):
"""Test Options rejects list-form system prompt with a clear error."""
with pytest.raises(ValueError, match="does not accept a list"):
ClaudeAgentOptions(
system_prompt=[
{"type": "text", "text": "hello"},
{"type": "text", "text": "world"},
],
)

def test_claude_code_options_with_session_continuation(self):
"""Test Options with session continuation."""
options = ClaudeAgentOptions(continue_conversation=True, resume="session-123")
Expand Down