Support list-form system_prompt for subprocess CLI (fixes #899)#947
Open
zuhabul wants to merge 2 commits into
Open
Support list-form system_prompt for subprocess CLI (fixes #899)#947zuhabul wants to merge 2 commits into
zuhabul wants to merge 2 commits into
Conversation
…\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>
There was a problem hiding this comment.
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_prompthandling inSubprocessCLITransport._build_command()by writing a temp JSON file and passing it to the CLI. - Refactor
efforttyping to use a newEffortLeveltype 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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.