From a14cd78b72a1e3612fa82ec41c9477d033720fb7 Mon Sep 17 00:00:00 2001 From: huhongwei <381093478@qq.com> Date: Wed, 28 Jan 2026 15:01:18 +0800 Subject: [PATCH] fix: use os.homedir() instead of process.env.HOME for Windows compatibility On Windows, process.env.HOME is undefined, causing the plugin to create a literal '~' directory in the project folder instead of using the user's home directory. This commit replaces all occurrences of 'process.env.HOME || "~"' with 'os.homedir()' for proper cross-platform path resolution. Changes: - Added 'import * as os from "os"' to src/cli.ts - Fixed 3 path.join() calls to use os.homedir() - setup command (line 469) - verify command (line 547) - SESSION_STATE_FILE constant (line 652) Fixes Windows path issue where session state file was created in project directory instead of user home directory. --- src/cli.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/cli.ts b/src/cli.ts index c923dd8..c77c35f 100644 --- a/src/cli.ts +++ b/src/cli.ts @@ -14,6 +14,7 @@ import { Command } from "commander"; import * as readline from "readline"; import * as fs from "fs"; import * as path from "path"; +import * as os from "os"; import { loadConfig, saveConfig, @@ -466,7 +467,7 @@ program .description("Add hooks to Claude Code settings (configures ~/.claude/settings.json)") .option("--force", "Overwrite existing hooks configuration") .action(async (options: { force?: boolean }) => { - const claudeDir = path.join(process.env.HOME || "~", ".claude"); + const claudeDir = path.join(os.homedir(), ".claude"); const settingsPath = path.join(claudeDir, "settings.json"); console.log("\n Claude Code Sync - Setup\n"); @@ -544,7 +545,7 @@ program } // Check Claude Code config - const settingsPath = path.join(process.env.HOME || "~", ".claude", "settings.json"); + const settingsPath = path.join(os.homedir(), ".claude", "settings.json"); let hooksConfigured = false; if (fs.existsSync(settingsPath)) { @@ -649,7 +650,7 @@ program // Track session state for title generation (first user prompt) const SESSION_STATE_FILE = path.join( - process.env.HOME || "~", + os.homedir(), ".config", "claude-code-sync", "session-state.json"