CLAUDE_CODE_CHILD_SESSION
Claude CodeがBashやPowerShell、フック、ステータスラインコマンドを通じて生成するサブプロセスにおいて1に設定される環境変数。
使い方・用途
- 実行中のプロセスがClaude Code自身のツール呼び出しから開始された子セッション(入れ子のセッション)であることを識別するために使用します。
- 子セッションとして起動されたインタラクティブなTUIが、自動的に履歴(--resume等)やエージェントリストに保存されるのを防ぎ、セッション管理をクリーンに保ちます。
- 自作CLIツールなどがClaude Codeから呼び出された際に、この変数の有無を検知してヒントタグを出力するなど、AI向けに最適化した挙動を制御する際の判定基準になります。
Set to 1 in subprocesses Claude Code spawns via the Bash, PowerShell, and Monitor tools, hook commands, and status line commands. Not set for stdio MCP server subprocesses, which are long-lived and outlive the session that spawned them. Unlike CLAUDECODE, this is only set by Claude Code's own spawn path and not by IDE extensions, so it reliably distinguishes a nested session from a top-level claude launched in an IDE-integrated terminal. A nested interactive claude TUI started this way is automatically excluded from --resume, --continue, up-arrow history, and the claude agents list. Non-interactive claude -p sessions still persist. Set CLAUDE_CODE_FORCE_SESSION_PERSISTENCE=1 to override this exclusion. Requires Claude Code v2.1.172 or later