fix: expand literal $HOME in injected env path vars (LIFEOS_DIR/LIFEOS_CONFIG_DIR/PROJECTS_DIR) — fixes #1404 shadow-$HOME directories and orphaned learning data - #1451
Merged
danielmiessler merged 1 commit intoJul 9, 2026
Conversation
…G_DIR / PROJECTS_DIR) — closes the danielmiessler#1404 shadow-directory bug Claude Code injects settings.json env values verbatim, without shell expansion, so the shipped settings.system.json values like "$HOME/.claude/LIFEOS" reach every hook/tool as a literal string. Because "$HOME/..." is a relative path, fs writes resolve under the process cwd — every session grows a junk directory literally named '$HOME/' containing shadow MEMORY/LEARNING/STATE trees, and learning captures (FailureCapture, SatisfactionCapture ratings) are silently orphaned there instead of landing in the real tree. Fix (consumer-side, keeps settings.system.json portable): - 64 TS consumers: normalize LIFEOS_DIR / LIFEOS_CONFIG_DIR / PROJECTS_DIR in process.env at module load — if the value starts with a literal $HOME / ${HOME}, expand it before any path math. hooks/lib/paths.ts (already expands) and Safety.hook.ts (own expansion) untouched. - LIFEOS_StatusLine.sh: bash ${LIFEOS_DIR:-...} keeps the literal env value without re-expanding, so expand $HOME/${HOME}/~ prefixes explicitly after the default assignment.
Owner
|
Merged — thank you. The diagnosis is exactly right, and the before/after repro made it easy to verify. Two notes on how this landed on my side: this repo is regenerated from my private source tree at release time, so I ported the fix there as well. It applied cleanly everywhere except four files that no longer exist in the 7.x tree, which will drop out of the next release. And your install-time expansion idea is a good complement — I may add that in the scaffolder so future consumers are covered without per-file blocks. Appreciate the testing evidence. Fixes like this are why I love running this project in the open. |
aristo-Cat
added a commit
to aristo-Cat/LifeOS
that referenced
this pull request
Jul 13, 2026
BLOCKERs: - InstallSettings.ts (src+mirror): home = HOME||USERPROFILE||homedir() (was || "" → wrote literal $HOME/.claude into settings.json, danielmiessler#1404/danielmiessler#1451). - LIFEOS_StatusLine.ps1: expand literal $HOME/~ then export HOME+LIFEOS_DIR as MSYS paths (cygpath-style) so the bash fail-closed guard (danielmiessler#1463) accepts them instead of collapsing to bare 'LifeOS'. ADAPTs (each a win32 branch / homedir fallback): - Doctor.ts: which() -> Bun.which (PATHEXT-aware); chromeBinary() win32 paths (Chrome/Edge/Brave); HOME fallback. - CarrierProbe.ts: slug regex /[\/:.]/ (verified vs real C--Users-juanc--claude); resolveClaudeBin() win32 .exe via where (shell:false safe); honor CLAUDE_CONFIG_DIR. - MemoryHealthCheck.ts: HOME fallback + CLAUDE_CONFIG_DIR (every-turn hook nag). - FailureCapture.ts: drop process.env.HOME! non-null assert -> homedir fallback. Verified no-change: AlgorithmNudge.hook.ts already registered in hooks.json; InstallHooks.toWindowsHookCommand wraps every hook with $env:HOME set (danielmiessler#8/danielmiessler#9).
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.
Problem (#1404)
Claude Code injects
settings.jsonenv values verbatim — never shell-expanded — so the shippedsettings.system.jsonvaluesreach every hook/tool as literal strings. Since
$HOME/...is a relative path,fswrites resolve under the process cwd: every working directory a session runs in silently grows a junk directory literally named$HOME/containing shadowMEMORY/LEARNING/STATEtrees.Beyond the junk directories, this loses data: on our install,
FailureCapturewrote a full failure record (including a ~950 KB transcript) andSatisfactionCapturewrote sentiment notes and 27 rating lines into shadow trees instead of the realMEMORY/LEARNING— invisible toMemoryRetriever, the statusline ratings display, and the learning loop.Fix (consumer-side;
settings.system.jsonstays portable)process.env.LIFEOS_DIR/LIFEOS_CONFIG_DIR/PROJECTS_DIRget a small normalization block at module load: if the value starts with a literal$HOME/${HOME}, expand it inprocess.envbefore any path math. Idempotent, no imports, no behavior change when the value is already absolute.hooks/lib/paths.ts(already expands viaexpandPath) andSafety.hook.ts(own inline expansion) are untouched.LIFEOS_StatusLine.sh: bash${LIFEOS_DIR:-…}keeps an already-set literal value without re-expanding it, so the script now expands$HOME/${HOME}/~/prefixes explicitly right after the default assignment. This is the offender that continuously regrows the junk trees on established installs (model/weather/location/version caches every statusline tick), as also reported in the settings.system.json env values ship a literal, unexpanded $HOME — breaks USER scaffold on fresh installs (regression of the #1124 / #1270 class) #1404 comments.Deliberately not changed: the
$HOMEform insettings.system.json(it's the portable template; expanding it at install time would also work and could be done as a complement — happy to add that if preferred). The consumer-side fix makes the code correct for existing installs too, which already have the literal value baked into theirsettings.json.Testing evidence
Tested on a live LifeOS v6.0.5 install (macOS, Claude Code, bun 1.2.x) carrying the same bug — three shadow
$HOMEtrees had accumulated (in~/code,~/Compass, and~/.claude).Reproduction of what Claude Code does — run offenders from a pristine cwd with the literal env value:
/tmp/proof-cwd/$HOME/.claude/LIFEOS/...appears, containingMEMORY/STATE/model-cache.txt,USER/CACHE/freshness.json,OBSERVABILITY/format-gate.jsonl.~/.claude/LIFEOS/...paths with fresh mtimes (verified for statusline caches, freshness cache, and format-gate telemetry).Bun.Transpilerparse check;bash -npasses on the statusline; the diff is insert-only (453 insertions, 0 deletions).Fixes #1404 (fresh-install scaffold breakage has the same root cause;
ScaffoldUser.ts/LinkUser.ts/SeedPulse.tsare among the patched consumers).