Skip to content

[Phase 2.5] ANTHROPIC_API_KEY not reliably propagated to CLI subprocesses #376

Description

@frankbria

Problem

When running the CLI via subprocess (e.g., from e2e tests or scripts), ANTHROPIC_API_KEY is not reliably inherited. This causes silent failures where:

  1. codeframe tasks generate falls back to "simple extraction" instead of LLM generation
  2. codeframe work start --execute completes in ~1.6s without doing real work (no API calls made)
  3. Both return exit code 0, masking the failure

Root Cause

The environment variable must be explicitly set in the subprocess environment. The _build_env() method in GoldenPathRunner copies os.environ, but if the parent process loaded the key from .env after the environment was already established, child processes don't inherit it.

Observed Behavior

codeframe tasks generate
# Output: "LLM generation failed (ANTHROPIC_API_KEY not set...), using simple extraction"
# Exit code: 0  ← NOT an error from CLI perspective

Current Workaround

The e2e conftest.py has _ensure_api_key() that eagerly loads from .env at import time:

def _ensure_api_key():
    if os.environ.get("ANTHROPIC_API_KEY"):
        return
    env_file = CODEFRAME_ROOT / ".env"
    # ... reads .env and sets os.environ

Proposed Fix

Two complementary changes:

  1. CLI should fail loudly when ANTHROPIC_API_KEY is required but missing (for commands like tasks generate, work start --execute). Instead of falling back silently, print a clear error and exit with non-zero code.

  2. GoldenPathRunner._build_env() should explicitly load from .env if the key isn't in the environment, similar to how conftest.py does it.

Files

  • codeframe/cli/app.py — Task generation and work execution commands
  • tests/e2e/cli/golden_path_runner.py_build_env() method
  • tests/e2e/cli/conftest.py_ensure_api_key() workaround

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingphase-2Phase 2: Server Layer as Thin Adapter

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions