clawd-code-sdk 1.2.4__tar.gz → 1.2.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.
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/PKG-INFO +1 -1
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/pyproject.toml +1 -1
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/client.py +3 -2
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/models/__init__.py +4 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/models/context_usage.py +30 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/models/server_info.py +5 -1
- clawd_code_sdk-1.2.6/tests/test_apply_flag_settings.py +28 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/test_get_usage.py +14 -2
- clawd_code_sdk-1.2.4/src/clawd_code_sdk/usage.py +0 -199
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/.gitignore +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/LICENSE +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/README.md +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/__init__.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/_bundled/.gitignore +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/_errors.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/_internal/__init__.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/_internal/mcp_compat.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/_internal/query.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/_internal/sdk_mcp_bridge.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/_internal/session_mutations.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/_internal/sessions.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/_internal/transport/__init__.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/_internal/transport/subprocess_cli.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/_internal/transport/subprocess_utils.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/_version.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/anthropic_stream.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/instrumentation.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/list_sessions.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/mcp_utils.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/models/agents.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/models/anthropic_types.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/models/base.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/models/content_blocks.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/models/control.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/models/hooks.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/models/input_types.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/models/mcp.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/models/messages.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/models/options.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/models/output_types.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/models/permissions.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/models/prompt_requests.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/models/prompts.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/models/session.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/models/settings.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/models/system_messages.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/models/thinking.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/models/usage.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/py.typed +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/session.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/storage/ARCHITECTURE.md +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/storage/__init__.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/storage/helpers.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/storage/models.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/storage/replay.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/__init__.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/conftest.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/e2e/__init__.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/e2e/test_agents_and_settings.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/e2e/test_dynamic_control.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/e2e/test_hook_events.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/e2e/test_hooks.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/e2e/test_include_partial_messages.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/e2e/test_mcp_resources.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/e2e/test_mcp_tools.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/e2e/test_sdk_mcp_resources.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/e2e/test_sdk_mcp_tools.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/e2e/test_slash_commands.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/e2e/test_stderr_callback.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/e2e/test_storage_parsing.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/e2e/test_structured_output.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/e2e/test_subagent_invocation.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/e2e/test_tool_permissions.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/mcp_server.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/mock_claude_server.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/test_api_content_blocks.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/test_changelog.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/test_client.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/test_elicitation_mcp_conversion.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/test_errors.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/test_image.png +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/test_integration.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/test_line_framing.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/test_message_parser.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/test_result_error.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/test_sandbox_settings.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/test_sdk_0_3_types.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/test_sdk_mcp_integration.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/test_session.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/test_session_mutations.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/test_sessions.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/test_streaming_client.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/test_subprocess_buffering.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/test_tool_callbacks.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/tests/test_transport.py +0 -0
- {clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/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.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
|
|
@@ -507,10 +507,11 @@ class ClaudeSDKClient:
|
|
|
507
507
|
other sources (user, project, etc.) to produce the effective settings.
|
|
508
508
|
|
|
509
509
|
Args:
|
|
510
|
-
settings: Settings to apply. Only
|
|
510
|
+
settings: Settings to apply. Only fields that were set explicitly (and are
|
|
511
|
+
not None) are sent: defaults would override every other settings source.
|
|
511
512
|
"""
|
|
512
513
|
query = self._ensure_connected()
|
|
513
|
-
serialized = settings.model_dump(by_alias=True, exclude_none=True)
|
|
514
|
+
serialized = settings.model_dump(by_alias=True, exclude_unset=True, exclude_none=True)
|
|
514
515
|
req = SDKControlApplyFlagSettingsRequest(settings=serialized)
|
|
515
516
|
await query._send_control_request(req)
|
|
516
517
|
|
|
@@ -50,7 +50,9 @@ from .context_usage import (
|
|
|
50
50
|
SDKUsageReport,
|
|
51
51
|
ContextUsageMcpInstructions,
|
|
52
52
|
ModelScopedUsageWindow,
|
|
53
|
+
UsageMoney,
|
|
53
54
|
UsageRateLimits,
|
|
55
|
+
UsageSpend,
|
|
54
56
|
UsageWindow,
|
|
55
57
|
)
|
|
56
58
|
from .control import (
|
|
@@ -878,7 +880,9 @@ __all__ = [
|
|
|
878
880
|
"TriggerMetadata",
|
|
879
881
|
"URLPDFSource",
|
|
880
882
|
"Usage",
|
|
883
|
+
"UsageMoney",
|
|
881
884
|
"UsageRateLimits",
|
|
885
|
+
"UsageSpend",
|
|
882
886
|
"UsageWindow",
|
|
883
887
|
"UserContentBlock",
|
|
884
888
|
"UserDocumentPrompt",
|
|
@@ -336,6 +336,34 @@ class ModelScopedUsageWindow(UsageWindow):
|
|
|
336
336
|
display_name: str
|
|
337
337
|
|
|
338
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
|
+
|
|
339
367
|
class UsageRateLimits(ClaudeCodeBaseModel):
|
|
340
368
|
"""Plan rate-limit windows from the claude.ai usage endpoint.
|
|
341
369
|
|
|
@@ -355,6 +383,8 @@ class UsageRateLimits(ClaudeCodeBaseModel):
|
|
|
355
383
|
extra_usage: UsageReportExtraUsage | None = None
|
|
356
384
|
limits: list[UsageReportLimit] | None = None
|
|
357
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)."""
|
|
358
388
|
|
|
359
389
|
|
|
360
390
|
class SDKUsageReport(ClaudeCodeBaseModel):
|
|
@@ -52,12 +52,16 @@ class ClaudeCodeModelInfo(ClaudeCodeBaseModel):
|
|
|
52
52
|
"""Whether the model supports fast mode."""
|
|
53
53
|
|
|
54
54
|
supports_auto_mode: bool | None = None
|
|
55
|
+
"""Whether the model supports auto mode."""
|
|
56
|
+
|
|
55
57
|
supports_thinking_off: bool | None = None
|
|
58
|
+
"""Whether thinking can be turned off for the model."""
|
|
59
|
+
|
|
56
60
|
disabled: bool | None = None
|
|
57
61
|
"""Visible but not selectable (only set for entries in ``unavailable_models``)."""
|
|
62
|
+
|
|
58
63
|
resolved_model: str | None = None
|
|
59
64
|
"""Concrete model ID this entry resolves to (e.g. for aliases)."""
|
|
60
|
-
"""Whether the model supports auto mode."""
|
|
61
65
|
|
|
62
66
|
|
|
63
67
|
class ClaudeCodeCommandInfo(ClaudeCodeBaseModel):
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
"""The apply_flag_settings control request sends only the settings that were set."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any, cast
|
|
6
|
+
|
|
7
|
+
from clawd_code_sdk import ClaudeAgentOptions, ClaudeSDKClient
|
|
8
|
+
from clawd_code_sdk.models.control import SDKControlApplyFlagSettingsRequest
|
|
9
|
+
from clawd_code_sdk.models.settings import ClaudeCodeSettings
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class _RecordingQuery:
|
|
13
|
+
def __init__(self) -> None:
|
|
14
|
+
self.requests: list[Any] = []
|
|
15
|
+
|
|
16
|
+
async def _send_control_request(self, request: Any) -> dict[str, Any]:
|
|
17
|
+
self.requests.append(request)
|
|
18
|
+
return {}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
async def test_only_set_fields_are_sent() -> None:
|
|
22
|
+
client = ClaudeSDKClient(ClaudeAgentOptions())
|
|
23
|
+
query = _RecordingQuery()
|
|
24
|
+
client._query = cast(Any, query)
|
|
25
|
+
|
|
26
|
+
await client.apply_flag_settings(ClaudeCodeSettings(effort_level="low"))
|
|
27
|
+
|
|
28
|
+
assert query.requests == [SDKControlApplyFlagSettingsRequest(settings={"effortLevel": "low"})]
|
|
@@ -63,9 +63,16 @@ RESPONSE: dict[str, Any] = {
|
|
|
63
63
|
"model_scoped": [
|
|
64
64
|
{"display_name": "Fable", "utilization": 0, "resets_at": "2026-11-22T13:00:00+00:00"}
|
|
65
65
|
],
|
|
66
|
-
# Undocumented, experimental fields are ignored
|
|
66
|
+
# Undocumented, experimental fields are ignored (spend is modelled)
|
|
67
67
|
"pace": {"status": "on_track"},
|
|
68
|
-
"spend": {
|
|
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
|
+
},
|
|
69
76
|
},
|
|
70
77
|
"behaviors": None,
|
|
71
78
|
}
|
|
@@ -83,6 +90,11 @@ def test_parses_real_response() -> None:
|
|
|
83
90
|
assert limits.model_scoped[0].display_name == "Fable"
|
|
84
91
|
assert limits.limits is not None
|
|
85
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
|
|
86
98
|
|
|
87
99
|
|
|
88
100
|
def test_without_plan_limits() -> 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.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/_internal/sdk_mcp_bridge.py
RENAMED
|
File without changes
|
{clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/src/clawd_code_sdk/_internal/session_mutations.py
RENAMED
|
File without changes
|
|
File without changes
|
{clawd_code_sdk-1.2.4 → clawd_code_sdk-1.2.6}/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
|