feat(cli): Claude Code 구독 OAuth 지원 (--use-claude-code-auth)#50
Merged
Conversation
… OAuth Mirrors the existing --use-codex-auth path: reads OAuth tokens from the macOS keychain entry "Claude Code-credentials" or ~/.claude/.credentials.json, auto-refreshes near-expiry tokens against console.anthropic.com, and routes chat through @ai-sdk/anthropic with the OAuth-required anthropic-beta header, ?beta=true on /v1/messages, and the Claude Code identity system-prompt prefix that Anthropic rejects requests without. Adds the --use-claude-auth alias and OPENCLONE_USE_CLAUDE_CODE_AUTH / OPENCLONE_USE_CLAUDE_AUTH env switches. Tokens never leave their original storage; refreshed values are written back in place. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… betas, two-block system Anthropic returns a generic 429 rate_limit_error (with response headers showing utilization < 1.0) when the OAuth request shape doesn't look like Claude Code itself, even on accounts nowhere near their cap. Three things were leaking the AI SDK's identity through: - @ai-sdk/anthropic preset User-Agent to ai-sdk/anthropic/<ver>; the conditional override never fired. Force it to claude-cli/2.1.87 (external, cli). - The SDK appended structured-outputs-2025-11-13 to anthropic-beta on top of our two OAuth betas. OAuth tokens reject any beta beyond oauth-2025-04-20 / interleaved-thinking-2025-05-14. Replace the header outright instead of merging. - The system prompt was sent as a single content block with the Claude Code identity and the persona joined by \n\n. Anthropic's OAuth path validates that the first system block is exactly the identity. Split into two text blocks at the fetch-wrapper layer. Also strips x-stainless-* fingerprint headers and adds OPENCLONE_DEBUG_HTTP=1 debug logging so future rate_limit_error 429s can be diagnosed without guessing. Verified live: `node dist/cli/index.js chat douglas --use-claude-code-auth --prompt "1+1?"` now returns 200 with utilization headers showing 5h=0.34, 7d=0.22. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Collaborator
|
Thanks for the contribution! 🙏 This repository's automation only reviews pull requests that target the GitHub UI → click "Edit" next to the PR title → change the base branch to |
# Conflicts: # CLAUDE.md
npm install regenerated the lockfile to reflect the dual MIT/CC-BY-NC-SA-4.0 license string introduced on main in #49. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
4entrepreneur
added a commit
that referenced
this pull request
May 5, 2026
Catches up #50 (Claude Code OAuth) so the citation-fix branch is again up to date with main.
This was referenced May 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
변경 요약
openclone chat <slug> --use-claude-code-auth한 줄로 Claude Pro/Max 구독자가 별도 Anthropic API 키 없이 standalone CLI 를 쓸 수 있게 했습니다. macOS 키체인 항목Claude Code-credentials또는~/.claude/.credentials.json의 OAuth 토큰을 그대로 재사용하고, 만료 임박 시console.anthropic.com으로 자동 갱신해 같은 위치에 다시 씁니다. 별도 OAuth wrapper 패키지 없이@ai-sdk/anthropic의authToken/headers/fetchfirst-class 옵션 위에 얇은 셰임만 추가했습니다.--use-claude-authalias 와OPENCLONE_USE_CLAUDE_CODE_AUTH=1env 도 함께 지원.핵심 invariant: 커스텀 fetch 가
User-Agent를claude-cli/2.1.87 (external, cli)로 강제 덮어쓰고,anthropic-beta를oauth-2025-04-20,interleaved-thinking-2025-05-14로 완전 교체하며 (SDK 가 자동 추가하는structured-outputs-*등은 strip),system을 두 블록[{identity}, {persona}]로 분리하고,/v1/messages에?beta=true를 붙입니다 — 이 네 가지 중 하나라도 빠지면 Anthropic 이 generic429 rate_limit_error로 차단합니다 (계정 cap 무관).변경 유형
references/*.md) —skills/openclone-cli/references/claude-code-oauth.mdREADME.md,CLAUDE.md,skills/openclone-cli/SKILL.mdsrc/cli/,src/lib/)테스트 방법
라이브 검증: 200 응답 + 페르소나 voice 유지된 답변 (
파랑.). 응답 헤더에서anthropic-ratelimit-unified-{5h,7d}-status: allowed(utilization 0.34/0.22) — 계정 cap 과 무관하게 OAuth 검증 통과 확인.--use-claude-code-auth명시 안 하면 Claude 자격증명을 절대 읽지 않음 (가드 테스트 포함). macOS 첫 실행 시 키체인 권한 다이얼로그가 1회 뜨는 건 정상.체크리스트
clones/)을 수정하지 않았음을 확인.github/workflows/validate.yml) — 로컬에서 typecheck + 101/101 tests + smoke-hook + markdownlint 통과🤖 Generated with Claude Code