Skip to content

Autonomous AI sales agent powered by Claude Code or Codex. Finds prospects, writes cold emails, sends campaigns, handles replies, books meetings. No API keys needed — runs on your Claude or Codex subscriptions.

Windows review 2: system code page fallback, claude.exe-only shim match

Ethan3233b468cdc3
diff --git a/harvey/claude_runtime.py b/harvey/claude_runtime.py
index f0fc768..cecd723 100644
--- a/harvey/claude_runtime.py
+++ b/harvey/claude_runtime.py
@@ -81,9 +81,12 @@ class ClaudeRuntimeError(Exception):
_PLATFORM = sys.platform
-# npm/yarn/pnpm shims name their target relative to the shim's folder:
+# npm/yarn/pnpm shims name their target relative to the shim's folder
# "%dp0%\node_modules\@anthropic-ai\claude-code\bin\claude.exe" %*
-_SHIM_TARGET_RE = re.compile(r'"%~?dp0%?\\([^"%]+?\.exe)"', re.IGNORECASE)
+# or, on another drive, by absolute path. Only claude.exe counts: older
+# shims also name node.exe.
+_SHIM_TARGET_RE = re.compile(
+ r'"(?:%~?dp0%?\\)?((?:[A-Za-z]:\\)?[^"%]*?\bclaude\.exe)"', re.IGNORECASE)
# Before its install script runs, the package's bin/claude.exe is a small
# text placeholder, not the real binary.
_MIN_NATIVE_BYTES = 4096
@@ -103,7 +106,8 @@ def _shim_target(shim: Path) -> Path:
except OSError:
m = None
if m:
- return shim.parent / Path(m.group(1).replace("\\", "/"))
+ target = m.group(1).replace("\\", "/")
+ return Path(target) if re.match(r"[A-Za-z]:/", target) else shim.parent / target
return shim.parent / "node_modules" / "@anthropic-ai" / "claude-code" / "bin" / "claude.exe"
@@ -128,10 +132,14 @@ def find_claude(env: dict | None = None) -> str | None:
found, native = _locate(env)
if native is None:
return found
- if native.is_file() and native.stat().st_size >= _MIN_NATIVE_BYTES:
+ try:
+ size = native.stat().st_size if native.is_file() else None
+ except OSError:
+ size = None # removed between the checks: treated as missing
+ if size is not None and size >= _MIN_NATIVE_BYTES:
return str(native)
problem = ("is only a placeholder: the package's install script didn't run"
- if native.is_file() else "isn't there")
+ if size is not None else "isn't there")
raise ClaudeRuntimeError(
f"Found the claude.cmd shim ({found}), but the claude.exe it launches "
f"({native}) {problem}. Harvey never runs Claude through cmd.exe, which "
diff --git a/harvey/textio.py b/harvey/textio.py
index a373b0e..02ce829 100644
--- a/harvey/textio.py
+++ b/harvey/textio.py
@@ -21,7 +21,9 @@ def read_user_text(path) -> str:
try:
return data.decode("utf-8-sig")
except UnicodeDecodeError:
- encoding = locale.getpreferredencoding(False)
+ # The system code page (cp1252 on most Windows), even in Python's
+ # UTF-8 mode, where getpreferredencoding() would say utf-8.
+ encoding = locale.getencoding()
logger.warning(
f"{path} isn't saved as UTF-8; read it as {encoding}. Re-save it as "
"UTF-8 to keep characters like ★ or — intact.")
diff --git a/tests/test_windows_support.py b/tests/test_windows_support.py
index d9c5ef1..3b5a660 100644
--- a/tests/test_windows_support.py
+++ b/tests/test_windows_support.py
@@ -189,5 +189,44 @@ def test_a_cp1252_config_loads(tmp_path):
config = tmp_path / "harvey.yaml"
config.write_bytes(yaml.safe_dump(data, allow_unicode=True).encode("cp1252"))
company = load_config(str(config)).persona.company
- # Exact under a cp1252 locale (Windows CI); readable, not a crash, elsewhere.
- assert company.startswith("Caf") and company.endswith("Studio")
+ import locale
+ if locale.getencoding().lower() in ("cp1252", "windows-1252"):
+ assert company == "Caf\u00e9 \u2014 Studio" # Windows CI, even in UTF-8 mode
+ else:
+ assert company.startswith("Caf") and company.endswith("Studio") # readable, no crash
+
+
+# Shim texts as npm's cmd-shim 9 and pnpm's @zkochan/cmd-shim write them.
+SHIMS = {
+ "npm": ('@ECHO off\r\nGOTO start\r\n:find_dp0\r\nSET dp0=%~dp0\r\nEXIT /b\r\n:start\r\n'
+ 'SETLOCAL\r\nCALL :find_dp0\r\n"%dp0%\\node_modules\\@anthropic-ai\\claude-code'
+ '\\bin\\claude.exe" %*\r\n',
+ "node_modules/@anthropic-ai/claude-code/bin/claude.exe"),
+ "pnpm": ('@SETLOCAL\r\n@"%~dp0\\global\\5\\node_modules\\@anthropic-ai\\claude-code'
+ '\\bin\\claude.exe" %*\r\n',
+ "global/5/node_modules/@anthropic-ai/claude-code/bin/claude.exe"),
+ "yarn": ('@"%~dp0\\..\\Data\\global\\node_modules\\@anthropic-ai\\claude-code\\bin'
+ '\\claude.exe" %*\r\n',
+ "../Data/global/node_modules/@anthropic-ai/claude-code/bin/claude.exe"),
+ # An older JS-era shim also names node.exe first: never picked.
+ "node-first": ('@IF EXIST "%~dp0\\node.exe" (\r\n "%~dp0\\node.exe" '
+ '"%~dp0\\node_modules\\x\\claude.exe" %*\r\n)\r\n',
+ "node_modules/x/claude.exe"),
+}
+
+
[email protected]("kind", sorted(SHIMS))
+def test_shim_targets(kind, tmp_path):
+ text, expected = SHIMS[kind]
+ shim = tmp_path / "bin" / "claude.cmd"
+ shim.parent.mkdir()
+ shim.write_text(text, encoding="utf-8")
+ assert claude_runtime._shim_target(shim) == shim.parent / expected
+
+
+def test_a_shim_pointing_to_another_drive(tmp_path):
+ shim = tmp_path / "claude.cmd"
+ shim.write_text('@"D:\\pnpm\\global\\5\\node_modules\\@anthropic-ai\\claude-code\\bin'
+ '\\claude.exe" %*\r\n', encoding="utf-8")
+ assert str(claude_runtime._shim_target(shim)).replace("\\", "/") == \
+ "D:/pnpm/global/5/node_modules/@anthropic-ai/claude-code/bin/claude.exe"