fix: Cross-platform hook compatibility for Windows#706
Open
chrisglick wants to merge 1 commit intodanielmiessler:mainfrom
Open
fix: Cross-platform hook compatibility for Windows#706chrisglick wants to merge 1 commit intodanielmiessler:mainfrom
chrisglick wants to merge 1 commit intodanielmiessler:mainfrom
Conversation
…anielmiessler#440, danielmiessler#543) Three categories of fixes applied to 10 hook/lib files: 1. HOME environment variable fallback chain: `process.env.HOME!` → `(process.env.HOME || process.env.USERPROFILE || require('os').homedir())` On macOS/Linux, HOME is always set (POSIX requirement), so the fallback chain is never reached — zero behavioral change. On Windows, HOME may be unset in cmd.exe contexts; USERPROFILE is the Windows equivalent. 2. Tilde path resolution (LoadContext.hook.ts): `~/.claude/...` hardcoded strings → `join(paiDir, ...)` Tilde expansion is a shell feature that doesn't work in Windows cmd.exe or when paths are used programmatically. 3. Cross-platform utilities (hooks/lib/paths.ts): - getHome(): HOME || USERPROFILE || os.homedir() - getTempPath(): os.tmpdir() instead of hardcoded /tmp/ - isWindows(): process.platform === 'win32' Also fixed identity.ts to use getSettingsPath() from paths.ts instead of hardcoding join(HOME, '.claude/settings.json'). Files changed: hooks/lib/paths.ts - Added 3 utility functions hooks/lib/identity.ts - Use getSettingsPath() import hooks/lib/algorithm-state.ts - HOME fallback hooks/AlgorithmTracker.hook.ts - HOME fallback hooks/AutoWorkCreation.hook.ts - HOME fallback hooks/RatingCapture.hook.ts - HOME fallback (2 locations) hooks/SessionSummary.hook.ts - HOME fallback hooks/WorkCompletionLearning.hook.ts - HOME fallback hooks/LoadContext.hook.ts - Tilde path → join() hooks/handlers/RebuildSkill.ts - HOME fallback + use CORE_DIR const Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
3 tasks
nsalvacao
added a commit
to nsalvacao/Personal_AI_Infrastructure
that referenced
this pull request
Feb 17, 2026
…hook compatibility)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
process.env.HOME!→(HOME || USERPROFILE || homedir())— prevents crash whenHOMEis unset on Windows~/.claude/...→join(paiDir, ...)— tilde doesn't expand in Windows cmd.exepaths.ts:getHome(),getTempPath(),isWindows()— reusable helpers for future hooksgetSettingsPath()from paths.ts instead of hardcodedjoin(HOME, '.claude/settings.json')Problem
Hooks crash on Windows with
TypeError: Cannot read properties of undefined (reading 'replace')or similar errors because:process.env.HOMEis undefined on Windows (it usesUSERPROFILEinstead)HOME!) crashes instead of falling back~) is a shell feature — it doesn't expand incmd.exeor in programmatic path constructionZero impact on macOS/Linux
On macOS/Linux,
HOMEis always set (POSIX requirement). The fallback toUSERPROFILEandhomedir()is never reached. Thejoin()path construction produces identical output to the tilde strings. These changes are dead code on Unix — they only activate on Windows whereHOMEis unset.Files changed (10)
hooks/lib/paths.tsgetHome(),getTempPath(),isWindows()hooks/lib/identity.tsgetSettingsPath()instead of hardcoded HOME pathhooks/lib/algorithm-state.tshooks/AlgorithmTracker.hook.tshooks/AutoWorkCreation.hook.tshooks/RatingCapture.hook.tshooks/SessionSummary.hook.tshooks/WorkCompletionLearning.hook.tshooks/LoadContext.hook.tsjoin(paiDir, ...)hooks/handlers/RebuildSkill.tsCORE_DIRconstRelation to #704
This is a companion to PR #704 (installer + documentation). That PR handles install-time path resolution in
settings.json. This PR handles runtime path resolution in hook source code. Together they provide complete Windows compatibility.Test plan
grep -r 'process.env.HOME!' hooks/returns zero resultsgrep -r '~/.claude/' hooks/LoadContext.hook.tsreturns zero resultsCloses #440, #543
🤖 Generated with Claude Code