TrueNix/dsh-anthropic-oauth ↗★ 1

dsh-anthropic-oauth

将Claude Code OAuth会话无缝接入DSH并同步Token。 适合已拥有Claude Code授权,想在DSH中直接使用其凭据和模型的用户。

包名
dsh-anthropic-oauth
兼容性
待验证
版本
0.3.1
许可证
NOASSERTION
最近更新
2026年9月9日

安装

$npx -p @deepseek-ai/dsh dsh plugin --profile web add github:TrueNix/dsh-anthropic-oauth

dsh-anthropic-oauth

Bridge your existing Claude Code OAuth session (Pro / Max / Team) into DeepSeek Harness (DSH) — with zero hardcoding.

  • Reads ~/.claude/.credentials.json claudeAiOauth live (same file Claude Code writes)

  • Auto-refreshes accessToken via https://platform.claude.com/v1/oauth/token when dsh-anthropic-oauth Host plugin claudeAiOauth {accessToken, refreshToken, expiresAt} │ refreshIfNeeded() if expiry <5m POST https://platform.claude.com/v1/oauth/token {grant_type: refresh_token, client_id: 9d1c25…f5e} │ ├─► ~/.claude/.credentials.json (updated expiry) └─► ~/.dsh/.credentials.yaml ANTHROPIC_OAUTH_TOKEN: sk-ant-oat01-… CLAUDE_CODE_OAUTH_TOKEN: sk-ant-oat01-…

                                        └─► GET /v1/models  (live catalog)
                                             → llm-pi-ai.providers.anthropic.models
                                               [{id, name, contextWindow, maxTokens,
                                                 reasoning, effortLevels}, …]
    

~/.dsh/settings.yaml llm-pi-ai.providers.anthropic {apiKeyEnv: ANTHROPIC_OAUTH_TOKEN} │ └─► pi-ai anthropicMessagesApi — Authorization: Bearer sk-ant-oat01-… anthropic-beta: oauth-2025-04-20,claude-code-20250219,…


The model catalog is refreshed from `GET /v1/models` (≤6h TTL, or on demand via
`POST /api/anthropic-oauth/sync`); if discovery fails the provider keeps a minimal
Sonnet-4.5 seed so it still resolves offline. Quota is probed from
`POST /v1/messages` (`max_tokens:1`, Haiku — fractions of a cent, 60s TTL)
and exposed at `/api/anthropic-oauth/quota`.

## Set as default model

```yaml
# ~/.dsh/settings.yaml
agent-default-model:
  provider: anthropic
  model: claude-sonnet-4-5

Or pick per-session in Settings → Models after a reload.

Logs & manual sync

# DSH console (bridge + quota probe):
# [anthropic-oauth] pulled N models from /v1/models
# [anthropic-oauth] refreshed, new expiry …

# Force-refresh the model catalog (also syncs quota):
curl -X POST http://127.0.0.1:3080/api/anthropic-oauth/sync

# Live quota (60s TTL; ?force=1 bypasses cache):
curl http://127.0.0.1:3080/api/anthropic-oauth/quota
curl "http://127.0.0.1:3080/api/anthropic-oauth/quota?force=1"

Troubleshooting

  • MISSING_CREDENTIAL llm-pi-ai: no credential for provider route "anthropic" — bridge hasn't synced yet; re-login with claude login.
  • 401 from Anthropic — token expired and refresh failed; claude login again.
  • Quota ok:false with a refresh error — subscription may have changed; re-login, then check /api/anthropic-oauth/quota?force=1.

Refresh and re-login safety

Refreshes are single-flight per plugin and serialized between DSH processes. Missing fields and rejected refresh tokens do not trigger an endless HTTP retry loop. A still-valid access token remains usable while the status endpoint reports that a fresh Claude login is needed. New credentials clear that pause.

The bridge watches the credential directory so atomic replacements from Claude login are detected. It honors CLAUDE_CONFIG_DIR, validates refresh responses, and uses atomic owner-only writes. If the source file changes during an HTTP refresh, the newer credentials are kept instead of overwritten. Claude Code does not share the plugin lock; avoid logging in during an in-flight refresh when possible.

The bridge never repairs or directly writes DSH's credential YAML. An unknown top-level key error is a separate malformed-store problem, not an OAuth grant error.

Security

  • Never commits tokens — .gitignore excludes *.oat*, *.credentials.*.
  • Tokens live only in 0600 files owned by you: ~/.claude/.credentials.json and ~/.dsh/.credentials.yaml.
  • A Feb-2026 Anthropic docs note declares Pro/Max OAuth for official clients only — personal use at your own risk; use a console ANTHROPIC_API_KEY for production.

License

MIT