[PR #1540] [CLOSED] feat: Auth file parameter #9967

Closed
opened 2026-02-16 18:14:28 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/anomalyco/opencode/pull/1540
Author: @sahilchouksey
Created: 8/2/2025
Status: Closed

Base: devHead: feat/auth-file-parameter


📝 Commits (3)

  • 18a7fd4 fix: add missing topP function to ProviderTransform
  • 016ef06 feat: add --auth-file parameter for multiple account support
  • da51e15 Merge branch 'dev' into feat/auth-file-parameter

📊 Changes

5 files changed (+28 additions, -8 deletions)

View changed files

📝 packages/opencode/src/auth/index.ts (+7 -6)
📝 packages/opencode/src/cli/cmd/auth.ts (+1 -2)
📝 packages/opencode/src/global/index.ts (+10 -0)
📝 packages/opencode/src/index.ts (+9 -0)
📝 packages/opencode/src/provider/transform.ts (+1 -0)

📄 Description

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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/anomalyco/opencode/pull/1540 **Author:** [@sahilchouksey](https://github.com/sahilchouksey) **Created:** 8/2/2025 **Status:** ❌ Closed **Base:** `dev` ← **Head:** `feat/auth-file-parameter` --- ### 📝 Commits (3) - [`18a7fd4`](https://github.com/anomalyco/opencode/commit/18a7fd44da0f6a1f8f863a3322ed8451cedc455c) fix: add missing topP function to ProviderTransform - [`016ef06`](https://github.com/anomalyco/opencode/commit/016ef060cce5ec349bb322663b5f31c5cf3af0a5) feat: add --auth-file parameter for multiple account support - [`da51e15`](https://github.com/anomalyco/opencode/commit/da51e1595a879806aa0dc83a63dd0f3c24486caf) Merge branch 'dev' into feat/auth-file-parameter ### 📊 Changes **5 files changed** (+28 additions, -8 deletions) <details> <summary>View changed files</summary> 📝 `packages/opencode/src/auth/index.ts` (+7 -6) 📝 `packages/opencode/src/cli/cmd/auth.ts` (+1 -2) 📝 `packages/opencode/src/global/index.ts` (+10 -0) 📝 `packages/opencode/src/index.ts` (+9 -0) 📝 `packages/opencode/src/provider/transform.ts` (+1 -0) </details> ### 📄 Description # 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 ```bash # 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 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-16 18:14:28 -05:00
yindo closed this issue 2026-02-16 18:14:28 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#9967