opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat: Auth file parameter

Open sahilchouksey opened this issue 4 months ago • 2 comments

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-file global 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 to ProviderTransform namespace 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 management
  • packages/opencode/src/index.ts - CLI option and middleware
  • packages/opencode/src/auth/index.ts - Dynamic file path support
  • packages/opencode/src/cli/cmd/auth.ts - Display current auth file
  • packages/opencode/src/provider/transform.ts - Fix missing topP function

sahilchouksey avatar Aug 02 '25 09:08 sahilchouksey

this makes sense i need to think about it a bit though with some other changes i'm planning

thdxr avatar Aug 03 '25 19:08 thdxr

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.

FarisZR avatar Aug 19 '25 15:08 FarisZR