clawd-code-sdk 1.5.3__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.3 → clawd_code_sdk-1.6.2}/PKG-INFO +68 -36
  2. {clawd_code_sdk-1.5.3 → 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.3/pyproject.toml → clawd_code_sdk-1.6.2/pyproject.toml.orig +130 -33
  5. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/__init__.py +3 -1
  6. {clawd_code_sdk-1.5.3 → 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.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/_internal/query.py +75 -26
  9. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/_internal/sdk_mcp_bridge.py +9 -11
  10. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/_internal/session_mutations.py +1 -1
  11. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/_internal/sessions.py +5 -5
  12. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/_internal/transport/subprocess_cli.py +27 -4
  13. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/_internal/transport/subprocess_utils.py +170 -55
  14. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/client.py +113 -15
  15. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/instrumentation.py +6 -8
  16. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/mcp_utils.py +25 -33
  17. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/__init__.py +8 -0
  18. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/control.py +22 -18
  19. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/hooks.py +38 -0
  20. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/messages.py +2 -2
  21. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/options.py +23 -1
  22. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/system_messages.py +1 -1
  23. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/session.py +40 -9
  24. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/storage/chain.py +1 -1
  25. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/storage/helpers.py +17 -5
  26. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/storage/models.py +10 -12
  27. clawd_code_sdk-1.5.3/.gitignore +0 -54
  28. clawd_code_sdk-1.5.3/tests/__init__.py +0 -1
  29. clawd_code_sdk-1.5.3/tests/conftest.py +0 -35
  30. clawd_code_sdk-1.5.3/tests/e2e/__init__.py +0 -1
  31. clawd_code_sdk-1.5.3/tests/e2e/test_agents_and_settings.py +0 -498
  32. clawd_code_sdk-1.5.3/tests/e2e/test_dynamic_control.py +0 -71
  33. clawd_code_sdk-1.5.3/tests/e2e/test_hook_events.py +0 -185
  34. clawd_code_sdk-1.5.3/tests/e2e/test_hooks.py +0 -158
  35. clawd_code_sdk-1.5.3/tests/e2e/test_include_partial_messages.py +0 -91
  36. clawd_code_sdk-1.5.3/tests/e2e/test_mcp_resources.py +0 -72
  37. clawd_code_sdk-1.5.3/tests/e2e/test_mcp_tools.py +0 -246
  38. clawd_code_sdk-1.5.3/tests/e2e/test_sdk_mcp_resources.py +0 -78
  39. clawd_code_sdk-1.5.3/tests/e2e/test_sdk_mcp_tools.py +0 -119
  40. clawd_code_sdk-1.5.3/tests/e2e/test_slash_commands.py +0 -24
  41. clawd_code_sdk-1.5.3/tests/e2e/test_stderr_callback.py +0 -48
  42. clawd_code_sdk-1.5.3/tests/e2e/test_storage_parsing.py +0 -26
  43. clawd_code_sdk-1.5.3/tests/e2e/test_structured_output.py +0 -175
  44. clawd_code_sdk-1.5.3/tests/e2e/test_subagent_invocation.py +0 -170
  45. clawd_code_sdk-1.5.3/tests/e2e/test_tool_permissions.py +0 -68
  46. clawd_code_sdk-1.5.3/tests/mcp_server.py +0 -58
  47. clawd_code_sdk-1.5.3/tests/mock_claude_server.py +0 -100
  48. clawd_code_sdk-1.5.3/tests/test_api_content_blocks.py +0 -197
  49. clawd_code_sdk-1.5.3/tests/test_apply_flag_settings.py +0 -28
  50. clawd_code_sdk-1.5.3/tests/test_changelog.py +0 -81
  51. clawd_code_sdk-1.5.3/tests/test_client.py +0 -530
  52. clawd_code_sdk-1.5.3/tests/test_elicitation_mcp_conversion.py +0 -41
  53. clawd_code_sdk-1.5.3/tests/test_errors.py +0 -132
  54. clawd_code_sdk-1.5.3/tests/test_get_usage.py +0 -103
  55. clawd_code_sdk-1.5.3/tests/test_image.png +0 -0
  56. clawd_code_sdk-1.5.3/tests/test_initialize_fields.py +0 -103
  57. clawd_code_sdk-1.5.3/tests/test_integration.py +0 -335
  58. clawd_code_sdk-1.5.3/tests/test_line_framing.py +0 -84
  59. clawd_code_sdk-1.5.3/tests/test_mcp_delivery.py +0 -88
  60. clawd_code_sdk-1.5.3/tests/test_message_parser.py +0 -34
  61. clawd_code_sdk-1.5.3/tests/test_permission_flags.py +0 -16
  62. clawd_code_sdk-1.5.3/tests/test_result_error.py +0 -108
  63. clawd_code_sdk-1.5.3/tests/test_sandbox_settings.py +0 -63
  64. clawd_code_sdk-1.5.3/tests/test_sdk_0_3_types.py +0 -244
  65. clawd_code_sdk-1.5.3/tests/test_sdk_mcp_integration.py +0 -375
  66. clawd_code_sdk-1.5.3/tests/test_session.py +0 -633
  67. clawd_code_sdk-1.5.3/tests/test_session_mutations.py +0 -741
  68. clawd_code_sdk-1.5.3/tests/test_session_title.py +0 -51
  69. clawd_code_sdk-1.5.3/tests/test_sessions.py +0 -2106
  70. clawd_code_sdk-1.5.3/tests/test_steer.py +0 -89
  71. clawd_code_sdk-1.5.3/tests/test_storage_chain.py +0 -205
  72. clawd_code_sdk-1.5.3/tests/test_storage_entries.py +0 -357
  73. clawd_code_sdk-1.5.3/tests/test_streaming_client.py +0 -958
  74. clawd_code_sdk-1.5.3/tests/test_subprocess_buffering.py +0 -283
  75. clawd_code_sdk-1.5.3/tests/test_tool_callbacks.py +0 -682
  76. clawd_code_sdk-1.5.3/tests/test_transport.py +0 -898
  77. clawd_code_sdk-1.5.3/tests/test_transport_close.py +0 -84
  78. clawd_code_sdk-1.5.3/tests/test_unknown_entries.py +0 -53
  79. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/LICENSE +0 -0
  80. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/_bundled/.gitignore +0 -0
  81. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/_internal/__init__.py +0 -0
  82. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/_internal/mcp_compat.py +0 -0
  83. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/_internal/transport/__init__.py +0 -0
  84. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/_version.py +0 -0
  85. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/anthropic_stream.py +0 -0
  86. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/agents.py +0 -0
  87. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/anthropic_types.py +0 -0
  88. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/base.py +0 -0
  89. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/content_blocks.py +0 -0
  90. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/context_usage.py +0 -0
  91. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/input_types.py +0 -0
  92. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/mcp.py +0 -0
  93. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/output_types.py +0 -0
  94. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/permissions.py +0 -0
  95. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/prompt_requests.py +0 -0
  96. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/prompts.py +0 -0
  97. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/server_info.py +0 -0
  98. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/session.py +0 -0
  99. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/settings.py +0 -0
  100. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/thinking.py +0 -0
  101. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/models/usage.py +0 -0
  102. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/py.typed +0 -0
  103. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/storage/ARCHITECTURE.md +0 -0
  104. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/storage/__init__.py +0 -0
  105. {clawd_code_sdk-1.5.3 → clawd_code_sdk-1.6.2}/src/clawd_code_sdk/storage/replay.py +0 -0
@@ -1,40 +1,39 @@
1
- Metadata-Version: 2.5
1
+ Metadata-Version: 2.4
2
2
  Name: clawd-code-sdk
3
- Version: 1.5.3
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
24
  Requires-Dist: logfire>=6.0
25
- Requires-Dist: mcp<3.0.0,>=1.23.0
26
- Provides-Extra: dev
27
- Requires-Dist: anyio[trio]>=4.0.0; extra == 'dev'
28
- Requires-Dist: fastmcp>=3.0.0; extra == 'dev'
29
- Requires-Dist: pytest-asyncio>=0.20.0; extra == 'dev'
30
- Requires-Dist: pytest-cov>=4.0.0; extra == 'dev'
31
- Requires-Dist: pytest-timeout>=2.4.0; extra == 'dev'
32
- Requires-Dist: pytest>=7.0.0; extra == 'dev'
33
- Requires-Dist: ruff>=0.1.0; extra == 'dev'
34
- Requires-Dist: ty; extra == 'dev'
35
- Requires-Dist: types-jsonschema>=4.20.0; extra == 'dev'
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
36
36
  Provides-Extra: otel
37
- Requires-Dist: opentelemetry-api>=1.20.0; extra == 'otel'
38
37
  Description-Content-Type: text/markdown
39
38
 
40
39
  # Claude Agent SDK for Python
@@ -58,10 +57,12 @@ uv add clawd-code-sdk
58
57
  import anyio
59
58
  from clawd_code_sdk import ClaudeSDKClient
60
59
 
60
+
61
61
  async def main():
62
62
  async for message in ClaudeSDKClient.one_shot("What is 2 + 2?"):
63
63
  print(message)
64
64
 
65
+
65
66
  anyio.run(main)
66
67
  ```
67
68
 
@@ -155,10 +156,10 @@ Key points:
155
156
 
156
157
  ```python
157
158
  options = ClaudeAgentOptions(
158
- tools=["Read", "Write", "Bash"], # tools available to the agent
159
- allowed_tools=["Read", "Write", "Bash"], # auto-approved (no permission prompt)
160
- disallowed_tools=["WebFetch"], # completely removed from context
161
- 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
162
163
  )
163
164
  ```
164
165
 
@@ -168,8 +169,8 @@ options = ClaudeAgentOptions(
168
169
  from pathlib import Path
169
170
 
170
171
  options = ClaudeAgentOptions(
171
- cwd="/path/to/project", # or Path("/path/to/project")
172
- 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
173
174
  )
174
175
  ```
175
176
 
@@ -186,6 +187,17 @@ options = ClaudeAgentOptions(
186
187
  )
187
188
  ```
188
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
+
189
201
  ### Session Management
190
202
 
191
203
  ```python
@@ -209,10 +221,12 @@ options = ClaudeAgentOptions(session=ContinueLatest())
209
221
  ```python
210
222
  from pydantic import BaseModel
211
223
 
224
+
212
225
  class Joke(BaseModel):
213
226
  setup: str
214
227
  punchline: str
215
228
 
229
+
216
230
  options = ClaudeAgentOptions(
217
231
  output_schema=Joke, # accepts Pydantic models, dataclasses, TypedDicts, or raw dicts
218
232
  )
@@ -228,10 +242,12 @@ or IPC overhead:
228
242
  ```python
229
243
  from clawd_code_sdk import tool, create_sdk_mcp_server, ClaudeAgentOptions, ClaudeSDKClient
230
244
 
245
+
231
246
  @tool("greet", "Greet a user", {"name": str})
232
247
  async def greet_user(args):
233
248
  return {"content": [{"type": "text", "text": f"Hello, {args['name']}!"}]}
234
249
 
250
+
235
251
  server = create_sdk_mcp_server(
236
252
  name="my-tools",
237
253
  version="1.0.0",
@@ -271,8 +287,8 @@ SDK and external servers can be used together:
271
287
  ```python
272
288
  options = ClaudeAgentOptions(
273
289
  mcp_servers={
274
- "internal": sdk_server, # in-process
275
- "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
276
292
  }
277
293
  )
278
294
  ```
@@ -293,6 +309,7 @@ from clawd_code_sdk import (
293
309
  HookContext,
294
310
  )
295
311
 
312
+
296
313
  async def check_bash_command(
297
314
  input_data: PreToolUseHookInput,
298
315
  tool_use_id: str | None,
@@ -310,6 +327,7 @@ async def check_bash_command(
310
327
  }
311
328
  return {}
312
329
 
330
+
313
331
  options = ClaudeAgentOptions(
314
332
  allowed_tools=["Bash"],
315
333
  hooks={
@@ -372,7 +390,12 @@ async with ClaudeSDKClient() as client:
372
390
  Define subagents with their own prompts, tools, and MCP servers:
373
391
 
374
392
  ```python
375
- from clawd_code_sdk import ClaudeAgentOptions, ClaudeSDKClient, AgentDefinition, McpStdioServerConfig
393
+ from clawd_code_sdk import (
394
+ ClaudeAgentOptions,
395
+ ClaudeSDKClient,
396
+ AgentDefinition,
397
+ McpStdioServerConfig,
398
+ )
376
399
 
377
400
  options = ClaudeAgentOptions(
378
401
  agents={
@@ -430,14 +453,14 @@ for complete type definitions.
430
453
 
431
454
  ```python
432
455
  from clawd_code_sdk import (
433
- ClaudeSDKError, # Base error
434
- CLINotFoundError, # Claude Code not installed
456
+ ClaudeSDKError, # Base error
457
+ CLINotFoundError, # Claude Code not installed
435
458
  CLIConnectionError, # Connection issues
436
- ProcessError, # Process failed
459
+ ProcessError, # Process failed
437
460
  CLIJSONDecodeError, # JSON parsing issues
438
- BillingError, # Insufficient credits
439
- RateLimitError, # Rate limited
440
- AuthenticationError, # Invalid API key
461
+ BillingError, # Insufficient credits
462
+ RateLimitError, # Rate limited
463
+ AuthenticationError, # Invalid API key
441
464
  )
442
465
 
443
466
  try:
@@ -451,6 +474,15 @@ except ProcessError as e:
451
474
 
452
475
  See [src/clawd_code_sdk/\_errors.py](src/clawd_code_sdk/_errors.py) for all error types.
453
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
+
454
486
  ## Available Tools
455
487
 
456
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.