Claude Code Max 계정 여러 개를 OpenCode에서 자동 로테이션하여 토큰 한도 없이 사용하는 방법.
oc (alias) → ANTHROPIC_BASE_URL + API_KEY 주입 → OpenCode → opencode-anthropic-auth 플러그인 (패치)
↓
URL 경로 정규화 (/v1/ 삽입)
↓
CLIProxy (:8317) → 계정 풀 자동 전환
npm install -g @kaitranntt/ccs
# Claude 계정 풀에 계정 추가 (계정당 1회, 브라우저 OAuth 인증)
ccs claude --auth --add # 반복 실행하여 여러 계정 등록
# 등록된 계정 확인
ccs claude --accountscurl -fsSL https://opencode.ai/install | bash
# 모델 설정
# ~/.config/opencode/opencode.json 에서:
# "model": "anthropic/claude-opus-4-6"OpenCode의 opencode-anthropic-auth 플러그인이 OAuth 인증을 가로채서 CLIProxy와 호환되지 않습니다.
아래 패치를 적용하면 ANTHROPIC_BASE_URL 환경변수 감지 시 CLIProxy 모드로 동작합니다.
~/.cache/opencode/node_modules/opencode-anthropic-auth/index.mjs
auth: { ... loader(getAuth, provider) { 함수 본문 최상단 (기존 const auth = await getAuth() 앞)에 아래 블록 삽입:
// CCS CLIProxy mode: bypass OAuth, route to proxy
const proxyBaseUrl = process.env.ANTHROPIC_BASE_URL;
const proxyApiKey = process.env.ANTHROPIC_API_KEY;
if (proxyBaseUrl && proxyApiKey) {
for (const model of Object.values(provider.models)) {
model.cost = {
input: 0,
output: 0,
cache: { read: 0, write: 0 },
};
}
const anthropicOrigin = "https://api.anthropic.com";
const targetBase = proxyBaseUrl.replace(/\/$/, "");
return {
apiKey: proxyApiKey,
async fetch(input, init) {
let url =
typeof input === "string"
? input
: input instanceof URL
? input.toString()
: input instanceof Request
? input.url
: input;
if (typeof url === "string") {
// SDK may use anthropic origin or already-rewritten CLIProxy base
if (url.startsWith(anthropicOrigin)) {
const path = url.slice(anthropicOrigin.length);
const normalizedPath = path.startsWith("/v1/") ? path : "/v1" + path;
url = targetBase + normalizedPath;
} else if (url.startsWith(targetBase)) {
// SDK already using ANTHROPIC_BASE_URL — ensure /v1/ in path
const path = url.slice(targetBase.length);
if (!path.startsWith("/v1/")) {
url = targetBase + "/v1" + path;
}
}
}
if (input instanceof Request) {
return fetch(new Request(url, input), init);
}
return fetch(url, init);
},
};
}~/.zshrc (또는 ~/.bashrc)에 추가:
alias c='claude' # Claude Code (단독)
alias o='opencode' # OpenCode (단독, OAuth 단일 계정)
alias oc='eval $(ccs env claude --format anthropic) && ANTHROPIC_API_KEY="${ANTHROPIC_AUTH_TOKEN}" opencode'source ~/.zshrc| 명령어 | 동작 | 자동 Failover |
|---|---|---|
c |
Claude Code (단일 계정) | ❌ |
o |
OpenCode (auth.json OAuth, 단일 계정) | ❌ |
oc |
OpenCode + CCS 다계정 풀 | ✅ |
oc # TUI 실행 (quota 소진 시 자동 계정 전환)
oc run "task description" # 비대화형 실행
ccs claude --accounts # 풀 계정 목록
ccs cliproxy quota --provider claude # quota 상태 확인| 증상 | 원인 | 해결 |
|---|---|---|
| 404 에러 | 플러그인 패치 누락 또는 업데이트로 덮어씌워짐 | 3단계 패치 재적용 |
| OAuth 로그인 화면 | ANTHROPIC_BASE_URL 미설정 |
oc alias로 실행 (env var 자동 주입) |
connection refused |
CLIProxy 미실행 | ccs claude --accounts로 프록시 자동 시작 확인 |
grep "CCS CLIProxy" ~/.cache/opencode/node_modules/opencode-anthropic-auth/index.mjs
# 출력 없으면 → 패치 재적용 필요 (OpenCode 자동 업데이트가 덮어씌운 것)| 단계 | 패치 없이 | 패치 적용 후 |
|---|---|---|
| 인증 | OAuth Bearer 토큰 변환 | API Key 직접 전달 |
| URL | ?beta=true 추가, mcp_ 접두사 |
/v1/ 경로 정규화만 |
| 라우팅 | api.anthropic.com 직접 → 단일 계정 |
CLIProxy → 다계정 풀 |
| 비용 표시 | 실제 토큰 비용 계산 | $0 (Max 플랜) |
- Node.js 18+
- Claude Code Max 계정 1개 이상
- macOS / Linux