Skip to content

Commit f0094ca

Browse files
ashwin-antclaude
andcommitted
feat: add sdk environment variable
Include the SDK version in the environment when spawning the Claude CLI process. Also refactored version management to use a dedicated _version.py file to avoid circular imports. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent cfdd28a commit f0094ca

File tree

5 files changed

+27
-22
lines changed

5 files changed

+27
-22
lines changed

.github/workflows/publish.yml

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ jobs:
123123
# Get current SHA values of files
124124
echo "Getting SHA for pyproject.toml"
125125
PYPROJECT_SHA=$(gh api /repos/$GITHUB_REPOSITORY/contents/pyproject.toml --jq '.sha')
126-
echo "Getting SHA for __init__.py"
127-
INIT_SHA=$(gh api /repos/$GITHUB_REPOSITORY/contents/src/claude_code_sdk/__init__.py --jq '.sha')
128-
126+
echo "Getting SHA for _version.py"
127+
VERSION_SHA=$(gh api /repos/$GITHUB_REPOSITORY/contents/src/claude_code_sdk/_version.py --jq '.sha')
128+
129129
# Commit pyproject.toml via GitHub API (this creates signed commits)
130130
message="chore: bump version to ${{ env.VERSION }}"
131131
base64 -i pyproject.toml > pyproject.toml.b64
@@ -136,23 +136,23 @@ jobs:
136136
-F content=@pyproject.toml.b64 \
137137
-f sha="$PYPROJECT_SHA" \
138138
-f branch="$BRANCH_NAME"
139-
140-
# Commit __init__.py via GitHub API
141-
base64 -i src/claude_code_sdk/__init__.py > init.py.b64
139+
140+
# Commit _version.py via GitHub API
141+
base64 -i src/claude_code_sdk/_version.py > version.py.b64
142142
gh api \
143143
--method PUT \
144-
/repos/$GITHUB_REPOSITORY/contents/src/claude_code_sdk/__init__.py \
144+
/repos/$GITHUB_REPOSITORY/contents/src/claude_code_sdk/_version.py \
145145
-f message="$message" \
146-
-F content=@init.py.b64 \
147-
-f sha="$INIT_SHA" \
146+
-F content=@version.py.b64 \
147+
-f sha="$VERSION_SHA" \
148148
-f branch="$BRANCH_NAME"
149149
150150
# Create PR using GitHub CLI
151151
PR_BODY="This PR updates the version to ${{ env.VERSION }} after publishing to PyPI.
152152
153153
## Changes
154154
- Updated version in \`pyproject.toml\`
155-
- Updated version in \`src/claude_code_sdk/__init__.py\`
155+
- Updated version in \`src/claude_code_sdk/_version.py\`
156156
157157
## Release Information
158158
- Published to PyPI: https://pypi.org/project/claude-code-sdk/${{ env.VERSION }}/

scripts/update_version.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def update_version(new_version: str) -> None:
1111
# Update pyproject.toml
1212
pyproject_path = Path("pyproject.toml")
1313
content = pyproject_path.read_text()
14-
14+
1515
# Only update the version field in [project] section
1616
content = re.sub(
1717
r'^version = "[^"]*"',
@@ -20,14 +20,14 @@ def update_version(new_version: str) -> None:
2020
count=1,
2121
flags=re.MULTILINE
2222
)
23-
23+
2424
pyproject_path.write_text(content)
2525
print(f"Updated pyproject.toml to version {new_version}")
26-
27-
# Update __init__.py
28-
init_path = Path("src/claude_code_sdk/__init__.py")
29-
content = init_path.read_text()
30-
26+
27+
# Update _version.py
28+
version_path = Path("src/claude_code_sdk/_version.py")
29+
content = version_path.read_text()
30+
3131
# Only update __version__ assignment
3232
content = re.sub(
3333
r'^__version__ = "[^"]*"',
@@ -36,9 +36,9 @@ def update_version(new_version: str) -> None:
3636
count=1,
3737
flags=re.MULTILINE
3838
)
39-
40-
init_path.write_text(content)
41-
print(f"Updated __init__.py to version {new_version}")
39+
40+
version_path.write_text(content)
41+
print(f"Updated _version.py to version {new_version}")
4242

4343

4444
if __name__ == "__main__":

src/claude_code_sdk/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
ProcessError,
1313
)
1414
from ._internal.transport import Transport
15+
from ._version import __version__
1516
from .client import ClaudeSDKClient
1617
from .query import query
1718
from .types import (
@@ -274,11 +275,10 @@ async def call_tool(name: str, arguments: dict[str, Any]) -> Any:
274275
return McpSdkServerConfig(type="sdk", name=name, instance=server)
275276

276277

277-
__version__ = "0.0.23"
278-
279278
__all__ = [
280279
# Main exports
281280
"query",
281+
"__version__",
282282
# Transport
283283
"Transport",
284284
"ClaudeSDKClient",

src/claude_code_sdk/_internal/transport/subprocess_cli.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
from ..._errors import CLIConnectionError, CLINotFoundError, ProcessError
1818
from ..._errors import CLIJSONDecodeError as SDKJSONDecodeError
19+
from ..._version import __version__
1920
from ...types import ClaudeCodeOptions
2021
from . import Transport
2122

@@ -187,6 +188,7 @@ async def connect(self) -> None:
187188
**os.environ,
188189
**self._options.env, # User-provided env vars
189190
"CLAUDE_CODE_ENTRYPOINT": "sdk-py",
191+
"CLAUDE_AGENT_SDK_VERSION": __version__,
190192
}
191193

192194
if self._cwd:

src/claude_code_sdk/_version.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"""Version information for claude-code-sdk."""
2+
3+
__version__ = "0.0.23"

0 commit comments

Comments
 (0)