@djdowbnac/dsh-claude-auth 0.1.0

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.
package/README.md ADDED
@@ -0,0 +1,82 @@
1
+ # @djdowbnac/dsh-claude-auth
2
+
3
+ dsh model provider that streams Claude through your Claude Code subscription. No Anthropic API key.
4
+
5
+ Registers a `claude-subscription` provider on `ctx.llm`. On the first request the plugin queries `GET /v1/models` with your OAuth token and serves every model your account can use, with its real context window and output cap. The catalog updates itself when Anthropic ships or retires models, so there is no static model list to maintain.
6
+
7
+ Requests go to `api.anthropic.com/v1/messages` with the Claude Code first-party headers. Credentials come from `~/.claude/.credentials.json`, the same file the `claude` CLI writes.
8
+
9
+ > Anthropic reserves subscription tokens for official clients. This is a community workaround, same class as `opencode-claude-auth`. It draws from your plan limits, not API billing, and may stop working when Anthropic changes its OAuth surface.
10
+
11
+ ## How refresh works
12
+
13
+ The plugin keeps an access token in memory for 30 seconds and only calls the token endpoint when the token is within 60 seconds of expiry, or once per hour as a background pre-refresh. A cross-process lock serializes concurrent instances: the loser waits up to 15 seconds and adopts the winner's token instead of refreshing again. Anthropic rotates refresh tokens on single use, so double refreshes were what broke tokens before.
14
+
15
+ ## Install
16
+
17
+ Prerequisites: dsh on the `0.1.5-rc` line, bun, and a one-time `claude` login.
18
+
19
+ ```sh
20
+ dsh plugin --profile <name> add @djdowbnac/dsh-claude-auth
21
+ ```
22
+
23
+ That is the whole install. The command registers the package in the profile's `dsh.profile.bundles`, and dsh mounts the plugin's `cordis.patch.yml` as an automatic bundle layer on every boot. No manual patch entry, no profile edits.
24
+
25
+ For a local checkout, `add .` from inside the checkout directory. Restart dsh and pick a `claude-subscription` model.
26
+
27
+ ## Settings
28
+
29
+ Namespace `claude-auth`:
30
+
31
+ | Key | Default | Meaning |
32
+ |---|---|---|
33
+ | `credentialsPath` | `''` (→ `~/.claude/.credentials.json`) | Override the credentials file path. |
34
+ | `disabledModels` | `[]` | Model ids to stop serving. |
35
+ | `streamIdleTimeoutMs` | `600000` | Abort the stream when SSE goes quiet this long. |
36
+ | `requestTimeoutMs` | `900000` | Per-request budget. |
37
+
38
+ Changes apply on the next request. A missing or invalid credentials file shows as a diagnostic on the provider entry, and requests fail with a typed error.
39
+
40
+ ## Web settings
41
+
42
+ The Models page in the dsh web UI shows a green credential dot next to the provider when your Claude subscription credentials are valid. The plugin mirrors the current access token into the dsh credential store under the `CLAUDE_SUBSCRIPTION_API_KEY` reference, which is the same reference the page checks. When the token expires or the credentials file disappears, the dot goes away and the provider row shows a diagnostic.
43
+
44
+ The provider editor card is read-only by design in the dsh web UI. The page renders curated field layouts only for the two first-party provider namespaces (`llm-deepseek`, `llm-pi-ai`); every other namespace falls back to the "edit settings.yaml directly" hint. To change `streamIdleTimeoutMs` or `disabledModels`, edit the `claude-auth` section in `~/.dsh/settings.yaml`.
45
+
46
+ Reasoning effort is not a provider setting. Pick it in the model selection popup: the effort selector appears for every model that supports adaptive thinking (all current Opus, Sonnet, Fable, and Haiku 4.5+ models). The chosen effort is sent as `output_config.effort` on the wire request.
47
+
48
+ ## Develop
49
+
50
+ ```sh
51
+ bun test # 72 tests, all offline
52
+ bun run build
53
+ bun run smoke # one live request, costs a few tokens
54
+ ```
55
+
56
+ | File | What it does |
57
+ |---|---|
58
+ | `src/index.ts` | Plugin entry: config schema, provider registration, settings, disposal. |
59
+ | `src/adapter.ts` | `LlmAdapter`: headers, fetch, SSE consumption, error mapping, model discovery. |
60
+ | `src/serialize.ts` | Harness `Message[]` to Anthropic wire request. |
61
+ | `src/translate.ts` | Anthropic SSE to harness `StreamChunk`s. |
62
+ | `src/sse.ts` | SSE framing parser. |
63
+ | `src/auth.ts` | Credential read, refresh, write-back, backoff, cross-process lock. |
64
+ | `src/model-config.ts` | Beta headers, effort support, catalog fallback. |
65
+
66
+ Unit tests inject `fetchImpl`, so they run offline. The smoke script is the only live path.
67
+
68
+ ## Limitations
69
+
70
+ - Text only. Image and file content blocks return `UNSUPPORTED_CONTENT`.
71
+ - One credentials file per provider route. Multi-account is not wired.
72
+ - If the models endpoint is unreachable, the plugin falls back to a static catalog of the current Claude 5 lineup.
73
+
74
+ ## References
75
+
76
+ - [deepseek-ai/deepseek-harness](https://github.com/deepseek-ai/deepseek-harness): `dsh-llm` adapter contract, `dsh-settings`, `dsh-timeout`.
77
+ - [griffinmartin/opencode-claude-auth](https://github.com/griffinmartin/opencode-claude-auth): upstream reference for the OAuth surface and refresh strategy.
78
+ - [Claude model docs](https://platform.claude.com/docs/en/models/overview): current lineup and model ids.
79
+
80
+ ## License
81
+
82
+ MIT
@@ -0,0 +1,6 @@
1
+ - insert:
2
+ - id: claude-auth
3
+ name: '@djdowbnac/dsh-claude-auth'
4
+ config:
5
+ # credentialsPath: ''
6
+ # disabledModels: [claude-opus-4-1]