Skip to content

feat: Auth file parameter#1540

Closed
sahilchouksey wants to merge 3 commits into
anomalyco:devfrom
sahilchouksey:feat/auth-file-parameter
Closed

feat: Auth file parameter#1540
sahilchouksey wants to merge 3 commits into
anomalyco:devfrom
sahilchouksey:feat/auth-file-parameter

Conversation

@sahilchouksey

Copy link
Copy Markdown

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 and others added 3 commits August 2, 2025 15:08
- Fixes TypeError: ProviderTransform.topP is not a function
- Session initialization was failing due to missing topP transform function
- Added topP function with default return value of 1
Allow users to specify custom authentication file paths to support
multiple accounts per service provider.

## Problem
- OpenCode currently uses a single auth file (~/.local/share/opencode/auth.json)
- Adding new accounts overwrites existing credentials
- Users with multiple GitHub accounts (personal/work) cannot easily switch contexts

## Solution
- Added --auth-file CLI parameter to specify custom auth file paths
- Maintains backward compatibility - defaults to existing behavior
- All auth operations (login, logout, list) respect the custom file path

## Changes
- Global: Added setAuthFile() and getAuthFile() functions for dynamic path management
- CLI: Added --auth-file option with middleware processing
- Auth: Updated all auth functions to use configurable file paths
- Commands: Auth list command displays current auth file path

## Usage
```bash
# Default behavior (unchanged)
opencode auth list

# Use custom auth files for different contexts
opencode --auth-file ~/.config/opencode/work-auth.json auth login github-copilot
opencode --auth-file ~/.config/opencode/personal-auth.json auth login github-copilot
opencode run "help me code" --auth-file ./project-auth.json
```

🤖 Generated with [opencode](https://opencode.ai)

Co-Authored-By: opencode <noreply@opencode.ai>
@sahilchouksey sahilchouksey changed the title Feat/auth file parameter feat: Auth file parameter Aug 3, 2025
teamgroove pushed a commit to teamgroove/opencode that referenced this pull request Aug 3, 2025
Merged from: anomalyco#1540
Author: @sahilchouksey
Auto-merged by opencode-fork integration system
@thdxr

thdxr commented Aug 3, 2025

Copy link
Copy Markdown
Member

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

@FarisZR

FarisZR commented Aug 19, 2025

Copy link
Copy Markdown

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.

@github-actions

github-actions Bot commented Feb 2, 2026

Copy link
Copy Markdown
Contributor

Closing this pull request because it has had no updates for more than 60 days. If you plan to continue working on it, feel free to reopen or open a new PR.

@github-actions github-actions Bot closed this Feb 2, 2026
bussard76 pushed a commit to bussard76/openwork that referenced this pull request May 12, 2026
…malyco#1540)

* fix(messaging): auto-heal missing router agent file

* fix(messaging): restart the router for messaging recovery
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.

3 participants