pydantic-claude-code 0.7.5__tar.gz → 0.7.7__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.
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/PKG-INFO +66 -19
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/README.md +64 -17
- pydantic_claude_code-0.7.7/install.ps1 +42 -0
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/install.sh +2 -2
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/pyproject.toml +4 -2
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/scripts/sync_gist.sh +1 -1
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/src/pydantic_ai_claude_code/__init__.py +2 -2
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/src/pydantic_ai_claude_code/clai2.py +107 -18
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/src/pydantic_ai_claude_code/model.py +75 -6
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/src/pydantic_ai_claude_code/updates.py +6 -4
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/tests/test_clai2.py +115 -7
- pydantic_claude_code-0.7.7/tests/test_install.py +160 -0
- pydantic_claude_code-0.7.7/tests/test_model.py +293 -0
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/tests/test_updates.py +6 -4
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/uv.lock +2 -2
- pydantic_claude_code-0.7.5/tests/test_install.py +0 -70
- pydantic_claude_code-0.7.5/tests/test_model.py +0 -146
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/.github/workflows/ci.yml +0 -0
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/.github/workflows/publish.yml +0 -0
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/.gitignore +0 -0
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/LICENSE +0 -0
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/examples/basic.py +0 -0
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/src/pydantic_ai_claude_code/__main__.py +0 -0
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/src/pydantic_ai_claude_code/auth.py +0 -0
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/src/pydantic_ai_claude_code/config.py +0 -0
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/src/pydantic_ai_claude_code/credentials.py +0 -0
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/src/pydantic_ai_claude_code/flow.py +0 -0
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/src/pydantic_ai_claude_code/provider.py +0 -0
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/src/pydantic_ai_claude_code/py.typed +0 -0
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/src/pydantic_ai_claude_code/storage.py +0 -0
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/tests/conftest.py +0 -0
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/tests/test_callback_server.py +0 -0
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/tests/test_credentials.py +0 -0
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/tests/test_flow.py +0 -0
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/tests/test_integration.py +0 -0
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/tests/test_keyring_store.py +0 -0
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/tests/test_provider.py +0 -0
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/tests/test_refresh.py +0 -0
- {pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/tests/test_storage.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: pydantic-claude-code
|
|
3
|
-
Version: 0.7.
|
|
3
|
+
Version: 0.7.7
|
|
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/
|
|
@@ -17,7 +17,7 @@ Classifier: Programming Language :: Python :: 3.13
|
|
|
17
17
|
Classifier: Programming Language :: Python :: 3.14
|
|
18
18
|
Requires-Python: <3.15,>=3.10
|
|
19
19
|
Requires-Dist: keyring<26,>=23
|
|
20
|
-
Requires-Dist: pydantic-ai-slim[anthropic]<3,>=2.
|
|
20
|
+
Requires-Dist: pydantic-ai-slim[anthropic]<3,>=2.38.0
|
|
21
21
|
Provides-Extra: clai2
|
|
22
22
|
Requires-Dist: pydantic-clai2>=0.53.0; extra == 'clai2'
|
|
23
23
|
Provides-Extra: dev
|
|
@@ -61,33 +61,51 @@ so the stock agent, Coder, and your other plugins all keep working.
|
|
|
61
61
|
|
|
62
62
|
### Install
|
|
63
63
|
|
|
64
|
-
One line installs the latest release of the plugin, and running it again updates it
|
|
64
|
+
One line installs the latest release of the plugin, and running it again updates it.
|
|
65
|
+
|
|
66
|
+
**macOS and Linux:**
|
|
65
67
|
|
|
66
68
|
```bash
|
|
67
69
|
curl -fsSL https://gist.githubusercontent.com/mpfaffenberger/bd75c7b424ffdc6d81645bfe7de822d3/raw/install.sh | sh
|
|
68
70
|
```
|
|
69
71
|
|
|
72
|
+
**Windows (PowerShell):**
|
|
73
|
+
|
|
74
|
+
```powershell
|
|
75
|
+
irm https://gist.githubusercontent.com/mpfaffenberger/bd75c7b424ffdc6d81645bfe7de822d3/raw/install.ps1 | iex
|
|
76
|
+
```
|
|
77
|
+
|
|
70
78
|
The plugin is published as a [gist](https://gist.github.com/mpfaffenberger/bd75c7b424ffdc6d81645bfe7de822d3): its files are this repo's
|
|
71
|
-
`src/pydantic_ai_claude_code` folder at the latest release, plus `install.sh`.
|
|
79
|
+
`src/pydantic_ai_claude_code` folder at the latest release, plus `install.sh` and `install.ps1`.
|
|
72
80
|
The script downloads the gist and puts its files in CLAI2's plugins folder as
|
|
73
81
|
`claude_code`, replacing any older copy. To pin a release, pass a gist
|
|
74
|
-
revision (`... | sh -s -- REVISION
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
82
|
+
revision (`... | sh -s -- REVISION` on macOS/Linux, or
|
|
83
|
+
`$env:CLAUDE_CODE_REVISION = 'REVISION'; irm .../install.ps1 | iex` on Windows;
|
|
84
|
+
the gist's revisions are named after releases). Nothing to `pip install`: everything
|
|
85
|
+
the plugin imports (`pydantic-ai` with Anthropic support, `httpx2`, `keyring`)
|
|
86
|
+
already ships with CLAI2.
|
|
87
|
+
|
|
88
|
+
The plugins folder is `$XDG_CONFIG_HOME/pydantic-clai2/plugins/`, which defaults to
|
|
89
|
+
`~/.config/pydantic-clai2/plugins/` on macOS and Linux and
|
|
90
|
+
`%USERPROFILE%\.config\pydantic-clai2\plugins\` on Windows: the folder
|
|
81
91
|
next to CLAI2's `config.db`. To install by hand, clone the gist there yourself
|
|
82
92
|
(`git pull` in that folder then updates it):
|
|
83
93
|
|
|
84
94
|
```bash
|
|
95
|
+
# macOS / Linux
|
|
85
96
|
mkdir -p ~/.config/pydantic-clai2/plugins
|
|
86
97
|
git clone https://gist.github.com/mpfaffenberger/bd75c7b424ffdc6d81645bfe7de822d3.git ~/.config/pydantic-clai2/plugins/claude_code
|
|
87
98
|
```
|
|
88
99
|
|
|
100
|
+
```powershell
|
|
101
|
+
# Windows (PowerShell)
|
|
102
|
+
New-Item -ItemType Directory -Force "$HOME\.config\pydantic-clai2\plugins" | Out-Null
|
|
103
|
+
git clone https://gist.github.com/mpfaffenberger/bd75c7b424ffdc6d81645bfe7de822d3.git "$HOME\.config\pydantic-clai2\plugins\claude_code"
|
|
104
|
+
```
|
|
105
|
+
|
|
89
106
|
To hack on the plugin, symlink the folder instead of copying it:
|
|
90
|
-
`ln -s "$PWD/src/pydantic_ai_claude_code" ~/.config/pydantic-clai2/plugins/claude_code
|
|
107
|
+
`ln -s "$PWD/src/pydantic_ai_claude_code" ~/.config/pydantic-clai2/plugins/claude_code`
|
|
108
|
+
(on Windows PowerShell: `New-Item -ItemType Junction -Path "$HOME\.config\pydantic-clai2\plugins\claude_code" -Target "$PWD\src\pydantic_ai_claude_code"`).
|
|
91
109
|
|
|
92
110
|
Dropped-in plugins load when CLAI2 starts. Inside CLAI2, `/plugins` lists it as
|
|
93
111
|
`claude_code`, where Space turns it off and on. (The shell's `clai2 plugins list`
|
|
@@ -98,7 +116,10 @@ When a newer release is out, it says so once, after your first reply, with the
|
|
|
98
116
|
one-liner to update. Being offline is silent. Set `CLAUDE_CODE_NO_UPDATE_CHECK=1`
|
|
99
117
|
to turn the check off.
|
|
100
118
|
|
|
101
|
-
**
|
|
119
|
+
**Pax:** If you already run `pax`, use the same drop-in install and `/login claude-code`.
|
|
120
|
+
Pax reads the same `pydantic-clai2/plugins` folder. No legacy package is required.
|
|
121
|
+
|
|
122
|
+
**Legacy CLAI2 version:** the plugin is a class-based CLAI2 `Plugin`
|
|
102
123
|
([pydantic/pydantic-ai#9493](https://github.com/pydantic/pydantic-ai/pull/9493)),
|
|
103
124
|
which needs `pydantic-clai2` 0.53.0 or later, on Python 3.10 to 3.14. Run it
|
|
104
125
|
without installing anything:
|
|
@@ -128,11 +149,20 @@ Enter. CLAI2 counts the characters instead of echoing the code. Or open the sett
|
|
|
128
149
|
|
|
129
150
|
### Pick a model
|
|
130
151
|
|
|
131
|
-
`/login claude-code`
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
152
|
+
Signing in, with `/login claude-code` or from the settings menu, asks your
|
|
153
|
+
account which models it can run and adds every one of them to your model list,
|
|
154
|
+
so `/model` offers them right away. That is more than the table above, which
|
|
155
|
+
is only what the plugin knew of when it was released: a subscription listed 15
|
|
156
|
+
in November 2026. If the list cannot be read, the sign-in still stands and the
|
|
157
|
+
message says so.
|
|
158
|
+
|
|
159
|
+
`/model_settings` sets thinking mode, effort, and the rest for each model.
|
|
160
|
+
What you leave unset there follows the defaults under
|
|
161
|
+
[Use it from Python](#use-it-from-python): adaptive thinking, shown
|
|
162
|
+
as a summary, at medium effort. The menu shows those rows as not set.
|
|
163
|
+
|
|
164
|
+
For a model that isn't in your list, open `/add_model` and choose the
|
|
165
|
+
`claude-code` provider, or type one directly:
|
|
136
166
|
|
|
137
167
|
```text
|
|
138
168
|
/add_model claude-code:claude-opus-5-5
|
|
@@ -210,6 +240,23 @@ reads the prefix earlier ones cached instead of writing it again at the 1-hour p
|
|
|
210
240
|
key by key, so to turn caching off for one request, set `anthropic_cache`, `anthropic_cache_instructions` and
|
|
211
241
|
`anthropic_cache_tool_definitions` to `False`.
|
|
212
242
|
|
|
243
|
+
`ClaudeCodeModel` also turns **thinking** on by default, and shows it. Left to the API, a model's reasoning comes
|
|
244
|
+
back hidden, so a turn looks idle until its first word of text. Each request gets whatever of these its settings
|
|
245
|
+
leave open:
|
|
246
|
+
|
|
247
|
+
| Default | Setting | Applies to |
|
|
248
|
+
| --- | --- | --- |
|
|
249
|
+
| Adaptive thinking | `anthropic_thinking={"type": "adaptive"}` | Models that take adaptive thinking |
|
|
250
|
+
| Shown as a summary | `"display": "summarized"` in it | Any thinking that is on |
|
|
251
|
+
| A stale block is dropped, not an error | `"block_binding": {"prefix_mismatch_behavior": "drop_block"}` in it | Adaptive thinking |
|
|
252
|
+
| Medium effort | `anthropic_effort="medium"` | Models that take an effort |
|
|
253
|
+
|
|
254
|
+
Which model takes what comes from its Pydantic AI profile. Opus 4.5, Sonnet 4.5 and Haiku 4.5 do not take adaptive
|
|
255
|
+
thinking, so they think only when you ask them to, and the last two take no effort. The defaults fill gaps one value
|
|
256
|
+
at a time: `anthropic_thinking={"type": "adaptive"}` alone is still shown as a summary, and
|
|
257
|
+
`{"type": "adaptive", "display": "omitted"}` hides it again. `anthropic_thinking={"type": "disabled"}` or
|
|
258
|
+
Pydantic AI's own `thinking=False` turns thinking off, and a level such as `thinking="high"` sets the effort.
|
|
259
|
+
|
|
213
260
|
### Quick start
|
|
214
261
|
|
|
215
262
|
```python
|
|
@@ -340,7 +387,7 @@ uv run pytest
|
|
|
340
387
|
|
|
341
388
|
To release, bump `version` in `pyproject.toml` and `__version__` in
|
|
342
389
|
`src/pydantic_ai_claude_code/__init__.py` (a test checks they match), merge, and
|
|
343
|
-
push a matching tag (`git tag v0.7.
|
|
390
|
+
push a matching tag (`git tag v0.7.7 && git push origin v0.7.7`). The `Publish` workflow tests,
|
|
344
391
|
builds, and uploads it to PyPI with the `PYPI_API_TOKEN` repository secret. Then run
|
|
345
392
|
`scripts/sync_gist.sh` to publish the release to the install gist, which is what the one-liner and the
|
|
346
393
|
update notice install from.
|
|
@@ -32,33 +32,51 @@ so the stock agent, Coder, and your other plugins all keep working.
|
|
|
32
32
|
|
|
33
33
|
### Install
|
|
34
34
|
|
|
35
|
-
One line installs the latest release of the plugin, and running it again updates it
|
|
35
|
+
One line installs the latest release of the plugin, and running it again updates it.
|
|
36
|
+
|
|
37
|
+
**macOS and Linux:**
|
|
36
38
|
|
|
37
39
|
```bash
|
|
38
40
|
curl -fsSL https://gist.githubusercontent.com/mpfaffenberger/bd75c7b424ffdc6d81645bfe7de822d3/raw/install.sh | sh
|
|
39
41
|
```
|
|
40
42
|
|
|
43
|
+
**Windows (PowerShell):**
|
|
44
|
+
|
|
45
|
+
```powershell
|
|
46
|
+
irm https://gist.githubusercontent.com/mpfaffenberger/bd75c7b424ffdc6d81645bfe7de822d3/raw/install.ps1 | iex
|
|
47
|
+
```
|
|
48
|
+
|
|
41
49
|
The plugin is published as a [gist](https://gist.github.com/mpfaffenberger/bd75c7b424ffdc6d81645bfe7de822d3): its files are this repo's
|
|
42
|
-
`src/pydantic_ai_claude_code` folder at the latest release, plus `install.sh`.
|
|
50
|
+
`src/pydantic_ai_claude_code` folder at the latest release, plus `install.sh` and `install.ps1`.
|
|
43
51
|
The script downloads the gist and puts its files in CLAI2's plugins folder as
|
|
44
52
|
`claude_code`, replacing any older copy. To pin a release, pass a gist
|
|
45
|
-
revision (`... | sh -s -- REVISION
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
53
|
+
revision (`... | sh -s -- REVISION` on macOS/Linux, or
|
|
54
|
+
`$env:CLAUDE_CODE_REVISION = 'REVISION'; irm .../install.ps1 | iex` on Windows;
|
|
55
|
+
the gist's revisions are named after releases). Nothing to `pip install`: everything
|
|
56
|
+
the plugin imports (`pydantic-ai` with Anthropic support, `httpx2`, `keyring`)
|
|
57
|
+
already ships with CLAI2.
|
|
58
|
+
|
|
59
|
+
The plugins folder is `$XDG_CONFIG_HOME/pydantic-clai2/plugins/`, which defaults to
|
|
60
|
+
`~/.config/pydantic-clai2/plugins/` on macOS and Linux and
|
|
61
|
+
`%USERPROFILE%\.config\pydantic-clai2\plugins\` on Windows: the folder
|
|
52
62
|
next to CLAI2's `config.db`. To install by hand, clone the gist there yourself
|
|
53
63
|
(`git pull` in that folder then updates it):
|
|
54
64
|
|
|
55
65
|
```bash
|
|
66
|
+
# macOS / Linux
|
|
56
67
|
mkdir -p ~/.config/pydantic-clai2/plugins
|
|
57
68
|
git clone https://gist.github.com/mpfaffenberger/bd75c7b424ffdc6d81645bfe7de822d3.git ~/.config/pydantic-clai2/plugins/claude_code
|
|
58
69
|
```
|
|
59
70
|
|
|
71
|
+
```powershell
|
|
72
|
+
# Windows (PowerShell)
|
|
73
|
+
New-Item -ItemType Directory -Force "$HOME\.config\pydantic-clai2\plugins" | Out-Null
|
|
74
|
+
git clone https://gist.github.com/mpfaffenberger/bd75c7b424ffdc6d81645bfe7de822d3.git "$HOME\.config\pydantic-clai2\plugins\claude_code"
|
|
75
|
+
```
|
|
76
|
+
|
|
60
77
|
To hack on the plugin, symlink the folder instead of copying it:
|
|
61
|
-
`ln -s "$PWD/src/pydantic_ai_claude_code" ~/.config/pydantic-clai2/plugins/claude_code
|
|
78
|
+
`ln -s "$PWD/src/pydantic_ai_claude_code" ~/.config/pydantic-clai2/plugins/claude_code`
|
|
79
|
+
(on Windows PowerShell: `New-Item -ItemType Junction -Path "$HOME\.config\pydantic-clai2\plugins\claude_code" -Target "$PWD\src\pydantic_ai_claude_code"`).
|
|
62
80
|
|
|
63
81
|
Dropped-in plugins load when CLAI2 starts. Inside CLAI2, `/plugins` lists it as
|
|
64
82
|
`claude_code`, where Space turns it off and on. (The shell's `clai2 plugins list`
|
|
@@ -69,7 +87,10 @@ When a newer release is out, it says so once, after your first reply, with the
|
|
|
69
87
|
one-liner to update. Being offline is silent. Set `CLAUDE_CODE_NO_UPDATE_CHECK=1`
|
|
70
88
|
to turn the check off.
|
|
71
89
|
|
|
72
|
-
**
|
|
90
|
+
**Pax:** If you already run `pax`, use the same drop-in install and `/login claude-code`.
|
|
91
|
+
Pax reads the same `pydantic-clai2/plugins` folder. No legacy package is required.
|
|
92
|
+
|
|
93
|
+
**Legacy CLAI2 version:** the plugin is a class-based CLAI2 `Plugin`
|
|
73
94
|
([pydantic/pydantic-ai#9493](https://github.com/pydantic/pydantic-ai/pull/9493)),
|
|
74
95
|
which needs `pydantic-clai2` 0.53.0 or later, on Python 3.10 to 3.14. Run it
|
|
75
96
|
without installing anything:
|
|
@@ -99,11 +120,20 @@ Enter. CLAI2 counts the characters instead of echoing the code. Or open the sett
|
|
|
99
120
|
|
|
100
121
|
### Pick a model
|
|
101
122
|
|
|
102
|
-
`/login claude-code`
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
123
|
+
Signing in, with `/login claude-code` or from the settings menu, asks your
|
|
124
|
+
account which models it can run and adds every one of them to your model list,
|
|
125
|
+
so `/model` offers them right away. That is more than the table above, which
|
|
126
|
+
is only what the plugin knew of when it was released: a subscription listed 15
|
|
127
|
+
in November 2026. If the list cannot be read, the sign-in still stands and the
|
|
128
|
+
message says so.
|
|
129
|
+
|
|
130
|
+
`/model_settings` sets thinking mode, effort, and the rest for each model.
|
|
131
|
+
What you leave unset there follows the defaults under
|
|
132
|
+
[Use it from Python](#use-it-from-python): adaptive thinking, shown
|
|
133
|
+
as a summary, at medium effort. The menu shows those rows as not set.
|
|
134
|
+
|
|
135
|
+
For a model that isn't in your list, open `/add_model` and choose the
|
|
136
|
+
`claude-code` provider, or type one directly:
|
|
107
137
|
|
|
108
138
|
```text
|
|
109
139
|
/add_model claude-code:claude-opus-5-5
|
|
@@ -181,6 +211,23 @@ reads the prefix earlier ones cached instead of writing it again at the 1-hour p
|
|
|
181
211
|
key by key, so to turn caching off for one request, set `anthropic_cache`, `anthropic_cache_instructions` and
|
|
182
212
|
`anthropic_cache_tool_definitions` to `False`.
|
|
183
213
|
|
|
214
|
+
`ClaudeCodeModel` also turns **thinking** on by default, and shows it. Left to the API, a model's reasoning comes
|
|
215
|
+
back hidden, so a turn looks idle until its first word of text. Each request gets whatever of these its settings
|
|
216
|
+
leave open:
|
|
217
|
+
|
|
218
|
+
| Default | Setting | Applies to |
|
|
219
|
+
| --- | --- | --- |
|
|
220
|
+
| Adaptive thinking | `anthropic_thinking={"type": "adaptive"}` | Models that take adaptive thinking |
|
|
221
|
+
| Shown as a summary | `"display": "summarized"` in it | Any thinking that is on |
|
|
222
|
+
| A stale block is dropped, not an error | `"block_binding": {"prefix_mismatch_behavior": "drop_block"}` in it | Adaptive thinking |
|
|
223
|
+
| Medium effort | `anthropic_effort="medium"` | Models that take an effort |
|
|
224
|
+
|
|
225
|
+
Which model takes what comes from its Pydantic AI profile. Opus 4.5, Sonnet 4.5 and Haiku 4.5 do not take adaptive
|
|
226
|
+
thinking, so they think only when you ask them to, and the last two take no effort. The defaults fill gaps one value
|
|
227
|
+
at a time: `anthropic_thinking={"type": "adaptive"}` alone is still shown as a summary, and
|
|
228
|
+
`{"type": "adaptive", "display": "omitted"}` hides it again. `anthropic_thinking={"type": "disabled"}` or
|
|
229
|
+
Pydantic AI's own `thinking=False` turns thinking off, and a level such as `thinking="high"` sets the effort.
|
|
230
|
+
|
|
184
231
|
### Quick start
|
|
185
232
|
|
|
186
233
|
```python
|
|
@@ -311,7 +358,7 @@ uv run pytest
|
|
|
311
358
|
|
|
312
359
|
To release, bump `version` in `pyproject.toml` and `__version__` in
|
|
313
360
|
`src/pydantic_ai_claude_code/__init__.py` (a test checks they match), merge, and
|
|
314
|
-
push a matching tag (`git tag v0.7.
|
|
361
|
+
push a matching tag (`git tag v0.7.7 && git push origin v0.7.7`). The `Publish` workflow tests,
|
|
315
362
|
builds, and uploads it to PyPI with the `PYPI_API_TOKEN` repository secret. Then run
|
|
316
363
|
`scripts/sync_gist.sh` to publish the release to the install gist, which is what the one-liner and the
|
|
317
364
|
update notice install from.
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Install or update the Claude Code plugin for CLAI2 from its gist, which holds the latest release
|
|
2
|
+
# (set $env:CLAUDE_CODE_REVISION to pin a gist revision, or pass -Revision when running the file):
|
|
3
|
+
# irm https://gist.githubusercontent.com/mpfaffenberger/bd75c7b424ffdc6d81645bfe7de822d3/raw/install.ps1 | iex
|
|
4
|
+
param(
|
|
5
|
+
[string]$Revision = $(if ($env:CLAUDE_CODE_REVISION) { $env:CLAUDE_CODE_REVISION } else { 'HEAD' })
|
|
6
|
+
)
|
|
7
|
+
|
|
8
|
+
$ErrorActionPreference = 'Stop'
|
|
9
|
+
|
|
10
|
+
$gist = 'bd75c7b424ffdc6d81645bfe7de822d3'
|
|
11
|
+
$configHome = if ($env:XDG_CONFIG_HOME) { $env:XDG_CONFIG_HOME } else { Join-Path $HOME '.config' }
|
|
12
|
+
$plugins = Join-Path $configHome 'pydantic-clai2\plugins'
|
|
13
|
+
$target = Join-Path $plugins 'claude_code'
|
|
14
|
+
$url = "https://gist.github.com/mpfaffenberger/$gist/archive/$Revision.zip"
|
|
15
|
+
|
|
16
|
+
$download = Join-Path ([System.IO.Path]::GetTempPath()) ("claude-code-" + [System.Guid]::NewGuid().ToString('N'))
|
|
17
|
+
$archive = Join-Path $download 'gist.zip'
|
|
18
|
+
$extract = Join-Path $download 'extract'
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
New-Item -ItemType Directory -Path $extract -Force | Out-Null
|
|
22
|
+
Invoke-WebRequest -UseBasicParsing -Uri $url -OutFile $archive
|
|
23
|
+
Expand-Archive -Path $archive -DestinationPath $extract -Force
|
|
24
|
+
|
|
25
|
+
$folder = (Get-ChildItem -Path $extract -Directory | Select-Object -First 1).FullName
|
|
26
|
+
Remove-Item -Path (Join-Path $folder 'install.sh'), (Join-Path $folder 'install.ps1') -ErrorAction SilentlyContinue
|
|
27
|
+
|
|
28
|
+
New-Item -ItemType Directory -Path $plugins -Force | Out-Null
|
|
29
|
+
if (Test-Path $target) {
|
|
30
|
+
Remove-Item -Path $target -Recurse -Force
|
|
31
|
+
}
|
|
32
|
+
Move-Item -Path $folder -Destination $target
|
|
33
|
+
|
|
34
|
+
$init = Get-Content -Path (Join-Path $target '__init__.py') -Raw
|
|
35
|
+
$version = if ($init -match '(?m)^__version__ = "([^"]*)"') { $Matches[1] } else { 'unknown' }
|
|
36
|
+
Write-Output "Installed the Claude Code plugin (v$version) to $target."
|
|
37
|
+
Write-Output "Start clai2, sign in with /login claude-code, then /model claude-code:claude-opus-5-5."
|
|
38
|
+
} finally {
|
|
39
|
+
if (Test-Path $download) {
|
|
40
|
+
Remove-Item -Path $download -Recurse -Force -ErrorAction SilentlyContinue
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -14,11 +14,11 @@ trap 'rm -rf "$download"' EXIT
|
|
|
14
14
|
|
|
15
15
|
curl -fsSL "https://gist.github.com/mpfaffenberger/$gist/archive/$revision.tar.gz" | tar -xz -C "$download"
|
|
16
16
|
folder=$(echo "$download"/*)
|
|
17
|
-
rm -f "$folder/install.sh"
|
|
17
|
+
rm -f "$folder/install.sh" "$folder/install.ps1"
|
|
18
18
|
mkdir -p "$plugins"
|
|
19
19
|
rm -rf "$target"
|
|
20
20
|
mv "$folder" "$target"
|
|
21
21
|
|
|
22
22
|
version=$(grep -o '^__version__ = "[^"]*"' "$target/__init__.py" | cut -d '"' -f 2)
|
|
23
23
|
echo "Installed the Claude Code plugin (v$version) to $target."
|
|
24
|
-
echo "Start clai2, sign in with /login claude-code, then /model claude-code:claude-opus-5-5."
|
|
24
|
+
echo "Start pax (or clai2), sign in with /login claude-code, then /model claude-code:claude-opus-5-5."
|
|
@@ -4,13 +4,15 @@ build-backend = "hatchling.build"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "pydantic-claude-code"
|
|
7
|
-
version = "0.7.
|
|
7
|
+
version = "0.7.7"
|
|
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"
|
|
11
11
|
dependencies = [
|
|
12
12
|
"keyring>=23,<26",
|
|
13
|
-
|
|
13
|
+
# 2.38.0 is the first release to send the beta that `thinking.block_binding` needs, and `ClaudeCodeModel`
|
|
14
|
+
# sets that field by default on every model with adaptive thinking.
|
|
15
|
+
"pydantic-ai-slim[anthropic]>=2.38.0,<3",
|
|
14
16
|
]
|
|
15
17
|
license = { text = "MIT" }
|
|
16
18
|
authors = [{ name = "Michael Pfaffenberger" }]
|
|
@@ -13,7 +13,7 @@ trap 'rm -rf "$clone"' EXIT
|
|
|
13
13
|
gh auth setup-git
|
|
14
14
|
git clone -q "https://gist.github.com/$gist.git" "$clone"
|
|
15
15
|
git -C "$clone" rm -q --ignore-unmatch '*'
|
|
16
|
-
cp "$root"/src/pydantic_ai_claude_code/*.py "$root/install.sh" "$clone/"
|
|
16
|
+
cp "$root"/src/pydantic_ai_claude_code/*.py "$root/install.sh" "$root/install.ps1" "$clone/"
|
|
17
17
|
git -C "$clone" add -A
|
|
18
18
|
version=$(grep -o '^__version__ = "[^"]*"' "$root/src/pydantic_ai_claude_code/__init__.py" | cut -d '"' -f 2)
|
|
19
19
|
if git -C "$clone" diff --cached --quiet; then
|
{pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/src/pydantic_ai_claude_code/__init__.py
RENAMED
|
@@ -26,14 +26,14 @@ 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.
|
|
29
|
+
__version__ = "0.7.7"
|
|
30
30
|
"""Matches `version` in pyproject.toml (a test checks), so a copied folder knows its release."""
|
|
31
31
|
|
|
32
32
|
|
|
33
33
|
try:
|
|
34
34
|
from .clai2 import ClaudeCodePlugin as _ClaudeCodePlugin
|
|
35
35
|
except ModuleNotFoundError as error: # plain Pydantic AI use: CLAI2 is not installed, and needs no plugin
|
|
36
|
-
if
|
|
36
|
+
if error.name != "pydantic_clai2":
|
|
37
37
|
raise
|
|
38
38
|
else:
|
|
39
39
|
|
{pydantic_claude_code-0.7.5 → pydantic_claude_code-0.7.7}/src/pydantic_ai_claude_code/clai2.py
RENAMED
|
@@ -23,16 +23,39 @@ import importlib
|
|
|
23
23
|
import sys
|
|
24
24
|
from collections.abc import Awaitable, Callable, Sequence
|
|
25
25
|
from datetime import datetime
|
|
26
|
-
from typing import IO, Any, cast, get_args
|
|
26
|
+
from typing import TYPE_CHECKING, IO, Any, cast, get_args
|
|
27
27
|
|
|
28
|
-
from anthropic import APIError
|
|
28
|
+
from anthropic import APIError, AsyncAnthropic
|
|
29
29
|
from pydantic import BaseModel, ConfigDict, Field, ValidationError
|
|
30
30
|
from pydantic_ai.exceptions import UserError
|
|
31
|
-
|
|
31
|
+
|
|
32
|
+
try:
|
|
33
|
+
_host = importlib.import_module("pydantic_ai_pax")
|
|
34
|
+
except ModuleNotFoundError as error:
|
|
35
|
+
if error.name != "pydantic_ai_pax":
|
|
36
|
+
raise
|
|
37
|
+
_host = importlib.import_module("pydantic_clai2")
|
|
38
|
+
|
|
39
|
+
if not TYPE_CHECKING and _host.__name__ == "pydantic_ai_pax":
|
|
40
|
+
from pydantic_ai_pax.commands import Command
|
|
41
|
+
from pydantic_ai_pax.plugins import (
|
|
42
|
+
ModelProvider,
|
|
43
|
+
Plugin,
|
|
44
|
+
PluginHost,
|
|
45
|
+
PluginLogin,
|
|
46
|
+
SessionEnd,
|
|
47
|
+
SessionStart,
|
|
48
|
+
TurnEnd,
|
|
49
|
+
)
|
|
50
|
+
from pydantic_ai_pax.ui.menus.menu_worker import menu_key, run_worker
|
|
51
|
+
from pydantic_ai_pax.ui.menus.field_menu import TERMINAL, FieldMenu, FieldRow, Runners, first_error, run_flow_async
|
|
52
|
+
else:
|
|
53
|
+
from pydantic_clai2.commands import Command
|
|
54
|
+
from pydantic_clai2.plugins import ModelProvider, Plugin, PluginHost, PluginLogin, SessionEnd, SessionStart, TurnEnd
|
|
55
|
+
from pydantic_clai2.ui.menus.menu_worker import menu_key, run_worker
|
|
56
|
+
from pydantic_clai2.ui.menus.field_menu import TERMINAL, FieldMenu, FieldRow, Runners, first_error, run_flow_async
|
|
57
|
+
|
|
32
58
|
from termflow.tui.terminal import raw_mode
|
|
33
|
-
from pydantic_clai2.plugins import ModelProvider, Plugin, PluginHost, PluginLogin, SessionEnd, SessionStart, TurnEnd
|
|
34
|
-
from pydantic_clai2.ui.menus.menu_worker import menu_key, run_worker
|
|
35
|
-
from pydantic_clai2.ui.menus.field_menu import TERMINAL, FieldMenu, FieldRow, Runners, first_error, run_flow_async
|
|
36
59
|
|
|
37
60
|
from . import __version__, config, updates
|
|
38
61
|
from .flow import login, parse_pasteback
|
|
@@ -66,6 +89,16 @@ def _account(profile: str | None) -> str:
|
|
|
66
89
|
return "Claude Code" if profile is None else f"Claude Code profile {profile}"
|
|
67
90
|
|
|
68
91
|
|
|
92
|
+
def _model(name: str, profile: str | None) -> str:
|
|
93
|
+
"""A model as `/model` takes it: `claude-code:NAME`, or `claude-code@PROFILE:NAME`."""
|
|
94
|
+
return f"{PREFIX}:{name}" if profile is None else f"{PREFIX}@{profile}:{name}"
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def _pick_by_name(profile: str | None) -> str:
|
|
98
|
+
"""How to choose a model that `/model` does not list yet, for a message to end on after `Run` or `run`."""
|
|
99
|
+
return f"/model {_model(config.MODELS[0], profile)}, or any other model."
|
|
100
|
+
|
|
101
|
+
|
|
69
102
|
def _supported(cls: type, **optional: Any) -> dict[str, Any]:
|
|
70
103
|
"""The keyword arguments `cls` accepts: CLAI2 builds without auth profiles lack those fields."""
|
|
71
104
|
names = {field.name for field in dataclasses.fields(cls)}
|
|
@@ -201,14 +234,22 @@ class _UsageWindow(BaseModel):
|
|
|
201
234
|
|
|
202
235
|
def _usage_types() -> tuple[Any, Any]:
|
|
203
236
|
"""CLAI2's `AccountUsage` and `UsageWindow`; only builds that offer `PluginLogin.usage` ask for usage."""
|
|
204
|
-
plugins = importlib.import_module("
|
|
237
|
+
plugins = importlib.import_module(".plugins", _host.__name__)
|
|
205
238
|
return plugins.AccountUsage, plugins.UsageWindow
|
|
206
239
|
|
|
207
240
|
|
|
241
|
+
def _once(provider: ClaudeCodeProvider) -> AsyncAnthropic:
|
|
242
|
+
"""The provider's client for one quick question about the account: ten seconds, and no retries.
|
|
243
|
+
|
|
244
|
+
`AnthropicProvider` types its client as any of the SDK's; this provider only ever builds this one.
|
|
245
|
+
"""
|
|
246
|
+
return cast(AsyncAnthropic, provider.client).with_options(max_retries=0, timeout=10)
|
|
247
|
+
|
|
248
|
+
|
|
208
249
|
async def account_usage(provider: ClaudeCodeProvider) -> Any:
|
|
209
250
|
"""The subscription's five-hour and weekly windows, as CLAI2's `AccountUsage`."""
|
|
210
251
|
try:
|
|
211
|
-
body = await provider
|
|
252
|
+
body = await _once(provider).get(USAGE_PATH, cast_to=object)
|
|
212
253
|
except APIError as exc:
|
|
213
254
|
raise UserError(f"Claude Code usage unavailable: {exc.message}") from None
|
|
214
255
|
if not isinstance(body, dict):
|
|
@@ -238,20 +279,51 @@ ReadPasteback = Callable[[], Awaitable[str | None]]
|
|
|
238
279
|
"""Reads the address the browser ended on; `None` when the user cancels."""
|
|
239
280
|
|
|
240
281
|
|
|
282
|
+
async def account_models(provider: ClaudeCodeProvider) -> tuple[str, ...]:
|
|
283
|
+
"""Every model the signed-in account can run, as the Models API lists them: newest first."""
|
|
284
|
+
try:
|
|
285
|
+
return tuple([model.id async for model in _once(provider).models.list(limit=1000)])
|
|
286
|
+
except APIError as exc:
|
|
287
|
+
raise UserError(f"Claude Code's model list is unavailable: {exc.message}") from None
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def save_models(host: PluginHost[Any], names: Sequence[str]) -> None:
|
|
291
|
+
"""Add `names` to the saved model list that `/model` offers.
|
|
292
|
+
|
|
293
|
+
CLAI2 saves a `PluginLogin`'s own `models` after a sign-in, but those are fixed when the plugin loads,
|
|
294
|
+
before anyone has signed in, so they cannot be what the account lists. This adds to the same list.
|
|
295
|
+
A host without `settings_database` keeps its settings at the default path.
|
|
296
|
+
"""
|
|
297
|
+
settings_store = importlib.import_module(".config.settings_store", _host.__name__)
|
|
298
|
+
store = settings_store.SettingsStore(getattr(host, "settings_database", None))
|
|
299
|
+
for name in names:
|
|
300
|
+
store.add_model(name=name)
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
AddModels = Callable[[str | None], Awaitable[str]]
|
|
304
|
+
"""Adds the models a profile's account lists to `/model` and says what it did; `None` is the default account."""
|
|
305
|
+
|
|
306
|
+
|
|
241
307
|
async def sign_in(
|
|
242
308
|
source: ClaudeCodeConfig,
|
|
243
309
|
show_url: Callable[[str], None],
|
|
244
310
|
profile: str | None = None,
|
|
245
311
|
*,
|
|
246
312
|
read_pasteback: ReadPasteback,
|
|
313
|
+
add_models: AddModels | None = None,
|
|
247
314
|
) -> str:
|
|
248
|
-
"""Sign in through the browser, or a pasted redirect address, and save the tokens to the chosen store.
|
|
315
|
+
"""Sign in through the browser, or a pasted redirect address, and save the tokens to the chosen store.
|
|
316
|
+
|
|
317
|
+
With `add_models`, the account's models are then added to `/model`, and its report ends the message.
|
|
318
|
+
"""
|
|
249
319
|
store = source.store(profile)
|
|
250
320
|
await login(store=store, on_url=show_url, read_pasteback=read_pasteback)
|
|
251
|
-
|
|
321
|
+
if add_models is not None:
|
|
322
|
+
return f"Signed in to {_account(profile)}. {await add_models(profile)}"
|
|
252
323
|
if profile is not None:
|
|
253
|
-
return f"Signed in to {_account(profile)}. Run
|
|
254
|
-
|
|
324
|
+
return f"Signed in to {_account(profile)}. Run {_pick_by_name(profile)}"
|
|
325
|
+
first = _model(config.MODELS[0], None)
|
|
326
|
+
return f"Signed in to Claude Code. Choose a model in /add_model > {PREFIX}, or run /model {first}."
|
|
255
327
|
|
|
256
328
|
|
|
257
329
|
PASTE_PROMPT = "Or paste the address your browser ended on, then Enter (Esc cancels): "
|
|
@@ -267,7 +339,7 @@ def paste_reader(host: PluginHost[Any]) -> ReadPasteback:
|
|
|
267
339
|
`read_pasted_url` draws under the URL.
|
|
268
340
|
"""
|
|
269
341
|
try:
|
|
270
|
-
line_input = importlib.import_module("
|
|
342
|
+
line_input = importlib.import_module(".ui.prompt.line_input", _host.__name__)
|
|
271
343
|
except ImportError:
|
|
272
344
|
return lambda: run_worker(read_pasted_url)
|
|
273
345
|
|
|
@@ -336,12 +408,13 @@ async def configure(
|
|
|
336
408
|
runners: Runners = TERMINAL,
|
|
337
409
|
*,
|
|
338
410
|
read_pasteback: ReadPasteback,
|
|
411
|
+
add_models: AddModels | None = None,
|
|
339
412
|
) -> str:
|
|
340
413
|
"""Open the settings menu until Esc or Save & close."""
|
|
341
414
|
|
|
342
415
|
async def account() -> list[str]:
|
|
343
416
|
try:
|
|
344
|
-
return [await sign_in(source, show_url, read_pasteback=read_pasteback)]
|
|
417
|
+
return [await sign_in(source, show_url, read_pasteback=read_pasteback, add_models=add_models)]
|
|
345
418
|
except UserError as exc:
|
|
346
419
|
return [str(exc)]
|
|
347
420
|
|
|
@@ -399,10 +472,24 @@ class ClaudeCodePlugin(Plugin[ClaudeCodeSettings]):
|
|
|
399
472
|
return await account_usage(provider)
|
|
400
473
|
|
|
401
474
|
async def _sign_in(self) -> str:
|
|
402
|
-
return await
|
|
475
|
+
return await self._sign_in_profile(None)
|
|
476
|
+
|
|
477
|
+
async def _sign_in_profile(self, profile: str | None) -> str:
|
|
478
|
+
return await sign_in(
|
|
479
|
+
self.source, self._show_url, profile, read_pasteback=self._read_pasteback, add_models=self._add_models
|
|
480
|
+
)
|
|
403
481
|
|
|
404
|
-
async def
|
|
405
|
-
|
|
482
|
+
async def _add_models(self, profile: str | None) -> str:
|
|
483
|
+
"""Add every model the account lists to `/model`. A failure is reported, not raised: the sign-in stands."""
|
|
484
|
+
try:
|
|
485
|
+
provider = await asyncio.to_thread(self._providers.provider, self.source, profile)
|
|
486
|
+
names = [_model(name, profile) for name in await account_models(provider)]
|
|
487
|
+
if not names:
|
|
488
|
+
raise UserError("it lists none")
|
|
489
|
+
await asyncio.to_thread(save_models, self.host, names)
|
|
490
|
+
except Exception as exc: # Whatever stops the listing, signing in itself worked.
|
|
491
|
+
return f"Its models could not be listed ({exc}); run {_pick_by_name(profile)}"
|
|
492
|
+
return f"Added the {len(names)} model{'s' if len(names) != 1 else ''} it lists; choose one with /model."
|
|
406
493
|
|
|
407
494
|
def get_commands(self) -> Sequence[Command]:
|
|
408
495
|
return (
|
|
@@ -428,7 +515,9 @@ class ClaudeCodePlugin(Plugin[ClaudeCodeSettings]):
|
|
|
428
515
|
return await asyncio.to_thread(action, self.source, args[1] if len(args) == 2 else None)
|
|
429
516
|
|
|
430
517
|
async def configure(self) -> str:
|
|
431
|
-
return await configure(
|
|
518
|
+
return await configure(
|
|
519
|
+
self.source, self._show_url, read_pasteback=self._read_pasteback, add_models=self._add_models
|
|
520
|
+
)
|
|
432
521
|
|
|
433
522
|
async def on_session_start(self, event: SessionStart) -> None:
|
|
434
523
|
"""Check PyPI for a newer release in the background, so startup never waits on it."""
|