diff --git a/claude/uclaude_updater.py b/claude/uclaude_updater.py index 8606564..7fbe987 100644 --- a/claude/uclaude_updater.py +++ b/claude/uclaude_updater.py @@ -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