clawd-code-sdk 1.5.2__tar.gz → 1.6.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/PKG-INFO +69 -38
  2. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/README.md +48 -15
  3. clawd_code_sdk-1.6.2/pyproject.toml +335 -0
  4. clawd_code_sdk-1.5.2/pyproject.toml → clawd_code_sdk-1.6.2/pyproject.toml.orig +131 -35
  5. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/__init__.py +3 -6
  6. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/_errors.py +9 -0
  7. clawd_code_sdk-1.6.2/src/clawd_code_sdk/_internal/option_warnings.py +71 -0
  8. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/_internal/query.py +75 -26
  9. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/_internal/sdk_mcp_bridge.py +9 -11
  10. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/_internal/session_mutations.py +1 -1
  11. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/_internal/sessions.py +5 -5
  12. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/_internal/transport/subprocess_cli.py +27 -4
  13. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/_internal/transport/subprocess_utils.py +170 -55
  14. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/client.py +113 -15
  15. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/instrumentation.py +6 -8
  16. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/mcp_utils.py +25 -33
  17. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/__init__.py +8 -0
  18. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/content_blocks.py +1 -1
  19. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/control.py +22 -18
  20. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/hooks.py +38 -0
  21. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/messages.py +2 -2
  22. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/options.py +23 -1
  23. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/system_messages.py +1 -1
  24. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/session.py +40 -9
  25. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/storage/chain.py +1 -1
  26. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/storage/helpers.py +17 -5
  27. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/storage/models.py +10 -12
  28. clawd_code_sdk-1.5.2/.gitignore +0 -54
  29. clawd_code_sdk-1.5.2/tests/__init__.py +0 -1
  30. clawd_code_sdk-1.5.2/tests/conftest.py +0 -35
  31. clawd_code_sdk-1.5.2/tests/e2e/__init__.py +0 -1
  32. clawd_code_sdk-1.5.2/tests/e2e/test_agents_and_settings.py +0 -498
  33. clawd_code_sdk-1.5.2/tests/e2e/test_dynamic_control.py +0 -71
  34. clawd_code_sdk-1.5.2/tests/e2e/test_hook_events.py +0 -185
  35. clawd_code_sdk-1.5.2/tests/e2e/test_hooks.py +0 -158
  36. clawd_code_sdk-1.5.2/tests/e2e/test_include_partial_messages.py +0 -91
  37. clawd_code_sdk-1.5.2/tests/e2e/test_mcp_resources.py +0 -72
  38. clawd_code_sdk-1.5.2/tests/e2e/test_mcp_tools.py +0 -246
  39. clawd_code_sdk-1.5.2/tests/e2e/test_sdk_mcp_resources.py +0 -78
  40. clawd_code_sdk-1.5.2/tests/e2e/test_sdk_mcp_tools.py +0 -119
  41. clawd_code_sdk-1.5.2/tests/e2e/test_slash_commands.py +0 -24
  42. clawd_code_sdk-1.5.2/tests/e2e/test_stderr_callback.py +0 -48
  43. clawd_code_sdk-1.5.2/tests/e2e/test_storage_parsing.py +0 -26
  44. clawd_code_sdk-1.5.2/tests/e2e/test_structured_output.py +0 -175
  45. clawd_code_sdk-1.5.2/tests/e2e/test_subagent_invocation.py +0 -170
  46. clawd_code_sdk-1.5.2/tests/e2e/test_tool_permissions.py +0 -68
  47. clawd_code_sdk-1.5.2/tests/mcp_server.py +0 -58
  48. clawd_code_sdk-1.5.2/tests/mock_claude_server.py +0 -100
  49. clawd_code_sdk-1.5.2/tests/test_api_content_blocks.py +0 -183
  50. clawd_code_sdk-1.5.2/tests/test_apply_flag_settings.py +0 -28
  51. clawd_code_sdk-1.5.2/tests/test_changelog.py +0 -81
  52. clawd_code_sdk-1.5.2/tests/test_client.py +0 -530
  53. clawd_code_sdk-1.5.2/tests/test_elicitation_mcp_conversion.py +0 -41
  54. clawd_code_sdk-1.5.2/tests/test_errors.py +0 -132
  55. clawd_code_sdk-1.5.2/tests/test_get_usage.py +0 -103
  56. clawd_code_sdk-1.5.2/tests/test_image.png +0 -0
  57. clawd_code_sdk-1.5.2/tests/test_initialize_fields.py +0 -103
  58. clawd_code_sdk-1.5.2/tests/test_integration.py +0 -335
  59. clawd_code_sdk-1.5.2/tests/test_line_framing.py +0 -84
  60. clawd_code_sdk-1.5.2/tests/test_mcp_delivery.py +0 -88
  61. clawd_code_sdk-1.5.2/tests/test_message_parser.py +0 -34
  62. clawd_code_sdk-1.5.2/tests/test_permission_flags.py +0 -16
  63. clawd_code_sdk-1.5.2/tests/test_result_error.py +0 -108
  64. clawd_code_sdk-1.5.2/tests/test_sandbox_settings.py +0 -63
  65. clawd_code_sdk-1.5.2/tests/test_sdk_0_3_types.py +0 -244
  66. clawd_code_sdk-1.5.2/tests/test_sdk_mcp_integration.py +0 -375
  67. clawd_code_sdk-1.5.2/tests/test_session.py +0 -633
  68. clawd_code_sdk-1.5.2/tests/test_session_mutations.py +0 -741
  69. clawd_code_sdk-1.5.2/tests/test_session_title.py +0 -51
  70. clawd_code_sdk-1.5.2/tests/test_sessions.py +0 -2106
  71. clawd_code_sdk-1.5.2/tests/test_steer.py +0 -89
  72. clawd_code_sdk-1.5.2/tests/test_storage_chain.py +0 -205
  73. clawd_code_sdk-1.5.2/tests/test_storage_entries.py +0 -357
  74. clawd_code_sdk-1.5.2/tests/test_streaming_client.py +0 -958
  75. clawd_code_sdk-1.5.2/tests/test_subprocess_buffering.py +0 -283
  76. clawd_code_sdk-1.5.2/tests/test_tool_callbacks.py +0 -682
  77. clawd_code_sdk-1.5.2/tests/test_transport.py +0 -898
  78. clawd_code_sdk-1.5.2/tests/test_transport_close.py +0 -84
  79. clawd_code_sdk-1.5.2/tests/test_unknown_entries.py +0 -53
  80. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/LICENSE +0 -0
  81. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/_bundled/.gitignore +0 -0
  82. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/_internal/__init__.py +0 -0
  83. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/_internal/mcp_compat.py +0 -0
  84. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/_internal/transport/__init__.py +0 -0
  85. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/_version.py +0 -0
  86. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/anthropic_stream.py +0 -0
  87. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/agents.py +0 -0
  88. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/anthropic_types.py +0 -0
  89. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/base.py +0 -0
  90. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/context_usage.py +0 -0
  91. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/input_types.py +0 -0
  92. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/mcp.py +0 -0
  93. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/output_types.py +0 -0
  94. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/permissions.py +0 -0
  95. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/prompt_requests.py +0 -0
  96. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/prompts.py +0 -0
  97. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/server_info.py +0 -0
  98. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/session.py +0 -0
  99. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/settings.py +0 -0
  100. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/thinking.py +0 -0
  101. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/usage.py +0 -0
  102. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/py.typed +0 -0
  103. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/storage/ARCHITECTURE.md +0 -0
  104. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/storage/__init__.py +0 -0
  105. {clawd_code_sdk-1.5.2 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/storage/replay.py +0 -0
@@ -1,41 +1,39 @@
1
- Metadata-Version: 2.5
1
+ Metadata-Version: 2.4
2
2
  Name: clawd-code-sdk
3
- Version: 1.5.2
3
+ Version: 1.6.2
4
4
  Summary: Python SDK for Claude Code
5
- Project-URL: Documentation, https://github.com/phil65/claude-agent-sdk-python
6
- Project-URL: Homepage, https://github.com/phil65/claude-agent-sdk-python
7
- Project-URL: Issues, https://github.com/phil65/claude-agent-sdk-python/issues
8
- Author-email: phil65 <philipptemminghoff@gmail.com>
5
+ Keywords: ai,anthropic,claude,sdk
6
+ Author: Philipp Temminghoff
7
+ Author-email: Philipp Temminghoff <philipptemminghoff@gmail.com>
9
8
  License-Expression: MIT
10
9
  License-File: LICENSE
11
- Keywords: ai,anthropic,claude,sdk
12
10
  Classifier: Development Status :: 3 - Alpha
11
+ Classifier: Framework :: Pydantic
12
+ Classifier: Framework :: Pydantic :: 2
13
13
  Classifier: Intended Audience :: Developers
14
14
  Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
15
16
  Classifier: Programming Language :: Python :: 3
16
- Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3 :: Only
17
18
  Classifier: Programming Language :: Python :: 3.14
18
19
  Classifier: Typing :: Typed
19
- Requires-Python: >=3.13
20
20
  Requires-Dist: anthropic>=2.9.0
21
21
  Requires-Dist: anyenv>=2.0.15
22
22
  Requires-Dist: anyio>=4.0.0
23
23
  Requires-Dist: jsonschema>=4.20.0
24
- Requires-Dist: logfire>=4.32.1
25
- Requires-Dist: mcp<3.0.0,>=1.23.0
26
- Requires-Dist: python-dotenv>=1.2.1
27
- Provides-Extra: dev
28
- Requires-Dist: anyio[trio]>=4.0.0; extra == 'dev'
29
- Requires-Dist: fastmcp>=3.0.0; extra == 'dev'
30
- Requires-Dist: pytest-asyncio>=0.20.0; extra == 'dev'
31
- Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
32
- Requires-Dist: pytest-timeout>=2.4.0; extra == 'dev'
33
- Requires-Dist: pytest>=7.0.0; extra == 'dev'
34
- Requires-Dist: ruff>=0.1.0; extra == 'dev'
35
- Requires-Dist: ty; extra == 'dev'
36
- Requires-Dist: types-jsonschema>=4.20.0; extra == 'dev'
24
+ Requires-Dist: logfire>=6.0
25
+ Requires-Dist: mcp>=1.23.0,<3.0.0
26
+ Requires-Dist: opentelemetry-api>=1.20.0 ; extra == 'otel'
27
+ Requires-Python: >=3.14
28
+ Project-URL: Code coverage, https://app.codecov.io/gh/phil65/claude-agent-sdk-python
29
+ Project-URL: Documentation, https://phil65.github.io/claude-agent-sdk-python/
30
+ Project-URL: Issues, https://github.com/phil65/claude-agent-sdk-python/issues
31
+ Project-URL: Source, https://github.com/phil65/claude-agent-sdk-python
32
+ Project-URL: Spec: Agent SDK (Python), https://github.com/anthropics/claude-agent-sdk-python
33
+ Project-URL: Spec: Agent SDK (TypeScript), https://www.npmjs.com/package/@anthropic-ai/claude-agent-sdk
34
+ Project-URL: Spec: Claude Code CLI, https://code.claude.com/docs/en/cli-reference
35
+ Project-URL: Spec: Claude Code settings, https://json.schemastore.org/claude-code-settings.json
37
36
  Provides-Extra: otel
38
- Requires-Dist: opentelemetry-api>=1.20.0; extra == 'otel'
39
37
  Description-Content-Type: text/markdown
40
38
 
41
39
  # Claude Agent SDK for Python
@@ -59,10 +57,12 @@ uv add clawd-code-sdk
59
57
  import anyio
60
58
  from clawd_code_sdk import ClaudeSDKClient
61
59
 
60
+
62
61
  async def main():
63
62
  async for message in ClaudeSDKClient.one_shot("What is 2 + 2?"):
64
63
  print(message)
65
64
 
65
+
66
66
  anyio.run(main)
67
67
  ```
68
68
 
@@ -156,10 +156,10 @@ Key points:
156
156
 
157
157
  ```python
158
158
  options = ClaudeAgentOptions(
159
- tools=["Read", "Write", "Bash"], # tools available to the agent
160
- allowed_tools=["Read", "Write", "Bash"], # auto-approved (no permission prompt)
161
- disallowed_tools=["WebFetch"], # completely removed from context
162
- permission_mode="acceptEdits", # auto-accept file edits
159
+ tools=["Read", "Write", "Bash"], # tools available to the agent
160
+ allowed_tools=["Read", "Write", "Bash"], # auto-approved (no permission prompt)
161
+ disallowed_tools=["WebFetch"], # completely removed from context
162
+ permission_mode="acceptEdits", # auto-accept file edits
163
163
  )
164
164
  ```
165
165
 
@@ -169,8 +169,8 @@ options = ClaudeAgentOptions(
169
169
  from pathlib import Path
170
170
 
171
171
  options = ClaudeAgentOptions(
172
- cwd="/path/to/project", # or Path("/path/to/project")
173
- add_dirs=["/other/project"], # additional working directories
172
+ cwd="/path/to/project", # or Path("/path/to/project")
173
+ add_dirs=["/other/project"], # additional working directories
174
174
  )
175
175
  ```
176
176
 
@@ -187,6 +187,17 @@ options = ClaudeAgentOptions(
187
187
  )
188
188
  ```
189
189
 
190
+ ### Fine-grained tool streaming
191
+
192
+ `fine_grained_tool_streaming` (`"auto"` by default, or `True` / `False`) makes the API stream
193
+ tool input as the model writes it: `stream_event` messages then carry the input of a long
194
+ `Write` or `Edit` live, which a UI can render, and the tool call starts sooner. It saves no
195
+ tokens. The trade-off is compatibility: the partial tool input JSON is not validated, and
196
+ proxies, gateways and some Bedrock / Vertex models reject the request with HTTP 400. `"auto"`
197
+ turns it on only when Claude Code talks to Anthropic's API directly (no
198
+ `CLAUDE_CODE_USE_BEDROCK` / `CLAUDE_CODE_USE_VERTEX` / other provider, `ANTHROPIC_BASE_URL` unset
199
+ or `api.anthropic.com`) and leaves Claude Code's own default otherwise.
200
+
190
201
  ### Session Management
191
202
 
192
203
  ```python
@@ -210,10 +221,12 @@ options = ClaudeAgentOptions(session=ContinueLatest())
210
221
  ```python
211
222
  from pydantic import BaseModel
212
223
 
224
+
213
225
  class Joke(BaseModel):
214
226
  setup: str
215
227
  punchline: str
216
228
 
229
+
217
230
  options = ClaudeAgentOptions(
218
231
  output_schema=Joke, # accepts Pydantic models, dataclasses, TypedDicts, or raw dicts
219
232
  )
@@ -229,10 +242,12 @@ or IPC overhead:
229
242
  ```python
230
243
  from clawd_code_sdk import tool, create_sdk_mcp_server, ClaudeAgentOptions, ClaudeSDKClient
231
244
 
245
+
232
246
  @tool("greet", "Greet a user", {"name": str})
233
247
  async def greet_user(args):
234
248
  return {"content": [{"type": "text", "text": f"Hello, {args['name']}!"}]}
235
249
 
250
+
236
251
  server = create_sdk_mcp_server(
237
252
  name="my-tools",
238
253
  version="1.0.0",
@@ -272,8 +287,8 @@ SDK and external servers can be used together:
272
287
  ```python
273
288
  options = ClaudeAgentOptions(
274
289
  mcp_servers={
275
- "internal": sdk_server, # in-process
276
- "git": McpStdioServerConfig(command="uvx", args=["mcp-server-git"]), # subprocess
290
+ "internal": sdk_server, # in-process
291
+ "git": McpStdioServerConfig(command="uvx", args=["mcp-server-git"]), # subprocess
277
292
  }
278
293
  )
279
294
  ```
@@ -294,6 +309,7 @@ from clawd_code_sdk import (
294
309
  HookContext,
295
310
  )
296
311
 
312
+
297
313
  async def check_bash_command(
298
314
  input_data: PreToolUseHookInput,
299
315
  tool_use_id: str | None,
@@ -311,6 +327,7 @@ async def check_bash_command(
311
327
  }
312
328
  return {}
313
329
 
330
+
314
331
  options = ClaudeAgentOptions(
315
332
  allowed_tools=["Bash"],
316
333
  hooks={
@@ -373,7 +390,12 @@ async with ClaudeSDKClient() as client:
373
390
  Define subagents with their own prompts, tools, and MCP servers:
374
391
 
375
392
  ```python
376
- from clawd_code_sdk import ClaudeAgentOptions, ClaudeSDKClient, AgentDefinition, McpStdioServerConfig
393
+ from clawd_code_sdk import (
394
+ ClaudeAgentOptions,
395
+ ClaudeSDKClient,
396
+ AgentDefinition,
397
+ McpStdioServerConfig,
398
+ )
377
399
 
378
400
  options = ClaudeAgentOptions(
379
401
  agents={
@@ -431,14 +453,14 @@ for complete type definitions.
431
453
 
432
454
  ```python
433
455
  from clawd_code_sdk import (
434
- ClaudeSDKError, # Base error
435
- CLINotFoundError, # Claude Code not installed
456
+ ClaudeSDKError, # Base error
457
+ CLINotFoundError, # Claude Code not installed
436
458
  CLIConnectionError, # Connection issues
437
- ProcessError, # Process failed
459
+ ProcessError, # Process failed
438
460
  CLIJSONDecodeError, # JSON parsing issues
439
- BillingError, # Insufficient credits
440
- RateLimitError, # Rate limited
441
- AuthenticationError, # Invalid API key
461
+ BillingError, # Insufficient credits
462
+ RateLimitError, # Rate limited
463
+ AuthenticationError, # Invalid API key
442
464
  )
443
465
 
444
466
  try:
@@ -452,6 +474,15 @@ except ProcessError as e:
452
474
 
453
475
  See [src/clawd_code_sdk/\_errors.py](src/clawd_code_sdk/_errors.py) for all error types.
454
476
 
477
+ ### Unknown message types
478
+
479
+ A newer Claude Code CLI can send message types (or system message subtypes) this SDK does not
480
+ model yet. `receive_messages()` / `receive_response()` skip them and log a warning once per type,
481
+ so the stream keeps going. Set `CLAWD_STRICT_MESSAGES=1` (also `true`, `yes`, `on`) to raise
482
+ `MessageParseError` instead, which ends the stream. Recommended in development and CI, so a CLI
483
+ update that adds message types is noticed; this repo's test suite sets it in `tests/conftest.py`.
484
+ `parse_message()` itself always raises, and malformed messages of known types always raise.
485
+
455
486
  ## Available Tools
456
487
 
457
488
  See the [Claude Code documentation](https://docs.anthropic.com/en/docs/claude-code/settings#tools-available-to-claude) for a complete list of available tools.
@@ -19,10 +19,12 @@ uv add clawd-code-sdk
19
19
  import anyio
20
20
  from clawd_code_sdk import ClaudeSDKClient
21
21
 
22
+
22
23
  async def main():
23
24
  async for message in ClaudeSDKClient.one_shot("What is 2 + 2?"):
24
25
  print(message)
25
26
 
27
+
26
28
  anyio.run(main)
27
29
  ```
28
30
 
@@ -116,10 +118,10 @@ Key points:
116
118
 
117
119
  ```python
118
120
  options = ClaudeAgentOptions(
119
- tools=["Read", "Write", "Bash"], # tools available to the agent
120
- allowed_tools=["Read", "Write", "Bash"], # auto-approved (no permission prompt)
121
- disallowed_tools=["WebFetch"], # completely removed from context
122
- permission_mode="acceptEdits", # auto-accept file edits
121
+ tools=["Read", "Write", "Bash"], # tools available to the agent
122
+ allowed_tools=["Read", "Write", "Bash"], # auto-approved (no permission prompt)
123
+ disallowed_tools=["WebFetch"], # completely removed from context
124
+ permission_mode="acceptEdits", # auto-accept file edits
123
125
  )
124
126
  ```
125
127
 
@@ -129,8 +131,8 @@ options = ClaudeAgentOptions(
129
131
  from pathlib import Path
130
132
 
131
133
  options = ClaudeAgentOptions(
132
- cwd="/path/to/project", # or Path("/path/to/project")
133
- add_dirs=["/other/project"], # additional working directories
134
+ cwd="/path/to/project", # or Path("/path/to/project")
135
+ add_dirs=["/other/project"], # additional working directories
134
136
  )
135
137
  ```
136
138
 
@@ -147,6 +149,17 @@ options = ClaudeAgentOptions(
147
149
  )
148
150
  ```
149
151
 
152
+ ### Fine-grained tool streaming
153
+
154
+ `fine_grained_tool_streaming` (`"auto"` by default, or `True` / `False`) makes the API stream
155
+ tool input as the model writes it: `stream_event` messages then carry the input of a long
156
+ `Write` or `Edit` live, which a UI can render, and the tool call starts sooner. It saves no
157
+ tokens. The trade-off is compatibility: the partial tool input JSON is not validated, and
158
+ proxies, gateways and some Bedrock / Vertex models reject the request with HTTP 400. `"auto"`
159
+ turns it on only when Claude Code talks to Anthropic's API directly (no
160
+ `CLAUDE_CODE_USE_BEDROCK` / `CLAUDE_CODE_USE_VERTEX` / other provider, `ANTHROPIC_BASE_URL` unset
161
+ or `api.anthropic.com`) and leaves Claude Code's own default otherwise.
162
+
150
163
  ### Session Management
151
164
 
152
165
  ```python
@@ -170,10 +183,12 @@ options = ClaudeAgentOptions(session=ContinueLatest())
170
183
  ```python
171
184
  from pydantic import BaseModel
172
185
 
186
+
173
187
  class Joke(BaseModel):
174
188
  setup: str
175
189
  punchline: str
176
190
 
191
+
177
192
  options = ClaudeAgentOptions(
178
193
  output_schema=Joke, # accepts Pydantic models, dataclasses, TypedDicts, or raw dicts
179
194
  )
@@ -189,10 +204,12 @@ or IPC overhead:
189
204
  ```python
190
205
  from clawd_code_sdk import tool, create_sdk_mcp_server, ClaudeAgentOptions, ClaudeSDKClient
191
206
 
207
+
192
208
  @tool("greet", "Greet a user", {"name": str})
193
209
  async def greet_user(args):
194
210
  return {"content": [{"type": "text", "text": f"Hello, {args['name']}!"}]}
195
211
 
212
+
196
213
  server = create_sdk_mcp_server(
197
214
  name="my-tools",
198
215
  version="1.0.0",
@@ -232,8 +249,8 @@ SDK and external servers can be used together:
232
249
  ```python
233
250
  options = ClaudeAgentOptions(
234
251
  mcp_servers={
235
- "internal": sdk_server, # in-process
236
- "git": McpStdioServerConfig(command="uvx", args=["mcp-server-git"]), # subprocess
252
+ "internal": sdk_server, # in-process
253
+ "git": McpStdioServerConfig(command="uvx", args=["mcp-server-git"]), # subprocess
237
254
  }
238
255
  )
239
256
  ```
@@ -254,6 +271,7 @@ from clawd_code_sdk import (
254
271
  HookContext,
255
272
  )
256
273
 
274
+
257
275
  async def check_bash_command(
258
276
  input_data: PreToolUseHookInput,
259
277
  tool_use_id: str | None,
@@ -271,6 +289,7 @@ async def check_bash_command(
271
289
  }
272
290
  return {}
273
291
 
292
+
274
293
  options = ClaudeAgentOptions(
275
294
  allowed_tools=["Bash"],
276
295
  hooks={
@@ -333,7 +352,12 @@ async with ClaudeSDKClient() as client:
333
352
  Define subagents with their own prompts, tools, and MCP servers:
334
353
 
335
354
  ```python
336
- from clawd_code_sdk import ClaudeAgentOptions, ClaudeSDKClient, AgentDefinition, McpStdioServerConfig
355
+ from clawd_code_sdk import (
356
+ ClaudeAgentOptions,
357
+ ClaudeSDKClient,
358
+ AgentDefinition,
359
+ McpStdioServerConfig,
360
+ )
337
361
 
338
362
  options = ClaudeAgentOptions(
339
363
  agents={
@@ -391,14 +415,14 @@ for complete type definitions.
391
415
 
392
416
  ```python
393
417
  from clawd_code_sdk import (
394
- ClaudeSDKError, # Base error
395
- CLINotFoundError, # Claude Code not installed
418
+ ClaudeSDKError, # Base error
419
+ CLINotFoundError, # Claude Code not installed
396
420
  CLIConnectionError, # Connection issues
397
- ProcessError, # Process failed
421
+ ProcessError, # Process failed
398
422
  CLIJSONDecodeError, # JSON parsing issues
399
- BillingError, # Insufficient credits
400
- RateLimitError, # Rate limited
401
- AuthenticationError, # Invalid API key
423
+ BillingError, # Insufficient credits
424
+ RateLimitError, # Rate limited
425
+ AuthenticationError, # Invalid API key
402
426
  )
403
427
 
404
428
  try:
@@ -412,6 +436,15 @@ except ProcessError as e:
412
436
 
413
437
  See [src/clawd_code_sdk/\_errors.py](src/clawd_code_sdk/_errors.py) for all error types.
414
438
 
439
+ ### Unknown message types
440
+
441
+ A newer Claude Code CLI can send message types (or system message subtypes) this SDK does not
442
+ model yet. `receive_messages()` / `receive_response()` skip them and log a warning once per type,
443
+ so the stream keeps going. Set `CLAWD_STRICT_MESSAGES=1` (also `true`, `yes`, `on`) to raise
444
+ `MessageParseError` instead, which ends the stream. Recommended in development and CI, so a CLI
445
+ update that adds message types is noticed; this repo's test suite sets it in `tests/conftest.py`.
446
+ `parse_message()` itself always raises, and malformed messages of known types always raise.
447
+
415
448
  ## Available Tools
416
449
 
417
450
  See the [Claude Code documentation](https://docs.anthropic.com/en/docs/claude-code/settings#tools-available-to-claude) for a complete list of available tools.