-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Summary
Sidecar CLI fails with Missing Authentication header when API keys (GOOGLE_GENERATIVE_AI_API_KEY, OPENAI_API_KEY) are exported in ~/.zshrc but not in ~/.zshenv. This affects all headless (--no-ui) and interactive invocations when launched from non-interactive shells (e.g., Claude Code's Bash tool, CI/CD, scripts).
Steps to Reproduce
- Export API keys in
~/.zshrc(not~/.zshenv) - Run sidecar from a non-interactive shell context (e.g., Claude Code, a Node script, cron):
sidecar start --model gemini --prompt "Hello" --no-ui - Observe:
{"level":"error","msg":"Session error detected","error":"APIError","message":"Missing Authentication header"}
Workaround: source ~/.zshrc && sidecar start ... — works but fragile.
Root Cause
Sidecar is a Node.js script (#!/usr/bin/env node) that inherits environment from its parent shell. When the parent is non-interactive (common for tool-spawned processes), zsh only sources ~/.zshenv — not ~/.zshrc.
| Shell Mode | Sources .zshrc? |
Keys Available? |
|---|---|---|
zsh (non-interactive) |
No | No |
zsh -l (login) |
No | No |
zsh -i (interactive) |
Yes | Yes |
| Terminal.app / iTerm | Yes | Yes |
| Claude Code Bash tool | No | No |
source ~/.zshrc && sidecar |
Forced | Yes (workaround) |
Expected Behavior
Sidecar should either:
- Document the requirement that API keys must be in
~/.zshenv(not~/.zshrc) for non-interactive shell compatibility — the setup docs currently say "Add these to your shell profile (~/.bashrc,~/.zshrc)" which is misleading for zsh - Auto-detect and warn when running in a non-interactive shell without required API keys, with a message like: "API key not found. If your keys are in ~/.zshrc, move them to ~/.zshenv for non-interactive shell support"
- Attempt to source common profile files as a fallback when keys are missing
Environment
- macOS 14.5 (Darwin 23.5.0)
- zsh (default shell)
- sidecar installed via npm (
/usr/local/bin/sidecar) - Claude Code as parent process
~/.local/share/opencode/auth.jsonhad placeholder value
Additional Context
The sidecar skill docs recommend ~/.bashrc and ~/.zshrc for key placement. For bash users this works fine (.bashrc is sourced by non-interactive bash when BASH_ENV is set). For zsh users, this is a silent failure mode — keys appear to work in terminals but fail in automated/tool contexts.
🤖 Generated with Claude Code