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:
codeframe tasks generate falls back to "simple extraction" instead of LLM generation
codeframe work start --execute completes in ~1.6s without doing real work (no API calls made)
- 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:
-
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.
-
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
Problem
When running the CLI via subprocess (e.g., from e2e tests or scripts),
ANTHROPIC_API_KEYis not reliably inherited. This causes silent failures where:codeframe tasks generatefalls back to "simple extraction" instead of LLM generationcodeframe work start --executecompletes in ~1.6s without doing real work (no API calls made)Root Cause
The environment variable must be explicitly set in the subprocess environment. The
_build_env()method inGoldenPathRunnercopiesos.environ, but if the parent process loaded the key from.envafter the environment was already established, child processes don't inherit it.Observed Behavior
Current Workaround
The e2e conftest.py has
_ensure_api_key()that eagerly loads from.envat import time:Proposed Fix
Two complementary changes:
CLI should fail loudly when
ANTHROPIC_API_KEYis required but missing (for commands liketasks generate,work start --execute). Instead of falling back silently, print a clear error and exit with non-zero code.GoldenPathRunner._build_env() should explicitly load from
.envif the key isn't in the environment, similar to how conftest.py does it.Files
codeframe/cli/app.py— Task generation and work execution commandstests/e2e/cli/golden_path_runner.py—_build_env()methodtests/e2e/cli/conftest.py—_ensure_api_key()workaround