Bug Description
The oc-chatgpt-multi-auth plugin fails to create the ~/.opencode/ directory and persist OpenAI OAuth accounts to disk on Windows. After successfully logging in (browser shows "Login successful"), neither the directory nor the accounts file ~/.opencode/openai-codex-accounts.json are created. The user must manually create the ~/.opencode/ directory first. When running openai-accounts tool in OpenCode TUI, it shows "No OpenAI accounts configured" despite successful login.
Steps to Reproduce
Ensure ~/.opencode/ directory does NOT exist (fresh environment)
Run opencode auth login
Select "OpenAI" → "ChatGPT Pro/Plus (browser)"
Complete OAuth flow in browser (shows "Login successful")
Check directory: ~/.opencode/ - NOT created automatically (user must create manually)
Check file: ~/.opencode/openai-codex-accounts.json - does not exist
Open OpenCode TUI and run tool: openai-accounts
Observe: "No OpenAI accounts configured" message
Even after manually creating ~/.opencode/ directory and re-logging in, accounts are still not saved
Expected Behavior
After successful OAuth login, the plugin should:
Save account credentials (refresh token, email, accountId) to ~/.opencode/openai-codex-accounts.json
Show accounts when running openai-accounts tool
Allow account switching and rotation between multiple accounts
Actual Behavior
Login shows "Login successful" in terminal
Directory ~/.opencode/ is NOT created automatically - user must create it manually with mkdir -p ~/.opencode
Even after manually creating the directory, file ~/.opencode/openai-codex-accounts.json is still never created
Running openai-accounts in TUI shows: "No OpenAI accounts configured. To add accounts: opencode auth login"
Storage path reported: C:\Users{username}.opencode\openai-codex-accounts.json (directory and file missing)
Multiple login attempts (2+ accounts) produce same result
Error appears to be silently caught in persistAccountPool() function - no error message shown to user
Environment
opencode version: 1.1.43
Plugin version: 4.11.1 (latest)
Operating System: Windows 10/11 (64-bit)
Node.js version: [bundled with OpenCode]
Logs
Enable debug logging
set DEBUG_CODEX_PLUGIN=1
opencode auth login
Check logs
Logs directory: ~/.opencode/logs/codex-plugin/
Note: Logs may not be created if storage write fails before logger initialization
Additional Context
Critical Finding: The ~/.opencode/ directory is being misidentified as a PROJECT directory due to containing project markers (package.json, .gitignore, bun.lock, node_modules/)
Plugin uses perProjectAccounts: true (default), which calls setStoragePath(process.cwd())
When C:\Users{username} contains project markers, it becomes the project root
Storage path is set to: {project}/.opencode/openai-codex-accounts.json → C:\Users{username}.opencode\openai-codex-accounts.json
Manual file write test using Node.js (fs.writeFile) to ~/.opencode/test.json succeeds (permissions OK)
Plugin cache location: ~/.cache/opencode/node_modules/oc-chatgpt-multi-auth/ exists and loads correctly
Key Issue: ~/.opencode should NOT contain project markers - this is the plugin's own data directory
Root Cause Analysis
Through log analysis and code review, I found the actual bug:
Per-Project Storage Path Issue: In dist/index.js line 455-456:
if (perProjectAccounts) {
setStoragePath(process.cwd());
}
This sets the storage path based on current directory. However, the user's ~/.opencode directory contains project files (package.json, etc.), causing the plugin to treat the user's home directory as a project root.
2. Storage Path Resolution: In dist/lib/storage.js line 47-58:
export function setStoragePath(projectPath) {
const projectRoot = findProjectRoot(projectPath);
if (projectRoot) {
currentStoragePath = join(getProjectConfigDir(projectRoot), "openai-codex-accounts.json");
}
}
The findProjectRoot() function finds project markers (package.json, .gitignore) in parent directories, incorrectly identifying the user's home as a project.
3. Silent Error Handling: In dist/index.js line 829-838:
try {
await persistAccountPool([resolved], isFirstAccount && startFresh);
}
catch (err) {
logWarn([${PLUGIN_NAME}] Failed to persist account to disk: ${err?.message});
await showToast(..., "warning", ...);
}
Errors are caught and only logged with logWarn(), which requires DEBUG_CODEX_PLUGIN=1 to be visible. Users see "Login successful" but the actual save operation failed silently
Compliance Checklist
Please confirm:
Bug Description
The oc-chatgpt-multi-auth plugin fails to create the ~/.opencode/ directory and persist OpenAI OAuth accounts to disk on Windows. After successfully logging in (browser shows "Login successful"), neither the directory nor the accounts file ~/.opencode/openai-codex-accounts.json are created. The user must manually create the ~/.opencode/ directory first. When running openai-accounts tool in OpenCode TUI, it shows "No OpenAI accounts configured" despite successful login.
Steps to Reproduce
Ensure ~/.opencode/ directory does NOT exist (fresh environment)
Run opencode auth login
Select "OpenAI" → "ChatGPT Pro/Plus (browser)"
Complete OAuth flow in browser (shows "Login successful")
Check directory: ~/.opencode/ - NOT created automatically (user must create manually)
Check file: ~/.opencode/openai-codex-accounts.json - does not exist
Open OpenCode TUI and run tool: openai-accounts
Observe: "No OpenAI accounts configured" message
Even after manually creating ~/.opencode/ directory and re-logging in, accounts are still not saved
Expected Behavior
After successful OAuth login, the plugin should:
Save account credentials (refresh token, email, accountId) to ~/.opencode/openai-codex-accounts.json
Show accounts when running openai-accounts tool
Allow account switching and rotation between multiple accounts
Actual Behavior
Login shows "Login successful" in terminal
Directory ~/.opencode/ is NOT created automatically - user must create it manually with mkdir -p ~/.opencode
Even after manually creating the directory, file ~/.opencode/openai-codex-accounts.json is still never created
Running openai-accounts in TUI shows: "No OpenAI accounts configured. To add accounts: opencode auth login"
Storage path reported: C:\Users{username}.opencode\openai-codex-accounts.json (directory and file missing)
Multiple login attempts (2+ accounts) produce same result
Error appears to be silently caught in persistAccountPool() function - no error message shown to user
Environment
opencode version: 1.1.43
Plugin version: 4.11.1 (latest)
Operating System: Windows 10/11 (64-bit)
Node.js version: [bundled with OpenCode]
Logs
Enable debug logging
set DEBUG_CODEX_PLUGIN=1
opencode auth login
Check logs
Logs directory: ~/.opencode/logs/codex-plugin/
Note: Logs may not be created if storage write fails before logger initialization
Additional Context
Critical Finding: The ~/.opencode/ directory is being misidentified as a PROJECT directory due to containing project markers (package.json, .gitignore, bun.lock, node_modules/)
Plugin uses perProjectAccounts: true (default), which calls setStoragePath(process.cwd())
When C:\Users{username} contains project markers, it becomes the project root
Storage path is set to: {project}/.opencode/openai-codex-accounts.json → C:\Users{username}.opencode\openai-codex-accounts.json
Manual file write test using Node.js (fs.writeFile) to ~/.opencode/test.json succeeds (permissions OK)
Plugin cache location: ~/.cache/opencode/node_modules/oc-chatgpt-multi-auth/ exists and loads correctly
Key Issue: ~/.opencode should NOT contain project markers - this is the plugin's own data directory
Root Cause Analysis
Through log analysis and code review, I found the actual bug:
Per-Project Storage Path Issue: In dist/index.js line 455-456:
if (perProjectAccounts) {
setStoragePath(process.cwd());
}
This sets the storage path based on current directory. However, the user's ~/.opencode directory contains project files (package.json, etc.), causing the plugin to treat the user's home directory as a project root.
2. Storage Path Resolution: In dist/lib/storage.js line 47-58:
export function setStoragePath(projectPath) {
const projectRoot = findProjectRoot(projectPath);
if (projectRoot) {
currentStoragePath = join(getProjectConfigDir(projectRoot), "openai-codex-accounts.json");
}
}
The findProjectRoot() function finds project markers (package.json, .gitignore) in parent directories, incorrectly identifying the user's home as a project.
3. Silent Error Handling: In dist/index.js line 829-838:
try {
await persistAccountPool([resolved], isFirstAccount && startFresh);
}
catch (err) {
logWarn(
[${PLUGIN_NAME}] Failed to persist account to disk: ${err?.message});await showToast(..., "warning", ...);
}
Errors are caught and only logged with logWarn(), which requires DEBUG_CODEX_PLUGIN=1 to be visible. Users see "Login successful" but the actual save operation failed silently
Compliance Checklist
Please confirm: