clawd-code-sdk 1.1.4__tar.gz → 1.1.6__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 (85) hide show
  1. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/PKG-INFO +1 -1
  2. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/pyproject.toml +1 -1
  3. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/_internal/session_mutations.py +24 -64
  4. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/_internal/sessions.py +34 -157
  5. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/_internal/transport/subprocess_cli.py +2 -6
  6. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/client.py +8 -0
  7. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/models/__init__.py +10 -0
  8. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/models/control.py +19 -0
  9. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/models/hooks.py +26 -0
  10. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/models/options.py +3 -0
  11. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/models/settings.py +12 -2
  12. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/.gitignore +0 -0
  13. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/LICENSE +0 -0
  14. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/README.md +0 -0
  15. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/__init__.py +0 -0
  16. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/_bundled/.gitignore +0 -0
  17. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/_errors.py +0 -0
  18. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/_internal/__init__.py +0 -0
  19. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/_internal/query.py +0 -0
  20. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/_internal/transport/__init__.py +0 -0
  21. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/_internal/transport/subprocess_utils.py +0 -0
  22. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/_version.py +0 -0
  23. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/anthropic_stream.py +0 -0
  24. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/instrumentation.py +0 -0
  25. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/list_sessions.py +0 -0
  26. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/mcp_utils.py +0 -0
  27. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/models/agents.py +0 -0
  28. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/models/anthropic_types.py +0 -0
  29. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/models/base.py +0 -0
  30. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/models/content_blocks.py +0 -0
  31. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/models/context_usage.py +0 -0
  32. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/models/input_types.py +0 -0
  33. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/models/mcp.py +0 -0
  34. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/models/messages.py +0 -0
  35. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/models/output_types.py +0 -0
  36. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/models/permissions.py +0 -0
  37. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/models/prompt_requests.py +0 -0
  38. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/models/prompts.py +0 -0
  39. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/models/server_info.py +0 -0
  40. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/models/session.py +0 -0
  41. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/models/system_messages.py +0 -0
  42. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/models/thinking.py +0 -0
  43. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/models/usage.py +0 -0
  44. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/py.typed +0 -0
  45. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/session.py +0 -0
  46. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/storage/ARCHITECTURE.md +0 -0
  47. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/storage/__init__.py +0 -0
  48. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/storage/helpers.py +0 -0
  49. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/storage/models.py +0 -0
  50. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/storage/replay.py +0 -0
  51. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/src/clawd_code_sdk/usage.py +0 -0
  52. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/__init__.py +0 -0
  53. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/conftest.py +0 -0
  54. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/e2e/__init__.py +0 -0
  55. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/e2e/test_agents_and_settings.py +0 -0
  56. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/e2e/test_dynamic_control.py +0 -0
  57. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/e2e/test_hook_events.py +0 -0
  58. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/e2e/test_hooks.py +0 -0
  59. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/e2e/test_include_partial_messages.py +0 -0
  60. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/e2e/test_mcp_resources.py +0 -0
  61. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/e2e/test_mcp_tools.py +0 -0
  62. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/e2e/test_sdk_mcp_resources.py +0 -0
  63. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/e2e/test_sdk_mcp_tools.py +0 -0
  64. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/e2e/test_slash_commands.py +0 -0
  65. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/e2e/test_stderr_callback.py +0 -0
  66. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/e2e/test_storage_parsing.py +0 -0
  67. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/e2e/test_structured_output.py +0 -0
  68. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/e2e/test_subagent_invocation.py +0 -0
  69. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/e2e/test_tool_permissions.py +0 -0
  70. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/mcp_server.py +0 -0
  71. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/mock_claude_server.py +0 -0
  72. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/test_changelog.py +0 -0
  73. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/test_client.py +0 -0
  74. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/test_errors.py +0 -0
  75. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/test_image.png +0 -0
  76. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/test_integration.py +0 -0
  77. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/test_message_parser.py +0 -0
  78. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/test_sdk_mcp_integration.py +0 -0
  79. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/test_session.py +0 -0
  80. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/test_session_mutations.py +0 -0
  81. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/test_sessions.py +0 -0
  82. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/test_streaming_client.py +0 -0
  83. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/test_subprocess_buffering.py +0 -0
  84. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/test_tool_callbacks.py +0 -0
  85. {clawd_code_sdk-1.1.4 → clawd_code_sdk-1.1.6}/tests/test_transport.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: clawd-code-sdk
3
- Version: 1.1.4
3
+ Version: 1.1.6
4
4
  Summary: Python SDK for Claude Code
5
5
  Project-URL: Documentation, https://github.com/phil65/claude-agent-sdk-python
6
6
  Project-URL: Homepage, https://github.com/phil65/claude-agent-sdk-python
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "clawd-code-sdk"
3
- version = "1.1.4"
3
+ version = "1.1.6"
4
4
  description = "Python SDK for Claude Code"
5
5
  readme = "README.md"
6
6
  requires-python = ">=3.13"
@@ -52,11 +52,7 @@ if TYPE_CHECKING:
52
52
  # ---------------------------------------------------------------------------
53
53
 
54
54
 
55
- def rename_session(
56
- session_id: str,
57
- title: str,
58
- directory: str | None = None,
59
- ) -> None:
55
+ def rename_session(session_id: str, title: str, directory: str | None = None) -> None:
60
56
  """Rename a session by appending a custom-title entry.
61
57
 
62
58
  ``list_sessions`` reads the LAST custom-title from the file tail, so
@@ -429,10 +425,7 @@ def fork_session(
429
425
  # ---------------------------------------------------------------------------
430
426
 
431
427
 
432
- def _find_session_file(
433
- session_id: str,
434
- directory: str | None,
435
- ) -> Path | None:
428
+ def _find_session_file(session_id: str, directory: str | None) -> Path | None:
436
429
  """Find the path to a session's JSONL file.
437
430
 
438
431
  Returns the path if found, None otherwise.
@@ -441,10 +434,7 @@ def _find_session_file(
441
434
  return result[0] if result else None
442
435
 
443
436
 
444
- def _find_session_file_with_dir(
445
- session_id: str,
446
- directory: str | None,
447
- ) -> tuple[Path, Path] | None:
437
+ def _find_session_file_with_dir(session_id: str, directory: str | None) -> tuple[Path, Path] | None:
448
438
  """Find a session file and its containing project directory.
449
439
 
450
440
  Returns ``(file_path, project_dir)`` or None. The fork operation
@@ -455,8 +445,7 @@ def _find_session_file_with_dir(
455
445
  def _try_dir(project_dir: Path) -> tuple[Path, Path] | None:
456
446
  path = project_dir / file_name
457
447
  try:
458
- st = path.stat()
459
- if st.st_size > 0:
448
+ if path.stat().st_size > 0:
460
449
  return (path, project_dir)
461
450
  except OSError:
462
451
  pass
@@ -464,24 +453,13 @@ def _find_session_file_with_dir(
464
453
 
465
454
  if directory:
466
455
  canonical = _canonicalize_path(directory)
467
- project_dir = _find_project_dir(canonical)
468
- if project_dir is not None:
469
- result = _try_dir(project_dir)
470
- if result:
471
- return result
472
-
473
- try:
474
- worktree_paths = _get_worktree_paths(canonical)
475
- except Exception:
476
- worktree_paths = []
477
- for wt in worktree_paths:
456
+ if (project_dir := _find_project_dir(canonical)) and (result := _try_dir(project_dir)):
457
+ return result
458
+ for wt in _get_worktree_paths(canonical):
478
459
  if wt == canonical:
479
460
  continue
480
- wt_project_dir = _find_project_dir(wt)
481
- if wt_project_dir is not None:
482
- result = _try_dir(wt_project_dir)
483
- if result:
484
- return result
461
+ if (wt_project_dir := _find_project_dir(wt)) and (result := _try_dir(wt_project_dir)):
462
+ return result
485
463
  return None
486
464
 
487
465
  projects_dir = _get_projects_dir()
@@ -490,8 +468,7 @@ def _find_session_file_with_dir(
490
468
  except OSError:
491
469
  return None
492
470
  for entry in dirents:
493
- result = _try_dir(entry)
494
- if result:
471
+ if result := _try_dir(entry):
495
472
  return result
496
473
  return None
497
474
 
@@ -518,22 +495,16 @@ def _parse_fork_transcript(
518
495
  entry = anyenv.load_json(stripped, return_type=dict)
519
496
  except (anyenv.JsonLoadError, ValueError):
520
497
  continue
521
- # match entry:
522
- # case {
523
- # "type": "user" | "assistant" | "attachment" | "system" | "progress" as typ,
524
- # "uuid": str(id_),
525
- # }:
526
- # pass
527
- entry_type = entry.get("type")
528
- if entry_type in _TRANSCRIPT_TYPES and isinstance(entry.get("uuid"), str):
529
- transcript.append(entry)
530
- elif (
531
- entry_type == "content-replacement"
532
- and entry.get("sessionId") == session_id
533
- and isinstance(entry.get("replacements"), list)
534
- ):
535
- content_replacements.extend(entry["replacements"])
536
-
498
+ match entry:
499
+ case {
500
+ "type": "user" | "assistant" | "attachment" | "system" | "progress",
501
+ "uuid": str(),
502
+ }:
503
+ transcript.append(entry)
504
+ case {"type": "content-replacement", "sessionId": str(sid), "replacements": list()} if (
505
+ sid == session_id
506
+ ):
507
+ content_replacements.extend(entry["replacements"])
537
508
  return transcript, content_replacements
538
509
 
539
510
 
@@ -548,29 +519,18 @@ def _append_to_session(session_id: str, data: str, directory: str | None) -> Non
548
519
 
549
520
  if directory:
550
521
  canonical = _canonicalize_path(directory)
551
-
552
522
  # Try the exact/prefix-matched project directory first.
553
- project_dir = _find_project_dir(canonical)
554
- if project_dir is not None and _try_append(project_dir / file_name, data):
523
+ if (proj_dir := _find_project_dir(canonical)) and _try_append(proj_dir / file_name, data):
555
524
  return
556
-
557
525
  # Worktree fallback — matches list_sessions/get_session_messages.
558
526
  # Sessions may live under a different worktree root.
559
- try:
560
- worktree_paths = _get_worktree_paths(canonical)
561
- except Exception:
562
- worktree_paths = []
563
- for wt in worktree_paths:
527
+ for wt in _get_worktree_paths(canonical):
564
528
  if wt == canonical:
565
529
  continue # already tried above
566
- wt_project_dir = _find_project_dir(wt)
567
- if wt_project_dir is not None and _try_append(wt_project_dir / file_name, data):
530
+ if (proj_dir := _find_project_dir(wt)) and _try_append(proj_dir / file_name, data):
568
531
  return
569
532
 
570
- raise FileNotFoundError(
571
- f"Session {session_id} not found in project directory for {directory}"
572
- )
573
-
533
+ raise FileNotFoundError(f"{session_id=} not found in project {directory=}")
574
534
  # No directory — search all project directories by trying each directly.
575
535
  projects_dir = _get_projects_dir()
576
536
  try:
@@ -6,13 +6,14 @@ extracts metadata from stat + head/tail reads without full JSONL parsing.
6
6
 
7
7
  from __future__ import annotations
8
8
 
9
+ from dataclasses import dataclass
9
10
  from datetime import datetime
10
11
  import os
11
12
  from pathlib import Path
12
13
  import re
13
14
  import subprocess
14
15
  import sys
15
- from typing import Any, Literal
16
+ from typing import Any
16
17
  import unicodedata
17
18
 
18
19
  import anyenv
@@ -26,7 +27,6 @@ from clawd_code_sdk.models.session import SDKSessionInfo, SessionMessage
26
27
 
27
28
  # Size of the head/tail buffer for lite metadata reads.
28
29
  LITE_READ_BUF_SIZE = 65536
29
-
30
30
  # Maximum length for a single filesystem path component. Most filesystems
31
31
  # limit individual components to 255 bytes. We use 200 to leave room for
32
32
  # the hash suffix and separator.
@@ -50,6 +50,7 @@ _COMMAND_NAME_RE = re.compile(r"<command-name>(.*?)</command-name>")
50
50
 
51
51
  _SANITIZE_RE = re.compile(r"[^a-zA-Z0-9]")
52
52
 
53
+ case_insensitive = sys.platform == "win32"
53
54
 
54
55
  # ---------------------------------------------------------------------------
55
56
  # UUID validation
@@ -314,16 +315,14 @@ def _extract_first_prompt_from_head(head: str) -> str:
314
315
  # ---------------------------------------------------------------------------
315
316
 
316
317
 
318
+ @dataclass(kw_only=True, slots=True)
317
319
  class _LiteSessionFile:
318
320
  """Result of reading a session file's head, tail, mtime and size."""
319
321
 
320
- __slots__ = ("head", "mtime", "size", "tail")
321
-
322
- def __init__(self, mtime: int, size: int, head: str, tail: str) -> None:
323
- self.mtime = mtime
324
- self.size = size
325
- self.head = head
326
- self.tail = tail
322
+ mtime: int
323
+ size: int
324
+ head: str
325
+ tail: str
327
326
 
328
327
 
329
328
  def _read_session_lite(file_path: Path) -> _LiteSessionFile | None:
@@ -381,12 +380,11 @@ def _get_worktree_paths(cwd: str) -> list[str]:
381
380
  if result.returncode != 0 or not result.stdout:
382
381
  return []
383
382
 
384
- paths = []
385
- for line in result.stdout.split("\n"):
386
- if line.startswith("worktree "):
387
- path = unicodedata.normalize("NFC", line[len("worktree ") :])
388
- paths.append(path)
389
- return paths
383
+ return [
384
+ unicodedata.normalize("NFC", i[len("worktree ") :])
385
+ for i in result.stdout.split("\n")
386
+ if i.startswith("worktree ")
387
+ ]
390
388
 
391
389
 
392
390
  # ---------------------------------------------------------------------------
@@ -554,15 +552,7 @@ def _list_sessions_for_project(
554
552
  ) -> list[SDKSessionInfo]:
555
553
  """Lists sessions for a specific project directory (and its worktrees)."""
556
554
  canonical_dir = _canonicalize_path(directory)
557
-
558
- if include_worktrees:
559
- try:
560
- worktree_paths = _get_worktree_paths(canonical_dir)
561
- except Exception:
562
- worktree_paths = []
563
- else:
564
- worktree_paths = []
565
-
555
+ worktree_paths = _get_worktree_paths(canonical_dir) if include_worktrees else []
566
556
  # No worktrees (or git not available / scanning disabled) —
567
557
  # just scan the single project dir
568
558
  if len(worktree_paths) <= 1:
@@ -574,8 +564,6 @@ def _list_sessions_for_project(
574
564
 
575
565
  # Worktree-aware scanning: find all project dirs matching any worktree
576
566
  projects_dir = _get_projects_dir()
577
- case_insensitive = sys.platform == "win32"
578
-
579
567
  # Sort worktree paths by sanitized prefix length (longest first) so
580
568
  # more specific matches take priority over shorter ones
581
569
  indexed = []
@@ -673,23 +661,6 @@ def list_sessions(
673
661
 
674
662
  Returns:
675
663
  List of ``SDKSessionInfo`` sorted by ``last_modified`` descending.
676
-
677
- Example:
678
- List sessions for a specific project::
679
-
680
- sessions = list_sessions(directory="/path/to/project")
681
-
682
- Paginate::
683
-
684
- page1 = list_sessions(limit=50)
685
- page2 = list_sessions(limit=50, offset=50)
686
-
687
- List sessions without scanning git worktrees::
688
-
689
- sessions = list_sessions(
690
- directory="/path/to/project",
691
- include_worktrees=False,
692
- )
693
664
  """
694
665
  if directory:
695
666
  return _list_sessions_for_project(directory, limit, offset, include_worktrees)
@@ -701,10 +672,7 @@ def list_sessions(
701
672
  # ---------------------------------------------------------------------------
702
673
 
703
674
 
704
- def get_session_info(
705
- session_id: str,
706
- directory: str | None = None,
707
- ) -> SDKSessionInfo | None:
675
+ def get_session_info(session_id: str, directory: str | None = None) -> SDKSessionInfo | None:
708
676
  """Reads metadata for a single session by ID.
709
677
 
710
678
  Wraps ``_read_session_lite`` for one file — no O(n) directory scan.
@@ -721,20 +689,6 @@ def get_session_info(
721
689
  Returns:
722
690
  ``SDKSessionInfo`` for the session, or ``None`` if the session file
723
691
  is not found, is a sidechain session, or has no extractable summary.
724
-
725
- Example:
726
- Look up a session in a specific project::
727
-
728
- info = get_session_info(
729
- "550e8400-e29b-41d4-a716-446655440000",
730
- directory="/path/to/project",
731
- )
732
- if info:
733
- print(info.summary)
734
-
735
- Search all projects for a session::
736
-
737
- info = get_session_info("550e8400-e29b-41d4-a716-446655440000")
738
692
  """
739
693
  uuid = _validate_uuid(session_id)
740
694
  if not uuid:
@@ -744,25 +698,16 @@ def get_session_info(
744
698
  if directory:
745
699
  canonical = _canonicalize_path(directory)
746
700
  project_dir = _find_project_dir(canonical)
747
- if project_dir is not None:
748
- lite = _read_session_lite(project_dir / file_name)
749
- if lite is not None:
750
- return _parse_session_info_from_lite(uuid, lite, canonical)
751
-
701
+ if project_dir and (lite := _read_session_lite(project_dir / file_name)):
702
+ return _parse_session_info_from_lite(uuid, lite, canonical)
752
703
  # Worktree fallback — matches get_session_messages semantics.
753
704
  # Sessions may live under a different worktree root.
754
- try:
755
- worktree_paths = _get_worktree_paths(canonical)
756
- except Exception:
757
- worktree_paths = []
758
- for wt in worktree_paths:
705
+ for wt in _get_worktree_paths(canonical):
759
706
  if wt == canonical:
760
707
  continue
761
708
  wt_project_dir = _find_project_dir(wt)
762
- if wt_project_dir is not None:
763
- lite = _read_session_lite(wt_project_dir / file_name)
764
- if lite is not None:
765
- return _parse_session_info_from_lite(uuid, lite, wt)
709
+ if wt_project_dir and (lite := _read_session_lite(wt_project_dir / file_name)):
710
+ return _parse_session_info_from_lite(uuid, lite, wt)
766
711
 
767
712
  return None
768
713
 
@@ -813,31 +758,19 @@ def _read_session_file(session_id: str, directory: str | None) -> str | None:
813
758
 
814
759
  if directory:
815
760
  canonical_dir = _canonicalize_path(directory)
816
-
817
761
  # Try the exact/prefix-matched project directory first
818
762
  project_dir = _find_project_dir(canonical_dir)
819
- if project_dir is not None:
820
- content = _try_read_session_file(project_dir, file_name)
821
- if content:
822
- return content
823
-
763
+ if project_dir and (content := _try_read_session_file(project_dir, file_name)):
764
+ return content
824
765
  # Try worktree paths — sessions may live under a different worktree root
825
- try:
826
- worktree_paths = _get_worktree_paths(canonical_dir)
827
- except Exception:
828
- worktree_paths = []
829
-
830
- for wt in worktree_paths:
766
+ for wt in _get_worktree_paths(canonical_dir):
831
767
  if wt == canonical_dir:
832
768
  continue # already tried above
833
769
  wt_project_dir = _find_project_dir(wt)
834
- if wt_project_dir is not None:
835
- content = _try_read_session_file(wt_project_dir, file_name)
836
- if content:
837
- return content
770
+ if wt_project_dir and (content := _try_read_session_file(wt_project_dir, file_name)):
771
+ return content
838
772
 
839
773
  return None
840
-
841
774
  # No directory provided — search all project directories
842
775
  projects_dir = _get_projects_dir()
843
776
  try:
@@ -846,8 +779,7 @@ def _read_session_file(session_id: str, directory: str | None) -> str | None:
846
779
  return None
847
780
 
848
781
  for entry in dirents:
849
- content = _try_read_session_file(entry, file_name)
850
- if content:
782
+ if content := (_try_read_session_file(entry, file_name)):
851
783
  return content
852
784
 
853
785
  return None
@@ -874,12 +806,9 @@ def _parse_transcript_entries(content: str) -> list[_TranscriptEntry]:
874
806
  continue
875
807
 
876
808
  try:
877
- entry = anyenv.load_json(line)
809
+ entry = anyenv.load_json(line, return_type=dict)
878
810
  except (anyenv.JsonLoadError, ValueError):
879
811
  continue
880
-
881
- if not isinstance(entry, dict):
882
- continue
883
812
  entry_type = entry.get("type")
884
813
  if entry_type in _TRANSCRIPT_ENTRY_TYPES and isinstance(entry.get("uuid"), str):
885
814
  entries.append(entry)
@@ -901,26 +830,12 @@ def _build_conversation_chain(
901
830
  """
902
831
  if not entries:
903
832
  return []
904
-
905
- # Index by uuid for O(1) parent lookup
906
- by_uuid: dict[str, _TranscriptEntry] = {}
907
- for entry in entries:
908
- by_uuid[entry["uuid"]] = entry
909
-
833
+ by_uuid = {e["uuid"]: e for e in entries}
910
834
  # Build index of entry positions (file order) for tie-breaking
911
- entry_index: dict[str, int] = {}
912
- for i, entry in enumerate(entries):
913
- entry_index[entry["uuid"]] = i
914
-
835
+ entry_index = {e["uuid"]: i for i, e in enumerate(entries)}
915
836
  # Find terminal messages (no children point to them via parentUuid)
916
- parent_uuids: set[str] = set()
917
- for entry in entries:
918
- parent = entry.get("parentUuid")
919
- if parent:
920
- parent_uuids.add(parent)
921
-
837
+ parent_uuids = {parent for e in entries if (parent := e.get("parentUuid"))}
922
838
  terminals = [e for e in entries if e["uuid"] not in parent_uuids]
923
-
924
839
  # From each terminal, walk back to find the nearest user/assistant leaf
925
840
  leaves: list[_TranscriptEntry] = []
926
841
  for terminal in terminals:
@@ -995,12 +910,10 @@ def _is_visible_message(entry: _TranscriptEntry) -> bool:
995
910
 
996
911
  def _to_session_message(entry: _TranscriptEntry) -> SessionMessage:
997
912
  """Converts a transcript entry dict into a SessionMessage."""
998
- entry_type = entry.get("type")
999
913
  # Narrow to the Literal type — _is_visible_message already guarantees
1000
914
  # this is "user" or "assistant".
1001
- msg_type: Literal["user", "assistant"] = "user" if entry_type == "user" else "assistant"
1002
- return SessionMessage( # pyright: ignore[reportCallIssue]
1003
- type=msg_type,
915
+ return SessionMessage(
916
+ type="user" if entry.get("type") == "user" else "assistant",
1004
917
  uuid=entry.get("uuid", ""),
1005
918
  session_id=entry.get("sessionId", ""),
1006
919
  message=entry.get("message"),
@@ -1030,22 +943,6 @@ def get_session_messages(
1030
943
  List of ``SessionMessage`` objects in chronological order. Returns
1031
944
  an empty list if the session is not found, the session_id is not a
1032
945
  valid UUID, or the transcript contains no visible messages.
1033
-
1034
- Example:
1035
- Read all messages from a session::
1036
-
1037
- messages = get_session_messages(
1038
- "550e8400-e29b-41d4-a716-446655440000",
1039
- directory="/path/to/project",
1040
- )
1041
- for msg in messages:
1042
- print(msg.type, msg.message)
1043
-
1044
- Read with pagination::
1045
-
1046
- page = get_session_messages(
1047
- session_id, limit=10, offset=20
1048
- )
1049
946
  """
1050
947
  if not _validate_uuid(session_id):
1051
948
  return []
@@ -1100,11 +997,7 @@ def _resolve_session_file_path(session_id: str, directory: str | None) -> Path |
1100
997
  if found is not None:
1101
998
  return found
1102
999
 
1103
- try:
1104
- worktree_paths = _get_worktree_paths(canonical_dir)
1105
- except Exception:
1106
- worktree_paths = []
1107
-
1000
+ worktree_paths = _get_worktree_paths(canonical_dir)
1108
1001
  for wt in worktree_paths:
1109
1002
  if wt == canonical_dir:
1110
1003
  continue
@@ -1265,35 +1158,19 @@ def get_subagent_messages(
1265
1158
  an empty list if the session or subagent is not found, the
1266
1159
  session_id is not a valid UUID, or the transcript contains no
1267
1160
  user/assistant messages.
1268
-
1269
- Example:
1270
- Read all messages from a subagent::
1271
-
1272
- messages = get_subagent_messages(
1273
- "550e8400-e29b-41d4-a716-446655440000",
1274
- "abc123",
1275
- directory="/path/to/project",
1276
- )
1277
1161
  """
1278
1162
  if not _validate_uuid(session_id):
1279
1163
  return []
1280
1164
  if not agent_id:
1281
1165
  return []
1282
-
1283
1166
  subagents_dir = _resolve_subagents_dir(session_id, directory)
1284
1167
  if subagents_dir is None:
1285
1168
  return []
1286
-
1287
1169
  # The agent file may be directly in subagents/ or in a nested
1288
1170
  # subdirectory — scan to find it.
1289
- match: Path | None = None
1290
- for found_id, file_path in _collect_agent_files(subagents_dir):
1291
- if found_id == agent_id:
1292
- match = file_path
1293
- break
1171
+ match = next((p for id_, p in _collect_agent_files(subagents_dir) if id_ == agent_id), None)
1294
1172
  if match is None:
1295
1173
  return []
1296
-
1297
1174
  try:
1298
1175
  content = match.read_text(encoding="utf-8")
1299
1176
  except OSError:
@@ -12,6 +12,7 @@ from typing import TYPE_CHECKING, Any
12
12
  import anyio
13
13
  import anyio.abc
14
14
  from anyio.streams.text import TextReceiveStream, TextSendStream
15
+ from anyio.to_thread import run_sync
15
16
 
16
17
  from clawd_code_sdk._errors import CLIConnectionError, CLINotFoundError, ProcessError
17
18
  from clawd_code_sdk._internal.transport import Transport
@@ -40,10 +41,7 @@ _DEFAULT_MAX_BUFFER_SIZE = 10 * 1024 * 1024 # 1MB buffer limit
40
41
  class SubprocessCLITransport(Transport):
41
42
  """Subprocess transport using Claude Code CLI."""
42
43
 
43
- def __init__(
44
- self,
45
- options: ClaudeAgentOptions | None = None,
46
- ):
44
+ def __init__(self, options: ClaudeAgentOptions | None = None):
47
45
  self._options = options or ClaudeAgentOptions()
48
46
  self._cli_path = str(opts) if (opts := self._options.cli_path) is not None else None
49
47
  self._process: Process | None = None
@@ -76,8 +74,6 @@ class SubprocessCLITransport(Transport):
76
74
 
77
75
  async def connect(self) -> None:
78
76
  """Start subprocess."""
79
- from anyio.to_thread import run_sync
80
-
81
77
  if self._process:
82
78
  return
83
79
  if self._cli_path is None:
@@ -208,6 +208,7 @@ class ClaudeSDKClient:
208
208
  agent_progress_summaries=options.agent_progress_summaries,
209
209
  title=title,
210
210
  skills=options.skills,
211
+ plan_mode_instructions=options.plan_mode_instructions,
211
212
  )
212
213
  response = await query._send_control_request(request, timeout=initialize_timeout)
213
214
  self._initialization_result = ClaudeCodeServerInfo.model_validate(response)
@@ -475,6 +476,13 @@ class ClaudeSDKClient:
475
476
  result = await query._send_control_request(request)
476
477
  return SDKControlGetContextUsageResponse.model_validate(result)
477
478
 
479
+ # async def get_session_cost(self) -> SDKControlGetSessionCostResponse:
480
+ # """Get the formatted session cost summary (the same text as /usage)."""
481
+ # query = self._ensure_connected()
482
+ # request = SDKControlGetSessionCostRequest()
483
+ # result = await query._send_control_request(request)
484
+ # return SDKControlGetSessionCostResponse.model_validate(result)
485
+
478
486
  async def mcp_authenticate(self, server_name: str) -> McpAuthenticateResponse:
479
487
  """Trigger OAuth authentication for an MCP server.
480
488
 
@@ -369,6 +369,11 @@ from .system_messages import (
369
369
  SystemMessageUnion,
370
370
  LocalCommandOutputMessage,
371
371
  ElicitationCompleteMessage,
372
+ MemoryRecallSystemMessage,
373
+ MirrorErrorSystemMessage,
374
+ NotificationSystemMessage,
375
+ PluginInstallSystemMessage,
376
+ TaskUpdatedSystemMessage,
372
377
  )
373
378
 
374
379
  from typing import Annotated, Any
@@ -577,8 +582,10 @@ __all__ = [
577
582
  "McpStatusResponse",
578
583
  "McpStdioServerConfig",
579
584
  "McpToolStatus",
585
+ "MemoryRecallSystemMessage",
580
586
  "Message",
581
587
  "MessageParam",
588
+ "MirrorErrorSystemMessage",
582
589
  "MiscMessages",
583
590
  "ModelUsage",
584
591
  "Network",
@@ -587,6 +594,7 @@ __all__ = [
587
594
  "NotebookEditOutput",
588
595
  "NotificationHookInput",
589
596
  "NotificationHookSpecificOutput",
597
+ "NotificationSystemMessage",
590
598
  "OnElicitation",
591
599
  "OnUserQuestion",
592
600
  "OutgoingControlRequest",
@@ -605,6 +613,7 @@ __all__ = [
605
613
  "PermissionUpdateDestination",
606
614
  "Permissions",
607
615
  "PlainTextMediaType",
616
+ "PluginInstallSystemMessage",
608
617
  "PostCompactHookInput",
609
618
  "PostToolUseFailureHookInput",
610
619
  "PostToolUseFailureHookSpecificOutput",
@@ -717,6 +726,7 @@ __all__ = [
717
726
  "TaskProgressUsage",
718
727
  "TaskStartedSystemMessage",
719
728
  "TaskStopOutput",
729
+ "TaskUpdatedSystemMessage",
720
730
  "TeammateIdleHookInput",
721
731
  "TextBlock",
722
732
  "ThinkingBlock",
@@ -123,6 +123,11 @@ class SDKControlInitializeRequest(_ControlBase):
123
123
  exact name, plugin-qualified name, or ":name" suffix.
124
124
  Omit to load every discovered skill.
125
125
  Applies to the main session only; subagents use AgentDefinition.skills."""
126
+ plan_mode_instructions: str | None = Field(
127
+ default=None,
128
+ serialization_alias="planModeInstructions",
129
+ )
130
+ """Custom workflow body for the plan-mode system reminder."""
126
131
 
127
132
 
128
133
  class SDKControlSetPermissionModeRequest(_ControlBase):
@@ -496,6 +501,12 @@ class SDKControlGetContextUsageRequest(_ControlBase):
496
501
  subtype: Literal["get_context_usage"] = "get_context_usage"
497
502
 
498
503
 
504
+ class SDKControlGetSessionCostRequest(_ControlBase):
505
+ """Requests the formatted session cost summary (the same text as /usage)."""
506
+
507
+ subtype: Literal["get_session_cost"] = "get_session_cost"
508
+
509
+
499
510
  class SDKControlGetSettingsRequest(_ControlBase):
500
511
  """Returns the effective merged settings and the raw per-source settings."""
501
512
 
@@ -508,6 +519,13 @@ class SDKControlSetProactiveRequest(_ControlBase):
508
519
  subtype: Literal["set_proactive"] = "set_proactive"
509
520
 
510
521
 
522
+ class SDKControlSetColorRequest(_ControlBase):
523
+ """Sets the session accent color. Accepts an agent color name or "default" to reset."""
524
+
525
+ subtype: Literal["set_color"] = "set_color"
526
+ color: str
527
+
528
+
511
529
  class SDKControlClaudeOAuthWaitForCompletionRequest(_ControlBase):
512
530
  """Waits for an in-progress Claude OAuth flow to complete.
513
531
 
@@ -622,6 +640,7 @@ OutgoingControlRequest = Annotated[
622
640
  | SDKControlStopTaskRequest
623
641
  | SDKControlApplyFlagSettingsRequest
624
642
  | SDKControlGetContextUsageRequest
643
+ | SDKControlGetSessionCostRequest
625
644
  | SDKControlGetSettingsRequest
626
645
  | SDKControlRewindFilesRequest
627
646
  | SDKControlCancelAsyncMessageRequest
@@ -22,6 +22,7 @@ HookEvent = Literal[
22
22
  "PreToolUse",
23
23
  "PostToolUse",
24
24
  "PostToolUseFailure",
25
+ "PostToolBatch",
25
26
  "UserPromptSubmit",
26
27
  "Stop",
27
28
  "StopFailure",
@@ -188,6 +189,22 @@ class PostToolUseFailureHookInput(BaseHookInput):
188
189
  agent_type: NotRequired[str]
189
190
 
190
191
 
192
+ class PostToolBatchToolCall(BaseModel):
193
+ """Represents a tool call in a PostToolBatch hook event."""
194
+
195
+ tool_name: str
196
+ tool_input: dict[str, Any]
197
+ tool_use_id: str
198
+ tool_response: Any = None
199
+
200
+
201
+ class PostToolBatchHookInput(BaseHookInput):
202
+ """Input data for PostToolBatch hook events."""
203
+
204
+ hook_event_name: Literal["PostToolBatch"]
205
+ tool_calls: list[PostToolBatchToolCall]
206
+
207
+
191
208
  class UserPromptSubmitHookInput(BaseHookInput):
192
209
  """Input data for UserPromptSubmit hook events."""
193
210
 
@@ -420,6 +437,7 @@ HookInput = (
420
437
  PreToolUseHookInput
421
438
  | PostToolUseHookInput
422
439
  | PostToolUseFailureHookInput
440
+ | PostToolBatchHookInput
423
441
  | UserPromptSubmitHookInput
424
442
  | StopHookInput
425
443
  | StopFailureHookInput
@@ -474,6 +492,13 @@ class PostToolUseFailureHookSpecificOutput(TypedDict):
474
492
  additionalContext: NotRequired[str]
475
493
 
476
494
 
495
+ class PostToolBatchHookSpecificOutput(TypedDict):
496
+ """Hook-specific output for PostToolBatch events."""
497
+
498
+ hookEventName: Literal["PostToolBatch"]
499
+ additionalContext: NotRequired[str]
500
+
501
+
477
502
  class UserPromptSubmitHookSpecificOutput(TypedDict):
478
503
  """Hook-specific output for UserPromptSubmit events."""
479
504
 
@@ -567,6 +592,7 @@ HookSpecificOutput = (
567
592
  PreToolUseHookSpecificOutput
568
593
  | PostToolUseHookSpecificOutput
569
594
  | PostToolUseFailureHookSpecificOutput
595
+ | PostToolBatchHookSpecificOutput
570
596
  | PermissionDeniedHookSpecificOutput
571
597
  | UserPromptSubmitHookSpecificOutput
572
598
  | SessionStartHookSpecificOutput
@@ -271,11 +271,14 @@ class ClaudeAgentOptions:
271
271
  include_builtin_system_prompt: bool = True
272
272
  """Whether to include Claude Code's builtin system prompt.
273
273
 
274
+
274
275
  When True (default) and system_prompt is set, it is appended to the
275
276
  builtin system prompt. When False, the system_prompt replaces it entirely.
276
277
  """
277
278
  exclude_dynamic_sections: bool | None = None
278
279
  """Whether to exclude dynamic sections from the system prompt."""
280
+ plan_mode_instructions: str | None = None
281
+ """Custom workflow body for the plan-mode system reminder."""
279
282
 
280
283
  hooks: dict[HookEvent, list[HookMatcher]] | None = None
281
284
  """Hook configurations."""
@@ -1,6 +1,6 @@
1
1
  # generated by datamodel-codegen:
2
2
  # filename: claude-code-settings-titled.json
3
- # timestamp: 2026-04-20T23:23:14+00:00
3
+ # timestamp: 2026-04-23T20:01:58+00:00
4
4
 
5
5
  from __future__ import annotations
6
6
 
@@ -283,6 +283,14 @@ class ExtraKnownMarketplaces(ClaudeCodeBaseModel):
283
283
  """
284
284
  Local cache path where marketplace manifest is stored (auto-generated if not provided)
285
285
  """
286
+ auto_update: bool | None = Field(None, alias="autoUpdate")
287
+ """
288
+ Whether to automatically update this marketplace on Claude Code startup. Written automatically by Claude Code when you toggle auto-update for a marketplace
289
+ """
290
+ last_updated: str | None = Field(None, alias="lastUpdated")
291
+ """
292
+ ISO 8601 timestamp of the last marketplace refresh. Written automatically by Claude Code
293
+ """
286
294
 
287
295
 
288
296
  class StrictMarketplaceHostPattern(ClaudeCodeBaseModel):
@@ -1217,7 +1225,9 @@ class ClaudeCodeSettings(ClaudeCodeBaseModel):
1217
1225
  """
1218
1226
  Map Anthropic model IDs to provider-specific model IDs such as Bedrock inference profile ARNs, Vertex AI version names, or Foundry deployment names. Each model picker entry uses its mapped value when calling the provider API. Unknown keys are ignored. See https://code.claude.com/docs/en/model-config#override-model-ids-per-version
1219
1227
  """
1220
- effort_level: Literal["low", "medium", "high"] | None = Field(None, alias="effortLevel")
1228
+ effort_level: Literal["low", "medium", "high", "xhigh"] | None = Field(
1229
+ None, alias="effortLevel"
1230
+ )
1221
1231
  """
1222
1232
  Control Opus 4.6 adaptive reasoning effort. Lower effort is faster and cheaper for straightforward tasks, higher effort provides deeper reasoning. Defaults vary by model and plan (Opus 4.6 defaults to medium for Max and Team subscribers). Use /effort auto to reset to model default. Also configurable via CLAUDE_CODE_EFFORT_LEVEL environment variable. See https://code.claude.com/docs/en/model-config#adjust-effort-level
1223
1233
  """
File without changes
File without changes