Skip to content

Sidecar fails with 'Missing Authentication header' when API keys are in ~/.zshrc #11

@ellisjr

Description

@ellisjr

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

  1. Export API keys in ~/.zshrc (not ~/.zshenv)
  2. Run sidecar from a non-interactive shell context (e.g., Claude Code, a Node script, cron):
    sidecar start --model gemini --prompt "Hello" --no-ui
  3. 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:

  1. 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
  2. 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"
  3. 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.json had 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions