[PR #299] [MERGED] fix: prefer $HOME over os.homedir() for path resolution #321

Closed
opened 2026-02-15 17:16:53 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/openclaw/clawhub/pull/299
Author: @superlowburn
Created: 2/14/2026
Status: Merged
Merged: 2/15/2026
Merged by: @steipete

Base: mainHead: fix/use-home-env-over-homedir


📝 Commits (2)

  • 14e5b64 fix: prefer $HOME over os.homedir() for path resolution
  • e588180 fix: normalize resolveHome output

📊 Changes

6 files changed (+75 additions, -11 deletions)

View changed files

📝 packages/clawdhub/src/cli/clawdbotConfig.test.ts (+35 -0)
📝 packages/clawdhub/src/cli/clawdbotConfig.ts (+4 -4)
📝 packages/clawdhub/src/cli/commands/syncHelpers.ts (+3 -3)
📝 packages/clawdhub/src/cli/scanSkills.ts (+2 -2)
📝 packages/clawdhub/src/config.ts (+2 -2)
packages/clawdhub/src/homedir.ts (+29 -0)

📄 Description

Summary

  • Adds a resolveHome() helper that prefers $HOME (Linux/macOS) or %USERPROFILE% (Windows) over os.homedir(), with fallback to os.homedir()
  • Replaces all os.homedir() calls in path resolution with resolveHome()
  • Adds test verifying $HOME override works for tilde expansion and workspace resolution

Problem

clawhub install fails with EACCES: permission denied, mkdir '/home/olduser' after a Linux user rename (usermod -l). This happens because Node.js os.homedir() reads from /etc/passwd (via getpwuid()), which can retain the old home directory path after a rename. The $HOME environment variable is set by the login process and correctly reflects the current session.

clawhub search is unaffected because it only makes API calls and never touches the filesystem path derived from homedir().

Fix

A new resolveHome() function in packages/clawdhub/src/homedir.ts checks $HOME first (or %USERPROFILE% on Windows), falling back to os.homedir() when the env var is unset. This is applied to all 7 callsites across 4 files:

  • clawdbotConfig.ts — state dir resolution (~/.clawdbot, ~/.openclaw) and tilde expansion in resolveUserPath()
  • scanSkills.ts — fallback skill root paths
  • config.ts — global config path resolution
  • syncHelpers.ts — display path abbreviation

On properly configured systems where $HOME == os.homedir(), behavior is identical. Only users with stale /etc/passwd entries benefit.

Test plan

  • All 90 existing tests pass (16 test files)
  • New test: verifies $HOME overrides os.homedir() for tilde expansion and workspace resolution
  • Verified zero remaining homedir() calls in production code (only in homedir.ts itself)

Closes #82

🤖 Generated with Claude Code

Greptile Overview

Greptile Summary

Replaces os.homedir() with a new resolveHome() helper that prefers environment variables ($HOME on Unix/macOS, %USERPROFILE% on Windows) over Node.js's os.homedir(). This fixes an EACCES error that occurs when Linux users rename their accounts with usermod -l, as os.homedir() reads from /etc/passwd which may contain stale home directory paths, while $HOME is set by the login shell and reflects the current session.

Changes applied:

  • Added new packages/clawdhub/src/homedir.ts module with resolveHome() function
  • Replaced all 7 os.homedir() callsites across 4 files with resolveHome()
  • Added test verifying $HOME override works correctly for tilde expansion
  • Proper fallback chain handles edge cases (empty strings, whitespace-only values)

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The implementation is straightforward and well-tested. All 7 callsites were correctly replaced, the fallback logic handles edge cases properly (empty strings, whitespace), and existing tests pass. The change is isolated to path resolution and maintains backward compatibility for systems where $HOME equals os.homedir()
  • No files require special attention

Last reviewed commit: 14e5b64


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/openclaw/clawhub/pull/299 **Author:** [@superlowburn](https://github.com/superlowburn) **Created:** 2/14/2026 **Status:** ✅ Merged **Merged:** 2/15/2026 **Merged by:** [@steipete](https://github.com/steipete) **Base:** `main` ← **Head:** `fix/use-home-env-over-homedir` --- ### 📝 Commits (2) - [`14e5b64`](https://github.com/openclaw/clawhub/commit/14e5b644b55ade1ce66645594ed58711e69d2db9) fix: prefer $HOME over os.homedir() for path resolution - [`e588180`](https://github.com/openclaw/clawhub/commit/e588180ff43e23f9f72f7ff6a925580db1616875) fix: normalize resolveHome output ### 📊 Changes **6 files changed** (+75 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `packages/clawdhub/src/cli/clawdbotConfig.test.ts` (+35 -0) 📝 `packages/clawdhub/src/cli/clawdbotConfig.ts` (+4 -4) 📝 `packages/clawdhub/src/cli/commands/syncHelpers.ts` (+3 -3) 📝 `packages/clawdhub/src/cli/scanSkills.ts` (+2 -2) 📝 `packages/clawdhub/src/config.ts` (+2 -2) ➕ `packages/clawdhub/src/homedir.ts` (+29 -0) </details> ### 📄 Description ## Summary - Adds a `resolveHome()` helper that prefers `$HOME` (Linux/macOS) or `%USERPROFILE%` (Windows) over `os.homedir()`, with fallback to `os.homedir()` - Replaces all `os.homedir()` calls in path resolution with `resolveHome()` - Adds test verifying `$HOME` override works for tilde expansion and workspace resolution ## Problem `clawhub install` fails with `EACCES: permission denied, mkdir '/home/olduser'` after a Linux user rename (`usermod -l`). This happens because Node.js `os.homedir()` reads from `/etc/passwd` (via `getpwuid()`), which can retain the old home directory path after a rename. The `$HOME` environment variable is set by the login process and correctly reflects the current session. `clawhub search` is unaffected because it only makes API calls and never touches the filesystem path derived from `homedir()`. ## Fix A new `resolveHome()` function in `packages/clawdhub/src/homedir.ts` checks `$HOME` first (or `%USERPROFILE%` on Windows), falling back to `os.homedir()` when the env var is unset. This is applied to all 7 callsites across 4 files: - `clawdbotConfig.ts` — state dir resolution (`~/.clawdbot`, `~/.openclaw`) and tilde expansion in `resolveUserPath()` - `scanSkills.ts` — fallback skill root paths - `config.ts` — global config path resolution - `syncHelpers.ts` — display path abbreviation On properly configured systems where `$HOME == os.homedir()`, behavior is identical. Only users with stale `/etc/passwd` entries benefit. ## Test plan - [x] All 90 existing tests pass (16 test files) - [x] New test: verifies `$HOME` overrides `os.homedir()` for tilde expansion and workspace resolution - [x] Verified zero remaining `homedir()` calls in production code (only in `homedir.ts` itself) Closes #82 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- greptile_comment --> <h2>Greptile Overview</h2> <h3>Greptile Summary</h3> Replaces `os.homedir()` with a new `resolveHome()` helper that prefers environment variables (`$HOME` on Unix/macOS, `%USERPROFILE%` on Windows) over Node.js's `os.homedir()`. This fixes an `EACCES` error that occurs when Linux users rename their accounts with `usermod -l`, as `os.homedir()` reads from `/etc/passwd` which may contain stale home directory paths, while `$HOME` is set by the login shell and reflects the current session. Changes applied: - Added new `packages/clawdhub/src/homedir.ts` module with `resolveHome()` function - Replaced all 7 `os.homedir()` callsites across 4 files with `resolveHome()` - Added test verifying `$HOME` override works correctly for tilde expansion - Proper fallback chain handles edge cases (empty strings, whitespace-only values) <h3>Confidence Score: 5/5</h3> - This PR is safe to merge with minimal risk - The implementation is straightforward and well-tested. All 7 callsites were correctly replaced, the fallback logic handles edge cases properly (empty strings, whitespace), and existing tests pass. The change is isolated to path resolution and maintains backward compatibility for systems where $HOME equals os.homedir() - No files require special attention <sub>Last reviewed commit: 14e5b64</sub> <!-- greptile_other_comments_section --> <!-- /greptile_comment --> --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-02-15 17:16:53 -05:00
yindo closed this issue 2026-02-15 17:16:53 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: openclaw/clawhub#321