環境変数

CLAUDE_CODE_FORWARD_SUBAGENT_TEXT

サブエージェントのテキスト出力や思考プロセス(thinking blocks)を、ストリーム出力形式で強制的に含めるための環境変数です。

使い方・用途

  • CI/CD パイプラインなどの自動化環境において、フラグを直接渡せない場合に利用します。
  • --output-format stream-json と併用することで、サブエージェントの全トランスクリプトを復元可能です。
  • プロセス全体で設定しても、非対話モードでエラーにならず適切に無視されるため安全に使用できます。
英語原文(公式ドキュメントより)

Set to 1 to emit subagent text and thinking blocks in claude -p --output-format stream-json output, the same behavior as the --forward-subagent-text flag. Use the variable when a harness invokes claude and can't pass the flag itself. Unlike the flag, which exits with an error outside non-interactive mode with stream-json output, the variable is ignored there so that nested invocations keep working when it's set process-wide. Requires Claude Code v2.1.211 or later

関連する変更履歴

v2.1.211(1件)

Added
--forward-subagent-textフラグとCLAUDE_CODE_FORWARD_SUBAGENT_TEXT環境変数を追加し、stream-json出力にサブエージェントのテキストとThinkingブロックを含められるようにした
英語原文を表示
Added --forward-subagent-text flag and CLAUDE_CODE_FORWARD_SUBAGENT_TEXT environment variable to include subagent text and thinking in stream-json output

変更前

デフォルトではサブエージェントによるツール使用(tool_use)とツール実行結果(tool_result)のブロックのみが出力されていました。サブエージェントが何を考え、どのようなテキストを出力したかの詳細はストリーム出力に含まれていませんでした。

変更後

フラグまたは環境変数を有効にすることで、サブエージェントの思考プロセスやテキスト生成内容もJSONストリームに含まれるようになります。これにより、外部ツールなどでサブエージェントを含む会話の完全なログを再現できるようになります。

ユーザーへの恩恵

ストリーム出力を解析してサブエージェントの動作を詳細に追跡したり、会話の書き起こしを完全に再現したりできるようになる。