pydantic-claude-code 0.7.2__tar.gz → 0.7.3__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 (36) hide show
  1. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/PKG-INFO +10 -6
  2. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/README.md +9 -5
  3. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/pyproject.toml +1 -1
  4. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/src/pydantic_ai_claude_code/__init__.py +1 -1
  5. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/src/pydantic_ai_claude_code/model.py +25 -3
  6. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/tests/test_model.py +54 -2
  7. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/uv.lock +1 -1
  8. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/.github/workflows/ci.yml +0 -0
  9. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/.github/workflows/publish.yml +0 -0
  10. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/.gitignore +0 -0
  11. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/LICENSE +0 -0
  12. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/examples/basic.py +0 -0
  13. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/install.sh +0 -0
  14. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/scripts/sync_gist.sh +0 -0
  15. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/src/pydantic_ai_claude_code/__main__.py +0 -0
  16. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/src/pydantic_ai_claude_code/auth.py +0 -0
  17. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/src/pydantic_ai_claude_code/clai2.py +0 -0
  18. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/src/pydantic_ai_claude_code/config.py +0 -0
  19. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/src/pydantic_ai_claude_code/credentials.py +0 -0
  20. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/src/pydantic_ai_claude_code/flow.py +0 -0
  21. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/src/pydantic_ai_claude_code/provider.py +0 -0
  22. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/src/pydantic_ai_claude_code/py.typed +0 -0
  23. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/src/pydantic_ai_claude_code/storage.py +0 -0
  24. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/src/pydantic_ai_claude_code/updates.py +0 -0
  25. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/tests/conftest.py +0 -0
  26. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/tests/test_callback_server.py +0 -0
  27. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/tests/test_clai2.py +0 -0
  28. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/tests/test_credentials.py +0 -0
  29. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/tests/test_flow.py +0 -0
  30. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/tests/test_install.py +0 -0
  31. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/tests/test_integration.py +0 -0
  32. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/tests/test_keyring_store.py +0 -0
  33. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/tests/test_provider.py +0 -0
  34. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/tests/test_refresh.py +0 -0
  35. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/tests/test_storage.py +0 -0
  36. {pydantic_claude_code-0.7.2 → pydantic_claude_code-0.7.3}/tests/test_updates.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: pydantic-claude-code
3
- Version: 0.7.2
3
+ Version: 0.7.3
4
4
  Summary: Use your Claude Code subscription from a Pydantic AI Agent or CLAI2, with full tool support
5
5
  Project-URL: Source, https://gist.github.com/mpfaffenberger/bd75c7b424ffdc6d81645bfe7de822d3
6
6
  Project-URL: Homepage, https://pypi.org/project/pydantic-claude-code/
@@ -201,10 +201,14 @@ provider. Instead of a `claude-code:` model string, construct
201
201
  `ClaudeCodeModel('claude-fable-5-1')` directly; it connects itself to a
202
202
  `ClaudeCodeProvider` by default.
203
203
 
204
- `ClaudeCodeModel` enables prompt caching with a **1-hour TTL** by default. Override it with
205
- `settings=AnthropicModelSettings(anthropic_cache="5m")`, or disable default caching with
206
- `settings=AnthropicModelSettings(anthropic_cache=False)`. Per-request settings take precedence.
207
- Tool-definition, static-instruction, and latest-tool-call breakpoints use Pydantic AI's caching implementation.
204
+ `ClaudeCodeModel` enables prompt caching with a **1-hour TTL** by default, on the conversation and on the
205
+ static prefix: the tool definitions and the instructions get breakpoints of their own, so a new conversation
206
+ reads the prefix earlier ones cached instead of writing it again at the 1-hour price. Passing any
207
+ `anthropic_cache*` setting to the model replaces this default as a whole: for example
208
+ `settings=AnthropicModelSettings(anthropic_cache="5m")` caches only the conversation, for 5 minutes, and
209
+ `settings=AnthropicModelSettings(anthropic_cache=False)` turns caching off. Per-request settings take precedence
210
+ key by key, so to turn caching off for one request, set `anthropic_cache`, `anthropic_cache_instructions` and
211
+ `anthropic_cache_tool_definitions` to `False`.
208
212
 
209
213
  ### Quick start
210
214
 
@@ -336,7 +340,7 @@ uv run pytest
336
340
 
337
341
  To release, bump `version` in `pyproject.toml` and `__version__` in
338
342
  `src/pydantic_ai_claude_code/__init__.py` (a test checks they match), merge, and
339
- push a matching tag (`git tag v0.7.2 && git push origin v0.7.2`). The `Publish` workflow tests,
343
+ push a matching tag (`git tag v0.7.3 && git push origin v0.7.3`). The `Publish` workflow tests,
340
344
  builds, and uploads it to PyPI with the `PYPI_API_TOKEN` repository secret. Then run
341
345
  `scripts/sync_gist.sh` to publish the release to the install gist, which is what the one-liner and the
342
346
  update notice install from.
@@ -172,10 +172,14 @@ provider. Instead of a `claude-code:` model string, construct
172
172
  `ClaudeCodeModel('claude-fable-5-1')` directly; it connects itself to a
173
173
  `ClaudeCodeProvider` by default.
174
174
 
175
- `ClaudeCodeModel` enables prompt caching with a **1-hour TTL** by default. Override it with
176
- `settings=AnthropicModelSettings(anthropic_cache="5m")`, or disable default caching with
177
- `settings=AnthropicModelSettings(anthropic_cache=False)`. Per-request settings take precedence.
178
- Tool-definition, static-instruction, and latest-tool-call breakpoints use Pydantic AI's caching implementation.
175
+ `ClaudeCodeModel` enables prompt caching with a **1-hour TTL** by default, on the conversation and on the
176
+ static prefix: the tool definitions and the instructions get breakpoints of their own, so a new conversation
177
+ reads the prefix earlier ones cached instead of writing it again at the 1-hour price. Passing any
178
+ `anthropic_cache*` setting to the model replaces this default as a whole: for example
179
+ `settings=AnthropicModelSettings(anthropic_cache="5m")` caches only the conversation, for 5 minutes, and
180
+ `settings=AnthropicModelSettings(anthropic_cache=False)` turns caching off. Per-request settings take precedence
181
+ key by key, so to turn caching off for one request, set `anthropic_cache`, `anthropic_cache_instructions` and
182
+ `anthropic_cache_tool_definitions` to `False`.
179
183
 
180
184
  ### Quick start
181
185
 
@@ -307,7 +311,7 @@ uv run pytest
307
311
 
308
312
  To release, bump `version` in `pyproject.toml` and `__version__` in
309
313
  `src/pydantic_ai_claude_code/__init__.py` (a test checks they match), merge, and
310
- push a matching tag (`git tag v0.7.2 && git push origin v0.7.2`). The `Publish` workflow tests,
314
+ push a matching tag (`git tag v0.7.3 && git push origin v0.7.3`). The `Publish` workflow tests,
311
315
  builds, and uploads it to PyPI with the `PYPI_API_TOKEN` repository secret. Then run
312
316
  `scripts/sync_gist.sh` to publish the release to the install gist, which is what the one-liner and the
313
317
  update notice install from.
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "pydantic-claude-code"
7
- version = "0.7.2"
7
+ version = "0.7.3"
8
8
  description = "Use your Claude Code subscription from a Pydantic AI Agent or CLAI2, with full tool support"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.10,<3.15"
@@ -26,7 +26,7 @@ from .model import ClaudeCodeModel
26
26
  from .provider import ClaudeCodeProvider
27
27
  from .storage import ClaudeCodeTokenStore, KeyringTokenStore, default_auth_path, default_store
28
28
 
29
- __version__ = "0.7.2"
29
+ __version__ = "0.7.3"
30
30
  """Matches `version` in pyproject.toml (a test checks), so a copied folder knows its release."""
31
31
 
32
32
 
@@ -18,6 +18,29 @@ from pydantic_ai.settings import ModelSettings
18
18
  from . import config
19
19
  from .auth import ClaudeCodeSignInExpiredError
20
20
 
21
+ _CACHE_SETTINGS = (
22
+ "anthropic_cache",
23
+ "anthropic_cache_instructions",
24
+ "anthropic_cache_tool_definitions",
25
+ "anthropic_cache_messages",
26
+ )
27
+ """The explicit Anthropic cache settings. Any one of them replaces the default caching as a whole."""
28
+
29
+
30
+ def _default_cache_settings(settings: ModelSettings | None) -> AnthropicModelSettings:
31
+ """One-hour caching of the conversation and of the static prefix, unless `settings` choose caching themselves.
32
+
33
+ Pydantic AI's unified `cache` setting, which CLAI sends, puts breakpoints after the tool definitions and the
34
+ instructions, so every new conversation reads that shared prefix instead of writing it again. An explicit
35
+ `anthropic_cache*` setting turns the unified one off, so a default naming only `anthropic_cache` would leave
36
+ just the conversation breakpoint: each new session would write its whole prefix at the one-hour price.
37
+ """
38
+ if settings and any(key in settings for key in _CACHE_SETTINGS):
39
+ return AnthropicModelSettings()
40
+ return AnthropicModelSettings(
41
+ anthropic_cache="1h", anthropic_cache_instructions="1h", anthropic_cache_tool_definitions="1h"
42
+ )
43
+
21
44
 
22
45
  class ClaudeCodeModel(AnthropicModel):
23
46
  """AnthropicModel whose system prompt opens with the Claude Code persona.
@@ -45,10 +68,9 @@ class ClaudeCodeModel(AnthropicModel):
45
68
  from .provider import ClaudeCodeProvider
46
69
 
47
70
  provider = ClaudeCodeProvider()
48
- defaults = AnthropicModelSettings(
49
- anthropic_cache=False if settings and settings.get("anthropic_cache_messages") else "1h",
71
+ super().__init__(
72
+ model_name, provider=provider, settings={**_default_cache_settings(settings), **(settings or {})}, **kwargs
50
73
  )
51
- super().__init__(model_name, provider=provider, settings={**defaults, **(settings or {})}, **kwargs)
52
74
 
53
75
  async def _map_message(
54
76
  self,
@@ -15,7 +15,7 @@ from pydantic_ai.providers.anthropic import AnthropicProvider
15
15
  from conftest import MessagesServer
16
16
  from pydantic_ai_claude_code import config
17
17
  from pydantic_ai_claude_code.credentials import ClaudeCodeCredentials
18
- from pydantic_ai_claude_code.model import ClaudeCodeModel, _persona_first
18
+ from pydantic_ai_claude_code.model import ClaudeCodeModel, _default_cache_settings, _persona_first
19
19
  from pydantic_ai_claude_code.provider import ClaudeCodeProvider
20
20
 
21
21
 
@@ -33,11 +33,63 @@ def test_cache_retention_defaults_to_one_hour(
33
33
  ) -> None:
34
34
  model = ClaudeCodeModel("claude-sonnet-4-6", provider=AnthropicProvider(api_key="test-key"), settings=settings)
35
35
  assert model.resolve_cache_retention(None) == expected
36
+ # Per-request settings win key by key, and the longest active breakpoint sets the retention.
36
37
  assert model.resolve_cache_retention(
37
- AnthropicModelSettings(anthropic_cache="5m", anthropic_cache_messages=False)
38
+ AnthropicModelSettings(
39
+ anthropic_cache="5m",
40
+ anthropic_cache_instructions="5m",
41
+ anthropic_cache_tool_definitions="5m",
42
+ anthropic_cache_messages=False,
43
+ )
38
44
  ) == timedelta(minutes=5)
39
45
 
40
46
 
47
+ ONE_HOUR = {"type": "ephemeral", "ttl": "1h"}
48
+
49
+
50
+ def test_the_default_caches_the_static_prefix_as_well_as_the_conversation() -> None:
51
+ assert _default_cache_settings(None) == AnthropicModelSettings(
52
+ anthropic_cache="1h", anthropic_cache_instructions="1h", anthropic_cache_tool_definitions="1h"
53
+ )
54
+
55
+
56
+ @pytest.mark.parametrize(
57
+ "settings",
58
+ [
59
+ AnthropicModelSettings(anthropic_cache="5m"),
60
+ AnthropicModelSettings(anthropic_cache=False),
61
+ AnthropicModelSettings(anthropic_cache_instructions=False),
62
+ AnthropicModelSettings(anthropic_cache_tool_definitions="5m"),
63
+ AnthropicModelSettings(anthropic_cache_messages="1h"),
64
+ ],
65
+ )
66
+ def test_any_explicit_cache_setting_replaces_the_whole_default(settings: AnthropicModelSettings) -> None:
67
+ model = ClaudeCodeModel("claude-sonnet-4-6", provider=AnthropicProvider(api_key="test-key"), settings=settings)
68
+ assert model.settings == settings
69
+
70
+
71
+ async def test_a_new_session_marks_the_tools_and_instructions_for_reuse(messages_stub: MessagesServer) -> None:
72
+ """CLAI sends the unified `cache` setting; the plugin's one-hour default must keep its static breakpoints."""
73
+ provider = ClaudeCodeProvider(
74
+ ClaudeCodeCredentials(access_token="sub-token", refresh_token="refresh"), base_url=messages_stub.url
75
+ )
76
+ agent = Agent(ClaudeCodeModel("claude-opus-5-5", provider=provider), instructions="Be terse.")
77
+
78
+ @agent.tool_plain
79
+ def lookup(key: str) -> str:
80
+ """Look a key up."""
81
+ return key # pragma: no cover -- the stub never calls tools
82
+
83
+ await agent.run("go on", model_settings={"cache": True})
84
+ body = messages_stub.received
85
+ tools = body["tools"]
86
+ system = body["system"]
87
+ assert isinstance(tools, list) and isinstance(system, list)
88
+ assert tools[-1]["cache_control"] == ONE_HOUR
89
+ assert system[-1]["cache_control"] == ONE_HOUR
90
+ assert body["cache_control"] == ONE_HOUR, "the conversation keeps its moving one-hour breakpoint"
91
+
92
+
41
93
  PERSONA = config.CLAUDE_CODE_SYSTEM_PROMPT
42
94
  SUMMARY = "Summary of previous conversation:\n\n## Intent\nShip the plugin."
43
95
 
@@ -1430,7 +1430,7 @@ wheels = [
1430
1430
 
1431
1431
  [[package]]
1432
1432
  name = "pydantic-claude-code"
1433
- version = "0.7.2"
1433
+ version = "0.7.3"
1434
1434
  source = { editable = "." }
1435
1435
  dependencies = [
1436
1436
  { name = "keyring" },