From 723dc019664a7e6826e0303614819922c493ee4a Mon Sep 17 00:00:00 2001 From: Lee YongSeok Date: Tue, 1 Jul 2025 21:41:29 +0900 Subject: [PATCH] Pass environment variables to the Claude CLI via options parameter. --- src/claude_code_sdk/_internal/transport/subprocess_cli.py | 3 ++- src/claude_code_sdk/types.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/claude_code_sdk/_internal/transport/subprocess_cli.py b/src/claude_code_sdk/_internal/transport/subprocess_cli.py index 288b2e7..9e091b0 100644 --- a/src/claude_code_sdk/_internal/transport/subprocess_cli.py +++ b/src/claude_code_sdk/_internal/transport/subprocess_cli.py @@ -33,6 +33,7 @@ class SubprocessCLITransport(Transport): self._options = options self._cli_path = str(cli_path) if cli_path else self._find_cli() self._cwd = str(options.cwd) if options.cwd else None + self._envvars = options.envvars if options.envvars else {} self._process: Process | None = None self._stdout_stream: TextReceiveStream | None = None self._stderr_stream: TextReceiveStream | None = None @@ -129,7 +130,7 @@ class SubprocessCLITransport(Transport): stdout=PIPE, stderr=PIPE, cwd=self._cwd, - env={**os.environ, "CLAUDE_CODE_ENTRYPOINT": "sdk-py"}, + env={**os.environ, **self._envvars, "CLAUDE_CODE_ENTRYPOINT": "sdk-py"}, ) if self._process.stdout: diff --git a/src/claude_code_sdk/types.py b/src/claude_code_sdk/types.py index bd3c726..8b7ab88 100644 --- a/src/claude_code_sdk/types.py +++ b/src/claude_code_sdk/types.py @@ -2,7 +2,7 @@ from dataclasses import dataclass, field from pathlib import Path -from typing import Any, Literal, TypedDict +from typing import Any, Literal, TypedDict, Dict from typing_extensions import NotRequired # For Python < 3.11 compatibility @@ -127,3 +127,4 @@ class ClaudeCodeOptions: model: str | None = None permission_prompt_tool_name: str | None = None cwd: str | Path | None = None + envvars: Dict[str, str] | None = None