opencode
opencode copied to clipboard
feat: Auth file parameter
Add --auth-file parameter for multiple account support
Summary
Add --auth-file CLI parameter to allow users to specify custom authentication file paths, enabling multiple accounts per service provider.
Problem
OpenCode currently uses a single auth file (~/.local/share/opencode/auth.json) which creates conflicts:
- Users with multiple GitHub accounts (work/personal) cannot maintain separate credentials
- Adding new accounts overwrites existing ones for the same service
- No way to isolate credentials per project or context
Additionally encountered ProviderTransform.topP is not a function error when testing locally due to missing function in transform namespace.
Fix
- Add
--auth-fileglobal CLI option that accepts custom file paths - Update auth system to use dynamic file paths via
Global.setAuthFile()/Global.getAuthFile() - All auth operations (
login,logout,list) respect the custom file path - Maintains backward compatibility - defaults to existing behavior when not specified
- Add missing
topP()function toProviderTransformnamespace to fix session initialization error
Testing
# Default behavior unchanged
opencode auth list
# Uses: ~/.local/share/opencode/auth.json
# Custom auth file works
opencode --auth-file /tmp/work-auth.json auth login # github or any supported provider
opencode --auth-file /tmp/work-auth.json auth list
# Uses: /tmp/work-auth.json
# Multiple accounts can coexist
opencode --auth-file ~/.config/work-auth.json auth login # work account
opencode --auth-file ~/.config/personal-auth.json auth login # personal account
# Each maintains separate credentials
opencode --auth-file /tmp/work-auth.json run "hello" --model="github-copilot/gpt-4o"
Files changed:
packages/opencode/src/global/index.ts- Auth file path managementpackages/opencode/src/index.ts- CLI option and middlewarepackages/opencode/src/auth/index.ts- Dynamic file path supportpackages/opencode/src/cli/cmd/auth.ts- Display current auth filepackages/opencode/src/provider/transform.ts- Fix missing topP function
this makes sense i need to think about it a bit though with some other changes i'm planning
I think it would be better to allow users to duplicate entries. Instead of using the provider name as the token name, add an additional 'type' parameter to specify which provider profile to use. Then you can name your Copilot profiles however you want.