Skip to content

feat(cli): Claude Code 구독 OAuth 지원 (--use-claude-code-auth)#50

Merged
4entrepreneur merged 5 commits into
mainfrom
hy/claude-code-auth
May 5, 2026
Merged

feat(cli): Claude Code 구독 OAuth 지원 (--use-claude-code-auth)#50
4entrepreneur merged 5 commits into
mainfrom
hy/claude-code-auth

Conversation

@4entrepreneur

Copy link
Copy Markdown
Collaborator

변경 요약

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/anthropicauthToken/headers/fetch first-class 옵션 위에 얇은 셰임만 추가했습니다. --use-claude-auth alias 와 OPENCLONE_USE_CLAUDE_CODE_AUTH=1 env 도 함께 지원.

핵심 invariant: 커스텀 fetch 가 User-Agentclaude-cli/2.1.87 (external, cli) 로 강제 덮어쓰고, anthropic-betaoauth-2025-04-20,interleaved-thinking-2025-05-14 로 완전 교체하며 (SDK 가 자동 추가하는 structured-outputs-* 등은 strip), system 을 두 블록 [{identity}, {persona}] 로 분리하고, /v1/messages?beta=true 를 붙입니다 — 이 네 가지 중 하나라도 빠지면 Anthropic 이 generic 429 rate_limit_error 로 차단합니다 (계정 cap 무관).

변경 유형

  • 새 레퍼런스 (references/*.md) — skills/openclone-cli/references/claude-code-oauth.md
  • 문서 (README·CONTRIBUTING·docs·등) — README.md, CLAUDE.md, skills/openclone-cli/SKILL.md
  • 그 외: standalone CLI 의 provider 경로 추가 (src/cli/, src/lib/)

테스트 방법

npm install && npm run build && npm test     # 101/101 통과
node dist/cli/index.js chat douglas --use-claude-code-auth --prompt "1+1?"
node dist/cli/index.js chat douglas --use-claude-auth --model claude-opus-4-7   # alias + 모델 변경
OPENCLONE_DEBUG_HTTP=1 node dist/cli/index.js chat douglas --use-claude-code-auth --prompt "test" 2>&1 | head -40

라이브 검증: 200 응답 + 페르소나 voice 유지된 답변 (파랑.). 응답 헤더에서 anthropic-ratelimit-unified-{5h,7d}-status: allowed (utilization 0.34/0.22) — 계정 cap 과 무관하게 OAuth 검증 통과 확인.

--use-claude-code-auth 명시 안 하면 Claude 자격증명을 절대 읽지 않음 (가드 테스트 포함). macOS 첫 실행 시 키체인 권한 다이얼로그가 1회 뜨는 건 정상.

체크리스트

  • 추가·수정한 텍스트에 이모지가 포함되지 않았음을 확인
  • 내장 클론(clones/)을 수정하지 않았음을 확인
  • CI(.github/workflows/validate.yml) — 로컬에서 typecheck + 101/101 tests + smoke-hook + markdownlint 통과
  • 관련 문서(README/CLAUDE.md/skills 레퍼런스) 갱신

🤖 Generated with Claude Code

4entrepreneur and others added 3 commits May 6, 2026 05:07
… 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>
@vkehfdl1

vkehfdl1 commented May 5, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the contribution! 🙏

This repository's automation only reviews pull requests that target the dev branch (this PR currently targets main). Please change the base branch to dev so dani can pick it up for automated review.

GitHub UI → click "Edit" next to the PR title → change the base branch to dev, then push (or reopen) the PR.

4entrepreneur and others added 2 commits May 6, 2026 05:23
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
4entrepreneur merged commit a0b4c52 into main May 5, 2026
1 check passed
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.
4entrepreneur added a commit that referenced this pull request May 6, 2026
chore: dev에 main 머지 (#50~#54 등 sync, main 우선)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants