Skip to content

SDK client fails inside Claude Code hooks due to inherited CLAUDECODE env var #106

Description

@wazum

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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