fix: default workdir to ~/.openclaw instead of cwd#1560
fix: default workdir to ~/.openclaw instead of cwd#1560gregb100 wants to merge 1 commit intoopenclaw:mainfrom
Conversation
Avoids mixing npm bundled skills with custom clawhub skills when installing from arbitrary working directories. Custom skills now land in ~/.openclaw/<skill> by default instead of cwd/skills/. Priority order: 1. Explicit --workdir flag 2. CLAWHUB_WORKDIR / CLAWDHUB_WORKDIR env vars 3. .clawhub marker directory in cwd 4. clawdbot workspace (if set) 5. ~/.openclaw (NEW - was cwd)
|
@gregb100 is attempting to deploy a commit to the 0xBuns Team on Vercel. A member of the Team first needs to authorize it. |
Greptile SummaryThis PR updates
Confidence Score: 3/5Safe to merge on Unix/macOS, but silently misbehaves on Windows due to the HOME env var assumption. The change achieves its stated goal correctly on Unix/macOS. However, using process.env.HOME instead of os.homedir() is a cross-platform bug — on Windows, HOME is typically not set, so the empty-string fallback causes resolve to use cwd, defeating the stated purpose of the PR on that platform. packages/clawhub/src/cli.ts line 109 — HOME env var fallback should be replaced with os.homedir(). Prompt To Fix All With AIThis is a comment left during a code review.
Path: packages/clawhub/src/cli.ts
Line: 109
Comment:
**`process.env.HOME` is not portable — use `os.homedir()`**
On Windows, `HOME` is typically not set (the platform uses `USERPROFILE` instead). When `HOME` is `undefined`, `process.env.HOME ?? ""` produces an empty string, and `path.resolve("", ".openclaw")` resolves to `<cwd>/.openclaw` — silently falling back to the cwd-relative behavior this PR is specifically trying to avoid.
Node's built-in `os.homedir()` resolves the home directory correctly on all platforms (Windows, macOS, Linux) and should be used here instead:
```suggestion
return resolve(homedir(), ".openclaw");
```
You'll also need to add the import at the top of the file:
```ts
import { homedir } from "node:os";
```
How can I resolve this? If you propose a fix, please make it concise.Reviews (1): Last reviewed commit: "fix: default workdir to ~/.openclaw inst..." | Re-trigger Greptile |
| return clawdbotWorkspace ? resolve(clawdbotWorkspace) : cwd; | ||
| if (clawdbotWorkspace) return resolve(clawdbotWorkspace); | ||
| // Default to ~/.openclaw instead of cwd to avoid mixing npm skills with custom skills | ||
| return resolve(process.env.HOME ?? "", ".openclaw"); |
There was a problem hiding this comment.
process.env.HOME is not portable — use os.homedir()
On Windows, HOME is typically not set (the platform uses USERPROFILE instead). When HOME is undefined, process.env.HOME ?? "" produces an empty string, and path.resolve("", ".openclaw") resolves to <cwd>/.openclaw — silently falling back to the cwd-relative behavior this PR is specifically trying to avoid.
Node's built-in os.homedir() resolves the home directory correctly on all platforms (Windows, macOS, Linux) and should be used here instead:
| return resolve(process.env.HOME ?? "", ".openclaw"); | |
| return resolve(homedir(), ".openclaw"); |
You'll also need to add the import at the top of the file:
import { homedir } from "node:os";Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/clawhub/src/cli.ts
Line: 109
Comment:
**`process.env.HOME` is not portable — use `os.homedir()`**
On Windows, `HOME` is typically not set (the platform uses `USERPROFILE` instead). When `HOME` is `undefined`, `process.env.HOME ?? ""` produces an empty string, and `path.resolve("", ".openclaw")` resolves to `<cwd>/.openclaw` — silently falling back to the cwd-relative behavior this PR is specifically trying to avoid.
Node's built-in `os.homedir()` resolves the home directory correctly on all platforms (Windows, macOS, Linux) and should be used here instead:
```suggestion
return resolve(homedir(), ".openclaw");
```
You'll also need to add the import at the top of the file:
```ts
import { homedir } from "node:os";
```
How can I resolve this? If you propose a fix, please make it concise.There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 84c18d2f77
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return clawdbotWorkspace ? resolve(clawdbotWorkspace) : cwd; | ||
| if (clawdbotWorkspace) return resolve(clawdbotWorkspace); | ||
| // Default to ~/.openclaw instead of cwd to avoid mixing npm skills with custom skills | ||
| return resolve(process.env.HOME ?? "", ".openclaw"); |
There was a problem hiding this comment.
Resolve fallback workdir from actual home directory
When HOME is unset (common on Windows and some non-login shells), resolve(process.env.HOME ?? '', '.openclaw') resolves to <cwd>/.openclaw instead of the user's home folder, so installs still go under the current project and can mix unrelated skills. This regresses the stated behavior change for those environments; the fallback should use a cross-platform home resolver (e.g. include USERPROFILE/os.homedir()) rather than an empty-string path segment.
Useful? React with 👍 / 👎.
|
Thanks for the contribution! We really appreciate your effort and the work you've put into this PR. A small question: what is the actual reason for separating skills into two distinct paths for management? It seems unnecessary to manage the same type of resource in two separate paths. |
|
no worries. Why the split exists: OpenClaw's skill loader searches multiple directories (openclaw-extra, openclaw-workspace, openclaw-user), and the workspace path lets different agents have different skill sets. clawhub defaults to cwd for portability. Why it's messy:
My proposed fix: ~/.openclaw/ as clawhub's default would give a predictable, centralized location for custom skills that's: • Not workspace-dependent |
Problem
clawhub install defaults to cwd, which means where you run it from determines where skills land. Skills from two completely different sources (OpenClaw team bundled skills vs custom clawhub skills) end up mixed in one directory with no way to tell them apart.
Solution
Change the default workdir fallback from
cwdto~/.openclaw. Skills installed via clawhub now land in~/.openclaw/<skill>by default instead ofcwd/skills/.Priority order (unchanged except for last item)
--workdirflagCLAWHUB_WORKDIR/CLAWDHUB_WORKDIRenv vars.clawhubmarker directory in cwd~/.openclaw(wascwd)