diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index c0a2d541..c2bf6049 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -123,9 +123,9 @@ jobs: # Get current SHA values of files echo "Getting SHA for pyproject.toml" PYPROJECT_SHA=$(gh api /repos/$GITHUB_REPOSITORY/contents/pyproject.toml --jq '.sha') - echo "Getting SHA for __init__.py" - INIT_SHA=$(gh api /repos/$GITHUB_REPOSITORY/contents/src/claude_code_sdk/__init__.py --jq '.sha') - + echo "Getting SHA for _version.py" + VERSION_SHA=$(gh api /repos/$GITHUB_REPOSITORY/contents/src/claude_code_sdk/_version.py --jq '.sha') + # Commit pyproject.toml via GitHub API (this creates signed commits) message="chore: bump version to ${{ env.VERSION }}" base64 -i pyproject.toml > pyproject.toml.b64 @@ -136,15 +136,15 @@ jobs: -F content=@pyproject.toml.b64 \ -f sha="$PYPROJECT_SHA" \ -f branch="$BRANCH_NAME" - - # Commit __init__.py via GitHub API - base64 -i src/claude_code_sdk/__init__.py > init.py.b64 + + # Commit _version.py via GitHub API + base64 -i src/claude_code_sdk/_version.py > version.py.b64 gh api \ --method PUT \ - /repos/$GITHUB_REPOSITORY/contents/src/claude_code_sdk/__init__.py \ + /repos/$GITHUB_REPOSITORY/contents/src/claude_code_sdk/_version.py \ -f message="$message" \ - -F content=@init.py.b64 \ - -f sha="$INIT_SHA" \ + -F content=@version.py.b64 \ + -f sha="$VERSION_SHA" \ -f branch="$BRANCH_NAME" # Create PR using GitHub CLI @@ -152,7 +152,7 @@ jobs: ## Changes - Updated version in \`pyproject.toml\` - - Updated version in \`src/claude_code_sdk/__init__.py\` + - Updated version in \`src/claude_code_sdk/_version.py\` ## Release Information - Published to PyPI: https://pypi.org/project/claude-code-sdk/${{ env.VERSION }}/ diff --git a/scripts/update_version.py b/scripts/update_version.py index 9d92a817..18a22a6f 100755 --- a/scripts/update_version.py +++ b/scripts/update_version.py @@ -11,7 +11,7 @@ def update_version(new_version: str) -> None: # Update pyproject.toml pyproject_path = Path("pyproject.toml") content = pyproject_path.read_text() - + # Only update the version field in [project] section content = re.sub( r'^version = "[^"]*"', @@ -20,14 +20,14 @@ def update_version(new_version: str) -> None: count=1, flags=re.MULTILINE ) - + pyproject_path.write_text(content) print(f"Updated pyproject.toml to version {new_version}") - - # Update __init__.py - init_path = Path("src/claude_code_sdk/__init__.py") - content = init_path.read_text() - + + # Update _version.py + version_path = Path("src/claude_code_sdk/_version.py") + content = version_path.read_text() + # Only update __version__ assignment content = re.sub( r'^__version__ = "[^"]*"', @@ -36,9 +36,9 @@ def update_version(new_version: str) -> None: count=1, flags=re.MULTILINE ) - - init_path.write_text(content) - print(f"Updated __init__.py to version {new_version}") + + version_path.write_text(content) + print(f"Updated _version.py to version {new_version}") if __name__ == "__main__": diff --git a/src/claude_code_sdk/__init__.py b/src/claude_code_sdk/__init__.py index b2d5ac2a..639c2c5c 100644 --- a/src/claude_code_sdk/__init__.py +++ b/src/claude_code_sdk/__init__.py @@ -12,6 +12,7 @@ ProcessError, ) from ._internal.transport import Transport +from ._version import __version__ from .client import ClaudeSDKClient from .query import query from .types import ( @@ -274,11 +275,10 @@ async def call_tool(name: str, arguments: dict[str, Any]) -> Any: return McpSdkServerConfig(type="sdk", name=name, instance=server) -__version__ = "0.0.23" - __all__ = [ # Main exports "query", + "__version__", # Transport "Transport", "ClaudeSDKClient", diff --git a/src/claude_code_sdk/_internal/transport/subprocess_cli.py b/src/claude_code_sdk/_internal/transport/subprocess_cli.py index 0b0cb785..c701bb37 100644 --- a/src/claude_code_sdk/_internal/transport/subprocess_cli.py +++ b/src/claude_code_sdk/_internal/transport/subprocess_cli.py @@ -16,6 +16,7 @@ from ..._errors import CLIConnectionError, CLINotFoundError, ProcessError from ..._errors import CLIJSONDecodeError as SDKJSONDecodeError +from ..._version import __version__ from ...types import ClaudeCodeOptions from . import Transport @@ -187,6 +188,7 @@ async def connect(self) -> None: **os.environ, **self._options.env, # User-provided env vars "CLAUDE_CODE_ENTRYPOINT": "sdk-py", + "CLAUDE_AGENT_SDK_VERSION": __version__, } if self._cwd: diff --git a/src/claude_code_sdk/_version.py b/src/claude_code_sdk/_version.py new file mode 100644 index 00000000..0ff45304 --- /dev/null +++ b/src/claude_code_sdk/_version.py @@ -0,0 +1,3 @@ +"""Version information for claude-code-sdk.""" + +__version__ = "0.0.23"