아카이브 / 개발
opencode-auth-profiles — 멀티계정 인증 프로필 자동화
목차 — 프로젝트 요약 · 담당 범위 · 문제와 구현 접근 · 이 작업에서 한 일 · 결과물과 원문 · 구현 상세
프로젝트 요약
여러 Claude/OpenCode 계정을 여러 원격 서버에 매핑하고, 리프레시 토큰을 복사하지 않고도 원격의 토큰 상태를 검증하는 인증 자동화 툴킷.
담당 범위
기획·설계·개발을 맡은 개인 프로젝트다. 공개 저장소에서 코드와 사용 방법을 확인할 수 있다.
문제와 구현 접근
로컬 머신 한 곳에서만 브라우저 로그인을 유지하면서, 계정별 프로필을 여러 원격 서버에 매핑하고 launchd/systemd 기반으로 토큰을 전파한다. 기본적으로 리프레시 토큰을 원격에 복사하지 않고 Anthropic 모델 엔드포인트로 원격 토큰의 유효성만 검증한다.
여러 Claude Code/Claude 계정을 여러 서버(macair·macstudio 등)에 나눠 운영하는 실제 개인 인프라 문제에서 나온 도구다.
이 작업에서 한 일
아이디어를 실제로 작동하는 코드로 만들고, 다른 사람이 설치하고 사용할 수 있도록 설명서를 함께 작성했다.
결과물과 원문
관련 등록공보·논문·저장소는 아래 링크에서 볼 수 있다.
구현 상세
README공개 저장소의 구조·기능·실행 문서
opencode-auth-profiles
Portable multi-profile auth automation for OpenCode.
This repository extracts a local automation setup into a reusable public package with:
- provider-scoped profile snapshots
- inactive Anthropic OAuth refresh on the local machine
- access-only deployment to remote servers
- remote verification via Anthropic models endpoint
- launchd/systemd-based token propagation
What problem it solves
If you use multiple Claude/OpenCode accounts and multiple remote servers, this toolkit lets you:
- keep browser login on one local machine
- map different accounts to different remote servers
- avoid copying refresh tokens to remotes by default
- monitor whether remotes still have usable Anthropic tokens
Core files
src/oc-profiles.sh- shell CLI for profile managementsrc/oc-refresh.mjs- Anthropic refresh engine and verification helperssrc/oc-token-push.sh- scheduler entrypointexamples/manifest.example.json- sanitized profile/server mapping examplelaunchd/com.opencode.token-push.plist.template- macOS scheduler template
Commands
oc-save <provider> <name> [label]oc-sync [provider...]oc-refreshoc-refresh --profile anthropic/<name> --forceoc-apply --anthropic <name> --openai <name>oc-map <server> --anthropic <name> --openai <name>oc-deploy <server>oc-deploy --alloc-healthoc-verify [server]oc-status
Install
git clone https://github.com/seokmogu/opencode-auth-profiles.git
cd opencode-auth-profiles
./install.sh
Then source the installed script:
source "$HOME/.local/share/opencode/profiles/oc-profiles.sh"
Example setup
- Copy the example manifest.
cp "$HOME/.local/share/opencode/profiles/manifest.json.example" "$HOME/.local/share/opencode/profiles/manifest.json"
- Edit profile names and server mappings.
- Log in locally with OpenCode.
opencode providers login -p anthropic
- Save the current provider snapshot.
oc-save anthropic account-a "account-a@example.com"
- Push access-only auth to remotes.
oc-deploy --all
- Verify remote usability.
oc-verify
Security model
- Local machine keeps refresh-capable OAuth state.
- Remotes receive access-only OAuth state by default.
oc-deploy --full-oauthexists, but should be treated as unsafe.- Never commit real profile JSON files or logs.
Publication checklist
- verify examples only use placeholders such as
account-a,server-a, andexample.com - verify the repository does not contain
auth.json, profile snapshots, logs, or token-shaped strings - verify launchd and install templates do not contain workstation-specific absolute paths
- verify
oc-deploy --full-oauthis documented as an exceptional unsafe mode
Verification commands
bash -n src/oc-profiles.sh
bash -n src/oc-token-push.sh
node --check src/oc-refresh.mjs
Scheduler
macOS
install.sh writes a launchd plist template into ~/Library/LaunchAgents/com.opencode.token-push.plist.
To enable it:
launchctl bootstrap gui/$(id -u) ~/Library/LaunchAgents/com.opencode.token-push.plist
The scheduler reacts to auth.json changes and also runs hourly.
Linux
On Linux, install.sh writes user-level systemd units into ~/.config/systemd/user/.
Enable them with:
systemctl --user daemon-reload
systemctl --user enable --now opencode-token-push.timer
Check timer state with:
systemctl --user status opencode-token-push.timer
systemctl --user list-timers | grep opencode-token-push
Known limitation
If an inactive Anthropic profile starts returning invalid_grant, you must log in locally for that account again and re-save the profile snapshot.
Optional integration
The original local setup also included an oc-export-openclaw-auth helper. This repository keeps the core OpenCode auth automation first; project-specific integrations can be added on top.