clawd-code-sdk 1.2.3__tar.gz → 1.2.5__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.
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/PKG-INFO +1 -1
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/pyproject.toml +1 -1
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/client.py +10 -3
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/models/__init__.py +12 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/models/context_usage.py +77 -2
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/models/control.py +15 -0
- clawd_code_sdk-1.2.5/tests/test_get_usage.py +103 -0
- clawd_code_sdk-1.2.3/src/clawd_code_sdk/usage.py +0 -199
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/.gitignore +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/LICENSE +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/README.md +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/__init__.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/_bundled/.gitignore +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/_errors.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/_internal/__init__.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/_internal/mcp_compat.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/_internal/query.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/_internal/sdk_mcp_bridge.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/_internal/session_mutations.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/_internal/sessions.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/_internal/transport/__init__.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/_internal/transport/subprocess_cli.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/_internal/transport/subprocess_utils.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/_version.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/anthropic_stream.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/instrumentation.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/list_sessions.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/mcp_utils.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/models/agents.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/models/anthropic_types.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/models/base.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/models/content_blocks.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/models/hooks.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/models/input_types.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/models/mcp.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/models/messages.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/models/options.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/models/output_types.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/models/permissions.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/models/prompt_requests.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/models/prompts.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/models/server_info.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/models/session.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/models/settings.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/models/system_messages.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/models/thinking.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/models/usage.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/py.typed +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/session.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/storage/ARCHITECTURE.md +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/storage/__init__.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/storage/helpers.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/storage/models.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/storage/replay.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/__init__.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/conftest.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/e2e/__init__.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/e2e/test_agents_and_settings.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/e2e/test_dynamic_control.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/e2e/test_hook_events.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/e2e/test_hooks.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/e2e/test_include_partial_messages.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/e2e/test_mcp_resources.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/e2e/test_mcp_tools.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/e2e/test_sdk_mcp_resources.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/e2e/test_sdk_mcp_tools.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/e2e/test_slash_commands.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/e2e/test_stderr_callback.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/e2e/test_storage_parsing.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/e2e/test_structured_output.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/e2e/test_subagent_invocation.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/e2e/test_tool_permissions.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/mcp_server.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/mock_claude_server.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/test_api_content_blocks.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/test_changelog.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/test_client.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/test_elicitation_mcp_conversion.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/test_errors.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/test_image.png +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/test_integration.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/test_line_framing.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/test_message_parser.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/test_result_error.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/test_sandbox_settings.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/test_sdk_0_3_types.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/test_sdk_mcp_integration.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/test_session.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/test_session_mutations.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/test_sessions.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/test_streaming_client.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/test_subprocess_buffering.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/test_tool_callbacks.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/test_transport.py +0 -0
- {clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/tests/test_transport_close.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: clawd-code-sdk
|
|
3
|
-
Version: 1.2.
|
|
3
|
+
Version: 1.2.5
|
|
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
|
|
@@ -39,6 +39,7 @@ from clawd_code_sdk.models import (
|
|
|
39
39
|
SDKControlGetTaskOutputRequest,
|
|
40
40
|
SDKControlGetTaskOutputResponse,
|
|
41
41
|
SDKControlGetUsageRequest,
|
|
42
|
+
SDKControlGetUsageResponse,
|
|
42
43
|
SDKControlInitializeRequest,
|
|
43
44
|
SDKControlInterruptRequest,
|
|
44
45
|
SDKControlInterruptResponse,
|
|
@@ -629,11 +630,17 @@ class ClaudeSDKClient:
|
|
|
629
630
|
result = await query._send_control_request(request)
|
|
630
631
|
return SDKControlGetTaskOutputResponse.model_validate(result)
|
|
631
632
|
|
|
632
|
-
async def get_usage(self, *, skip_behaviors: bool =
|
|
633
|
-
"""Get
|
|
633
|
+
async def get_usage(self, *, skip_behaviors: bool = True) -> SDKControlGetUsageResponse:
|
|
634
|
+
"""Get session usage and plan rate-limit windows (experimental, shape may change).
|
|
635
|
+
|
|
636
|
+
Args:
|
|
637
|
+
skip_behaviors: Skip the (slow) scan of local transcripts that fills
|
|
638
|
+
``behaviors``.
|
|
639
|
+
"""
|
|
634
640
|
query = self._ensure_connected()
|
|
635
641
|
request = SDKControlGetUsageRequest(skip_behaviors=skip_behaviors or None)
|
|
636
|
-
|
|
642
|
+
result = await query._send_control_request(request)
|
|
643
|
+
return SDKControlGetUsageResponse.model_validate(result)
|
|
637
644
|
|
|
638
645
|
async def get_binary_version(self) -> dict[str, Any]:
|
|
639
646
|
"""Get version info of the running Claude Code binary."""
|
|
@@ -49,12 +49,18 @@ from .context_usage import (
|
|
|
49
49
|
SDKContextUsage,
|
|
50
50
|
SDKUsageReport,
|
|
51
51
|
ContextUsageMcpInstructions,
|
|
52
|
+
ModelScopedUsageWindow,
|
|
53
|
+
UsageMoney,
|
|
54
|
+
UsageRateLimits,
|
|
55
|
+
UsageSpend,
|
|
56
|
+
UsageWindow,
|
|
52
57
|
)
|
|
53
58
|
from .control import (
|
|
54
59
|
SDKControlInterruptResponse,
|
|
55
60
|
SDKControlBackgroundTasksRequest,
|
|
56
61
|
SDKControlGetTaskOutputRequest,
|
|
57
62
|
SDKControlGetTaskOutputResponse,
|
|
63
|
+
SDKControlGetUsageResponse,
|
|
58
64
|
SDKControlGetUsageRequest,
|
|
59
65
|
SDKControlGetBinaryVersionRequest,
|
|
60
66
|
SDKControlListModelsRequest,
|
|
@@ -674,6 +680,7 @@ __all__ = [
|
|
|
674
680
|
"MiscMessages",
|
|
675
681
|
"ModelRefusalFallbackMessage",
|
|
676
682
|
"ModelRefusalNoFallbackMessage",
|
|
683
|
+
"ModelScopedUsageWindow",
|
|
677
684
|
"ModelUsage",
|
|
678
685
|
"Network",
|
|
679
686
|
"NewSession",
|
|
@@ -762,6 +769,7 @@ __all__ = [
|
|
|
762
769
|
"SDKControlGetTaskOutputRequest",
|
|
763
770
|
"SDKControlGetTaskOutputResponse",
|
|
764
771
|
"SDKControlGetUsageRequest",
|
|
772
|
+
"SDKControlGetUsageResponse",
|
|
765
773
|
"SDKControlInitializeRequest",
|
|
766
774
|
"SDKControlInterruptRequest",
|
|
767
775
|
"SDKControlInterruptResponse",
|
|
@@ -872,6 +880,10 @@ __all__ = [
|
|
|
872
880
|
"TriggerMetadata",
|
|
873
881
|
"URLPDFSource",
|
|
874
882
|
"Usage",
|
|
883
|
+
"UsageMoney",
|
|
884
|
+
"UsageRateLimits",
|
|
885
|
+
"UsageSpend",
|
|
886
|
+
"UsageWindow",
|
|
875
887
|
"UserContentBlock",
|
|
876
888
|
"UserDocumentPrompt",
|
|
877
889
|
"UserDocumentURLPrompt",
|
|
@@ -4,7 +4,7 @@ from __future__ import annotations
|
|
|
4
4
|
|
|
5
5
|
from typing import Literal
|
|
6
6
|
|
|
7
|
-
from pydantic import Field
|
|
7
|
+
from pydantic import ConfigDict, Field
|
|
8
8
|
|
|
9
9
|
from clawd_code_sdk.models.base import ClaudeCodeBaseModel
|
|
10
10
|
from clawd_code_sdk.models.usage import ModelUsage, Usage
|
|
@@ -274,6 +274,7 @@ class UsageReportDisplayName(ClaudeCodeBaseModel):
|
|
|
274
274
|
"""Wrapper holding a display name."""
|
|
275
275
|
|
|
276
276
|
display_name: str
|
|
277
|
+
id: str | None = None
|
|
277
278
|
|
|
278
279
|
|
|
279
280
|
class UsageReportLimitScope(ClaudeCodeBaseModel):
|
|
@@ -296,7 +297,13 @@ class UsageReportLimit(ClaudeCodeBaseModel):
|
|
|
296
297
|
|
|
297
298
|
|
|
298
299
|
class UsageReportExtraUsage(ClaudeCodeBaseModel):
|
|
299
|
-
"""Extra (overage) usage state.
|
|
300
|
+
"""Extra (overage) usage state.
|
|
301
|
+
|
|
302
|
+
Passed through from the claude.ai usage endpoint, which adds fields freely; unknown
|
|
303
|
+
fields are ignored even in strict (test) mode.
|
|
304
|
+
"""
|
|
305
|
+
|
|
306
|
+
model_config = ConfigDict(extra="ignore")
|
|
300
307
|
|
|
301
308
|
is_enabled: bool
|
|
302
309
|
monthly_limit: float | None
|
|
@@ -312,6 +319,74 @@ class UsageReportRateLimits(ClaudeCodeBaseModel):
|
|
|
312
319
|
extra_usage: UsageReportExtraUsage | None = None
|
|
313
320
|
|
|
314
321
|
|
|
322
|
+
class UsageWindow(ClaudeCodeBaseModel):
|
|
323
|
+
"""Utilization of one plan rate-limit window."""
|
|
324
|
+
|
|
325
|
+
model_config = ConfigDict(extra="ignore") # server-defined, see UsageReportExtraUsage
|
|
326
|
+
|
|
327
|
+
utilization: float | None
|
|
328
|
+
"""Percentage of the window used, 0-100."""
|
|
329
|
+
resets_at: str | None
|
|
330
|
+
"""ISO 8601 timestamp of the window's reset."""
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
class ModelScopedUsageWindow(UsageWindow):
|
|
334
|
+
"""Per-model weekly window."""
|
|
335
|
+
|
|
336
|
+
display_name: str
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
class UsageMoney(ClaudeCodeBaseModel):
|
|
340
|
+
"""An amount in minor units (amount_minor / 10**exponent in currency)."""
|
|
341
|
+
|
|
342
|
+
model_config = ConfigDict(extra="ignore")
|
|
343
|
+
|
|
344
|
+
amount_minor: int
|
|
345
|
+
currency: str
|
|
346
|
+
exponent: int
|
|
347
|
+
|
|
348
|
+
@property
|
|
349
|
+
def amount(self) -> float:
|
|
350
|
+
"""The amount in major units (e.g. dollars)."""
|
|
351
|
+
return self.amount_minor / 10**self.exponent
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
class UsageSpend(ClaudeCodeBaseModel):
|
|
355
|
+
"""Usage-credit spend beyond the plan windows (undocumented, server-defined)."""
|
|
356
|
+
|
|
357
|
+
model_config = ConfigDict(extra="ignore")
|
|
358
|
+
|
|
359
|
+
enabled: bool = False
|
|
360
|
+
used: UsageMoney | None = None
|
|
361
|
+
limit: UsageMoney | None = None
|
|
362
|
+
percent: float | None = None
|
|
363
|
+
"""Share of the spend limit used, 0-100."""
|
|
364
|
+
severity: str | None = None
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
class UsageRateLimits(ClaudeCodeBaseModel):
|
|
368
|
+
"""Plan rate-limit windows from the claude.ai usage endpoint.
|
|
369
|
+
|
|
370
|
+
Only the fields documented by the TypeScript SDK are modelled; the endpoint carries
|
|
371
|
+
many experimental extras, which are ignored.
|
|
372
|
+
"""
|
|
373
|
+
|
|
374
|
+
model_config = ConfigDict(extra="ignore")
|
|
375
|
+
|
|
376
|
+
five_hour: UsageWindow | None = None
|
|
377
|
+
seven_day: UsageWindow | None = None
|
|
378
|
+
seven_day_oauth_apps: UsageWindow | None = None
|
|
379
|
+
seven_day_opus: UsageWindow | None = None
|
|
380
|
+
seven_day_sonnet: UsageWindow | None = None
|
|
381
|
+
model_scoped: list[ModelScopedUsageWindow] | None = None
|
|
382
|
+
"""Per-model weekly windows (absent when unknown, empty when there are none)."""
|
|
383
|
+
extra_usage: UsageReportExtraUsage | None = None
|
|
384
|
+
limits: list[UsageReportLimit] | None = None
|
|
385
|
+
"""The server's usage rows, in the server's order (render verbatim)."""
|
|
386
|
+
spend: UsageSpend | None = None
|
|
387
|
+
"""Usage-credit spend (not documented by the TypeScript SDK; may change)."""
|
|
388
|
+
|
|
389
|
+
|
|
315
390
|
class SDKUsageReport(ClaudeCodeBaseModel):
|
|
316
391
|
"""Session usage report (same data as /usage)."""
|
|
317
392
|
|
|
@@ -15,6 +15,7 @@ from clawd_code_sdk.models.base import (
|
|
|
15
15
|
ModelName,
|
|
16
16
|
PermissionMode,
|
|
17
17
|
)
|
|
18
|
+
from clawd_code_sdk.models.context_usage import UsageRateLimits, UsageReportSession
|
|
18
19
|
from clawd_code_sdk.models.hooks import HookEvent, HookInput
|
|
19
20
|
from clawd_code_sdk.models.mcp import (
|
|
20
21
|
ExternalMcpServerConfig,
|
|
@@ -671,6 +672,20 @@ class SDKControlGetUsageRequest(_ControlBase):
|
|
|
671
672
|
skip_behaviors: bool | None = None
|
|
672
673
|
|
|
673
674
|
|
|
675
|
+
class SDKControlGetUsageResponse(ClaudeCodeBaseModel):
|
|
676
|
+
"""Structured /usage data: session totals and plan rate-limit windows. Experimental."""
|
|
677
|
+
|
|
678
|
+
session: UsageReportSession
|
|
679
|
+
"""Cost and usage accumulated by the current session."""
|
|
680
|
+
subscription_type: str | None
|
|
681
|
+
"""claude.ai plan (e.g. "pro", "max"), None without a subscription."""
|
|
682
|
+
rate_limits_available: bool
|
|
683
|
+
"""False when plan limits do not apply (API key, Bedrock, Vertex, ...)."""
|
|
684
|
+
rate_limits: UsageRateLimits | None
|
|
685
|
+
behaviors: dict[str, Any] | None = None
|
|
686
|
+
"""What contributes to usage, from a scan of local transcripts (None if skipped)."""
|
|
687
|
+
|
|
688
|
+
|
|
674
689
|
class SDKControlGetBinaryVersionRequest(_ControlBase):
|
|
675
690
|
"""Requests the version of the running Claude Code binary."""
|
|
676
691
|
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
"""The get_usage control response (real response shape, trimmed)."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from clawd_code_sdk.models import SDKControlGetUsageResponse
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
WINDOW_EXTRAS = {"limit_dollars": None, "used_dollars": None, "locked_reason": None}
|
|
11
|
+
|
|
12
|
+
RESPONSE: dict[str, Any] = {
|
|
13
|
+
"session": {
|
|
14
|
+
"total_cost_usd": 0,
|
|
15
|
+
"total_api_duration_ms": 0,
|
|
16
|
+
"total_duration_ms": 475,
|
|
17
|
+
"total_lines_added": 0,
|
|
18
|
+
"total_lines_removed": 0,
|
|
19
|
+
"model_usage": {},
|
|
20
|
+
},
|
|
21
|
+
"subscription_type": "pro",
|
|
22
|
+
"rate_limits_available": True,
|
|
23
|
+
"rate_limits": {
|
|
24
|
+
"five_hour": {
|
|
25
|
+
"utilization": 66,
|
|
26
|
+
"resets_at": "2026-11-20T09:39:59.762577+00:00",
|
|
27
|
+
**WINDOW_EXTRAS,
|
|
28
|
+
},
|
|
29
|
+
"seven_day": {
|
|
30
|
+
"utilization": 35,
|
|
31
|
+
"resets_at": "2026-11-22T12:59:59.762597+00:00",
|
|
32
|
+
**WINDOW_EXTRAS,
|
|
33
|
+
},
|
|
34
|
+
"seven_day_opus": None,
|
|
35
|
+
"extra_usage": {
|
|
36
|
+
"is_enabled": False,
|
|
37
|
+
"monthly_limit": None,
|
|
38
|
+
"used_credits": None,
|
|
39
|
+
"utilization": None,
|
|
40
|
+
"currency": None,
|
|
41
|
+
"spend_limit_reached": False,
|
|
42
|
+
},
|
|
43
|
+
"limits": [
|
|
44
|
+
{
|
|
45
|
+
"kind": "session",
|
|
46
|
+
"group": "session",
|
|
47
|
+
"percent": 66,
|
|
48
|
+
"resets_at": "2026-11-20T09:39:59.762577+00:00",
|
|
49
|
+
"severity": "normal",
|
|
50
|
+
"is_active": True,
|
|
51
|
+
"scope": None,
|
|
52
|
+
},
|
|
53
|
+
{
|
|
54
|
+
"kind": "weekly_scoped",
|
|
55
|
+
"group": "weekly",
|
|
56
|
+
"percent": 0,
|
|
57
|
+
"resets_at": "2026-11-22T13:00:00+00:00",
|
|
58
|
+
"severity": "normal",
|
|
59
|
+
"is_active": False,
|
|
60
|
+
"scope": {"model": {"id": None, "display_name": "Fable"}, "surface": None},
|
|
61
|
+
},
|
|
62
|
+
],
|
|
63
|
+
"model_scoped": [
|
|
64
|
+
{"display_name": "Fable", "utilization": 0, "resets_at": "2026-11-22T13:00:00+00:00"}
|
|
65
|
+
],
|
|
66
|
+
# Undocumented, experimental fields are ignored (spend is modelled)
|
|
67
|
+
"pace": {"status": "on_track"},
|
|
68
|
+
"spend": {
|
|
69
|
+
"used": {"amount_minor": 1250, "currency": "USD", "exponent": 2},
|
|
70
|
+
"limit": {"amount_minor": 5000, "currency": "USD", "exponent": 2},
|
|
71
|
+
"percent": 25,
|
|
72
|
+
"severity": "normal",
|
|
73
|
+
"enabled": True,
|
|
74
|
+
"disclaimer": "Usage credits cover you when you hit your plan limits.",
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
"behaviors": None,
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_parses_real_response() -> None:
|
|
82
|
+
usage = SDKControlGetUsageResponse.model_validate(RESPONSE)
|
|
83
|
+
assert usage.subscription_type == "pro"
|
|
84
|
+
limits = usage.rate_limits
|
|
85
|
+
assert limits is not None
|
|
86
|
+
assert limits.five_hour is not None
|
|
87
|
+
assert limits.five_hour.utilization == 66
|
|
88
|
+
assert limits.seven_day_opus is None
|
|
89
|
+
assert limits.model_scoped is not None
|
|
90
|
+
assert limits.model_scoped[0].display_name == "Fable"
|
|
91
|
+
assert limits.limits is not None
|
|
92
|
+
assert [row.kind for row in limits.limits] == ["session", "weekly_scoped"]
|
|
93
|
+
assert limits.spend is not None
|
|
94
|
+
assert limits.spend.enabled
|
|
95
|
+
assert limits.spend.percent == 25
|
|
96
|
+
assert limits.spend.used is not None
|
|
97
|
+
assert limits.spend.used.amount == 12.5
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_without_plan_limits() -> None:
|
|
101
|
+
data = {**RESPONSE, "subscription_type": None, "rate_limits_available": False}
|
|
102
|
+
usage = SDKControlGetUsageResponse.model_validate({**data, "rate_limits": None})
|
|
103
|
+
assert usage.rate_limits is None
|
|
@@ -1,199 +0,0 @@
|
|
|
1
|
-
"""Claude Code usage limits helper.
|
|
2
|
-
|
|
3
|
-
Fetches usage information from Anthropic's OAuth API using stored credentials.
|
|
4
|
-
Works on both Linux and macOS.
|
|
5
|
-
"""
|
|
6
|
-
|
|
7
|
-
from __future__ import annotations
|
|
8
|
-
|
|
9
|
-
import asyncio
|
|
10
|
-
from datetime import datetime
|
|
11
|
-
from pathlib import Path
|
|
12
|
-
import sys
|
|
13
|
-
|
|
14
|
-
import anyenv
|
|
15
|
-
import httpx
|
|
16
|
-
from pydantic import BaseModel
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
class UsageLimit(BaseModel):
|
|
20
|
-
"""A single usage limit with utilization percentage and reset time."""
|
|
21
|
-
|
|
22
|
-
utilization: float
|
|
23
|
-
"""Utilization percentage (0-100)."""
|
|
24
|
-
|
|
25
|
-
resets_at: datetime | None = None
|
|
26
|
-
"""When this limit resets, or None if not set."""
|
|
27
|
-
|
|
28
|
-
def format(self, name: str) -> str:
|
|
29
|
-
reset_str = ""
|
|
30
|
-
if self.resets_at:
|
|
31
|
-
reset_str = f" (resets {self.resets_at.strftime('%Y-%m-%d %H:%M UTC')})"
|
|
32
|
-
return f"{name}: {self.utilization:.0f}%{reset_str}"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
class ExtraUsage(BaseModel):
|
|
36
|
-
"""Extra usage information for paid plans."""
|
|
37
|
-
|
|
38
|
-
is_enabled: bool = False
|
|
39
|
-
monthly_limit: float | None = None
|
|
40
|
-
used_credits: float | None = None
|
|
41
|
-
utilization: float | None = None
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
class ClaudeCodeUsage(BaseModel):
|
|
45
|
-
"""Claude Code usage limits."""
|
|
46
|
-
|
|
47
|
-
five_hour: UsageLimit | None = None
|
|
48
|
-
"""5-hour rolling usage limit."""
|
|
49
|
-
|
|
50
|
-
seven_day: UsageLimit | None = None
|
|
51
|
-
"""7-day rolling usage limit."""
|
|
52
|
-
|
|
53
|
-
seven_day_opus: UsageLimit | None = None
|
|
54
|
-
"""7-day Opus-specific limit."""
|
|
55
|
-
|
|
56
|
-
seven_day_sonnet: UsageLimit | None = None
|
|
57
|
-
"""7-day Sonnet-specific limit."""
|
|
58
|
-
|
|
59
|
-
seven_day_oauth_apps: UsageLimit | None = None
|
|
60
|
-
"""7-day OAuth apps limit."""
|
|
61
|
-
|
|
62
|
-
extra_usage: ExtraUsage | None = None
|
|
63
|
-
"""Extra usage info for paid plans."""
|
|
64
|
-
|
|
65
|
-
def format_table(self) -> str:
|
|
66
|
-
"""Format usage as a readable table."""
|
|
67
|
-
lines = ["Claude Code Usage Limits", "=" * 50]
|
|
68
|
-
for name, limit in [
|
|
69
|
-
("5-hour", self.five_hour),
|
|
70
|
-
("7-day", self.seven_day),
|
|
71
|
-
("7-day Opus", self.seven_day_opus),
|
|
72
|
-
("7-day Sonnet", self.seven_day_sonnet),
|
|
73
|
-
("7-day OAuth Apps", self.seven_day_oauth_apps),
|
|
74
|
-
]:
|
|
75
|
-
if limit and (formatted := limit.format(name)):
|
|
76
|
-
lines.append(formatted)
|
|
77
|
-
|
|
78
|
-
if self.extra_usage and self.extra_usage.is_enabled:
|
|
79
|
-
lines.append("")
|
|
80
|
-
lines.append("Extra Usage (paid):")
|
|
81
|
-
if self.extra_usage.utilization is not None:
|
|
82
|
-
lines.append(f" Utilization: {self.extra_usage.utilization:.0f}%")
|
|
83
|
-
if self.extra_usage.used_credits is not None:
|
|
84
|
-
lines.append(f" Used credits: {self.extra_usage.used_credits}")
|
|
85
|
-
if self.extra_usage.monthly_limit is not None:
|
|
86
|
-
lines.append(f" Monthly limit: {self.extra_usage.monthly_limit}")
|
|
87
|
-
|
|
88
|
-
return "\n".join(lines)
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
def _get_credentials_path() -> Path | None:
|
|
92
|
-
"""Get the path to Claude Code credentials file.
|
|
93
|
-
|
|
94
|
-
Returns:
|
|
95
|
-
Path to credentials file, or None if not found.
|
|
96
|
-
"""
|
|
97
|
-
# Linux: ~/.claude/.credentials.json
|
|
98
|
-
linux_path = Path.home() / ".claude" / ".credentials.json"
|
|
99
|
-
if linux_path.exists():
|
|
100
|
-
return linux_path
|
|
101
|
-
# macOS: Also check ~/.claude first (newer versions)
|
|
102
|
-
if linux_path.exists():
|
|
103
|
-
return linux_path
|
|
104
|
-
return None
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
def _get_access_token_from_file(path: Path) -> str | None:
|
|
108
|
-
"""Read access token from credentials file."""
|
|
109
|
-
try:
|
|
110
|
-
data = anyenv.load_json(path.read_text(), return_type=dict)
|
|
111
|
-
val = data.get("claudeAiOauth", {}).get("accessToken")
|
|
112
|
-
except (anyenv.JsonLoadError, OSError):
|
|
113
|
-
return None
|
|
114
|
-
else:
|
|
115
|
-
assert isinstance(val, str)
|
|
116
|
-
return val
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
async def _get_access_token_from_keychain() -> str | None:
|
|
120
|
-
"""Read access token from macOS Keychain."""
|
|
121
|
-
if sys.platform != "darwin":
|
|
122
|
-
return None
|
|
123
|
-
|
|
124
|
-
try: # type: ignore[unreachable]
|
|
125
|
-
proc = await asyncio.create_subprocess_exec(
|
|
126
|
-
"security",
|
|
127
|
-
"find-generic-password",
|
|
128
|
-
"-s",
|
|
129
|
-
"Claude Code-credentials",
|
|
130
|
-
"-w",
|
|
131
|
-
stdout=asyncio.subprocess.PIPE,
|
|
132
|
-
stderr=asyncio.subprocess.PIPE,
|
|
133
|
-
)
|
|
134
|
-
stdout, _ = await proc.communicate()
|
|
135
|
-
if proc.returncode != 0:
|
|
136
|
-
return None
|
|
137
|
-
data = anyenv.load_json(stdout.decode().strip(), return_type=dict)
|
|
138
|
-
val = data.get("claudeAiOauth", {}).get("accessToken")
|
|
139
|
-
except (anyenv.JsonLoadError, FileNotFoundError, OSError):
|
|
140
|
-
return None
|
|
141
|
-
else:
|
|
142
|
-
assert isinstance(val, str)
|
|
143
|
-
return val
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
async def get_access_token() -> str | None:
|
|
147
|
-
"""Get Claude Code OAuth access token.
|
|
148
|
-
|
|
149
|
-
Checks both file-based storage (Linux/newer macOS) and Keychain (macOS).
|
|
150
|
-
|
|
151
|
-
Returns:
|
|
152
|
-
Access token string, or None if not found.
|
|
153
|
-
"""
|
|
154
|
-
# Try file-based first (works on Linux and newer macOS)
|
|
155
|
-
if (path := _get_credentials_path()) and (token := _get_access_token_from_file(path)):
|
|
156
|
-
return token
|
|
157
|
-
return await _get_access_token_from_keychain() # Fall back to macOS Keychain
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
async def get_usage(token: str | None = None) -> ClaudeCodeUsage:
|
|
161
|
-
"""Fetch Claude Code usage limits asynchronously.
|
|
162
|
-
|
|
163
|
-
Args:
|
|
164
|
-
token: OAuth access token. If not provided, will attempt to read from
|
|
165
|
-
stored credentials.
|
|
166
|
-
|
|
167
|
-
Returns:
|
|
168
|
-
ClaudeCodeUsage with current limits.
|
|
169
|
-
|
|
170
|
-
Raises:
|
|
171
|
-
ValueError: If no token provided and credentials not found.
|
|
172
|
-
httpx.HTTPStatusError: If API request fails.
|
|
173
|
-
"""
|
|
174
|
-
if token is None:
|
|
175
|
-
token = await get_access_token()
|
|
176
|
-
if token is None:
|
|
177
|
-
msg = "No Claude Code credentials found. Please authenticate with Claude Code first."
|
|
178
|
-
raise ValueError(msg)
|
|
179
|
-
|
|
180
|
-
async with httpx.AsyncClient() as client:
|
|
181
|
-
headers = {
|
|
182
|
-
"Accept": "application/json",
|
|
183
|
-
"Content-Type": "application/json",
|
|
184
|
-
"User-Agent": "claude-code/2.0.32",
|
|
185
|
-
"Authorization": f"Bearer {token}",
|
|
186
|
-
"anthropic-beta": "oauth-2025-04-20",
|
|
187
|
-
}
|
|
188
|
-
response = await client.get("https://api.anthropic.com/api/oauth/usage", headers=headers)
|
|
189
|
-
response.raise_for_status()
|
|
190
|
-
return ClaudeCodeUsage.model_validate(response.json())
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
if __name__ == "__main__":
|
|
194
|
-
|
|
195
|
-
async def main() -> None:
|
|
196
|
-
usage = await get_usage()
|
|
197
|
-
print(usage.format_table())
|
|
198
|
-
|
|
199
|
-
asyncio.run(main())
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/_internal/sdk_mcp_bridge.py
RENAMED
|
File without changes
|
{clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/_internal/session_mutations.py
RENAMED
|
File without changes
|
|
File without changes
|
{clawd_code_sdk-1.2.3 → clawd_code_sdk-1.2.5}/src/clawd_code_sdk/_internal/transport/__init__.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|