fix: read version from cli.js bundle instead of package.json

package.json shows npm-installed version (e.g. 2.1.47) while the actual
patched cli.js contains 2.1.50. Now reads "// Version: x.y.z" from the
bundle first, falls back to claude --version, then package.json.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
delta-cloud-208e
2026-02-21 14:03:35 +00:00
parent e98faa7e34
commit 2c00e0327d

View File

@@ -265,22 +265,31 @@ def find_cli_js():
def get_installed_version():
"""Get currently installed Claude Code version."""
"""Get currently installed Claude Code version.
Priority: cli.js bundle version > claude --version > package.json.
After patching, cli.js contains the real version while package.json
may still reflect the older npm-installed version.
"""
cli_js = find_cli_js()
if not cli_js:
return None, None
# Try package.json first (same directory as cli.js)
pkg_json = os.path.join(os.path.dirname(cli_js), "package.json")
if os.path.isfile(pkg_json):
try:
with open(pkg_json, "r") as f:
data = json.load(f)
return data.get("version"), cli_js
except Exception:
pass
# 1. Extract version from cli.js bundle itself (most accurate after patching)
try:
with open(cli_js, "r", encoding="utf-8", errors="ignore") as f:
# Read first 100KB where version string usually lives
head = f.read(100_000)
# Look for "// Version: x.y.z" comment or VERSION:"x.y.z" in the bundle
m = re.search(r'//\s*Version:\s*(\d+\.\d+\.\d+)', head)
if not m:
m = re.search(r'(?:VERSION|version)\s*[:=]\s*["\'](\d+\.\d+\.\d+)["\']', head)
if m:
return m.group(1), cli_js
except Exception:
pass
# Fallback: claude --version
# 2. claude --version
try:
result = subprocess.run(
["claude", "--version"],
@@ -292,6 +301,16 @@ def get_installed_version():
except Exception:
pass
# 3. Fallback: package.json (may be stale after cli.js replacement)
pkg_json = os.path.join(os.path.dirname(cli_js), "package.json")
if os.path.isfile(pkg_json):
try:
with open(pkg_json, "r") as f:
data = json.load(f)
return data.get("version"), cli_js
except Exception:
pass
return None, cli_js