Skip to content

Support list-form system_prompt for subprocess CLI (fixes #899)#947

Open
zuhabul wants to merge 2 commits into
anthropics:mainfrom
zuhabul:fix/system-prompt-list-899
Open

Support list-form system_prompt for subprocess CLI (fixes #899)#947
zuhabul wants to merge 2 commits into
anthropics:mainfrom
zuhabul:fix/system-prompt-list-899

Conversation

@zuhabul
Copy link
Copy Markdown

@zuhabul zuhabul commented May 10, 2026

Fixes #899 — accept list-of-content-blocks for system_prompt by writing a temp JSON file and passing it to the CLI via --system-prompt-file so the CLI forwards structured content to Anthropic.

…\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…-system-prompt-file (fixes anthropics#899)\n\nCo-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 10, 2026 06:36
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Python SDK’s subprocess-based Claude Code CLI transport to accept Anthropic’s list-of-content-blocks form for system_prompt by serializing the list to JSON and passing it to the CLI via --system-prompt-file.

Changes:

  • Add list-form system_prompt handling in SubprocessCLITransport._build_command() by writing a temp JSON file and passing it to the CLI.
  • Refactor effort typing to use a new EffortLevel type alias (and export it from the package).

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
src/claude_agent_sdk/_internal/transport/subprocess_cli.py Adds list-form system_prompt support via a temporary JSON file and --system-prompt-file.
src/claude_agent_sdk/types.py Introduces/uses EffortLevel for effort fields (currently broken as written).
src/claude_agent_sdk/__init__.py Exports EffortLevel from the package (import block formatting needs cleanup).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +35 to +36
EffortLevel: TypeAlias = EffortLevel

Comment on lines 99 to 102
maxTurns: int | None = None # noqa: N815
background: bool | None = None
effort: Literal["low", "medium", "high", "xhigh", "max"] | int | None = None
effort: EffortLevel | int | None = None
permissionMode: PermissionMode | None = None # noqa: N815
Comment on lines +145 to 147

EffortLevel,)

Comment on lines +234 to +247
if isinstance(sp, list):
# Write JSON array to a temporary file and pass via --system-prompt-file so
# the CLI can forward the structured content as-is.
import tempfile

tmp = tempfile.NamedTemporaryFile("w", delete=False, suffix=".json", encoding="utf-8")
json.dump(sp, tmp)
tmp.flush()
tmp.close()
# Ensure the temporary file is removed when the Python process exits
import atexit, os

atexit.register(lambda p=tmp.name: os.remove(p) if os.path.exists(p) else None)
cmd.extend(["--system-prompt-file", tmp.name])
Comment on lines +244 to +247
import atexit, os

atexit.register(lambda p=tmp.name: os.remove(p) if os.path.exists(p) else None)
cmd.extend(["--system-prompt-file", tmp.name])
Comment on lines +233 to +242
# Support list-of-content-blocks form for system_prompt (Anthropic API accepts this).
if isinstance(sp, list):
# Write JSON array to a temporary file and pass via --system-prompt-file so
# the CLI can forward the structured content as-is.
import tempfile

tmp = tempfile.NamedTemporaryFile("w", delete=False, suffix=".json", encoding="utf-8")
json.dump(sp, tmp)
tmp.flush()
tmp.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

subprocess CLI rejects list-form system_prompt (Anthropic API supports it)

3 participants