Description
When tdd-guard runs as a Claude Code hook with the default configuration (no VALIDATION_CLIENT set), the SDK client spawns a child Claude Code process via @anthropic-ai/claude-agent-sdk. This child process inherits the CLAUDECODE=1 environment variable from the parent session and refuses to start:
Error: Claude Code cannot be launched inside another Claude Code session.
Nested sessions share runtime resources and will crash all active sessions.
This causes tdd-guard to block all Edit/Write operations with:
Error during validation: Claude Code process exited with code 1
This affects every default installation — no special configuration is needed to trigger it.
Root Cause
ClaudeAgentSdk.getQueryOptions() does not pass an env option to query(), so the SDK inherits process.env including CLAUDECODE=1. The child Claude process interprets this as a nested session and exits.
This is a known upstream issue:
Suggested Fix
Strip CLAUDECODE from the environment passed to the SDK:
// in ClaudeAgentSdk.getQueryOptions()
env: this.getCleanEnvironment(),
// new private method
private getCleanEnvironment(): Record<string, string | undefined> {
const { CLAUDECODE, ...rest } = process.env
return rest
}
Environment
- tdd-guard 1.1.0
- Claude Code 2.x (native install)
@anthropic-ai/claude-agent-sdk (any version)
- macOS / Linux
Description
When tdd-guard runs as a Claude Code hook with the default configuration (no
VALIDATION_CLIENTset), the SDK client spawns a child Claude Code process via@anthropic-ai/claude-agent-sdk. This child process inherits theCLAUDECODE=1environment variable from the parent session and refuses to start:This causes tdd-guard to block all Edit/Write operations with:
This affects every default installation — no special configuration is needed to trigger it.
Root Cause
ClaudeAgentSdk.getQueryOptions()does not pass anenvoption toquery(), so the SDK inheritsprocess.envincludingCLAUDECODE=1. The child Claude process interprets this as a nested session and exits.This is a known upstream issue:
Suggested Fix
Strip
CLAUDECODEfrom the environment passed to the SDK:Environment
@anthropic-ai/claude-agent-sdk(any version)