Skip to content

fix: default workdir to ~/.openclaw instead of cwd#1560

Open
gregb100 wants to merge 1 commit intoopenclaw:mainfrom
gregb100:fix/default-workdir-to-openclaw
Open

fix: default workdir to ~/.openclaw instead of cwd#1560
gregb100 wants to merge 1 commit intoopenclaw:mainfrom
gregb100:fix/default-workdir-to-openclaw

Conversation

@gregb100
Copy link
Copy Markdown

@gregb100 gregb100 commented Apr 6, 2026

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 cwd to ~/.openclaw. Skills installed via clawhub now land in ~/.openclaw/<skill> by default instead of cwd/skills/.

Priority order (unchanged except for last item)

  1. Explicit --workdir flag
  2. CLAWHUB_WORKDIR / CLAWDHUB_WORKDIR env vars
  3. .clawhub marker directory in cwd
  4. clawdbot workspace (if set)
  5. ~/.openclaw (was cwd)

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)
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Apr 6, 2026

@gregb100 is attempting to deploy a commit to the 0xBuns Team on Vercel.

A member of the Team first needs to authorize it.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 6, 2026

Greptile Summary

This PR updates resolveWorkdir in packages/clawhub/src/cli.ts so that when no explicit workdir is configured (no --workdir flag, no CLAWHUB_WORKDIR env var, no .clawhub marker in cwd, and no clawdbot workspace), skills default to ~/.openclaw instead of the current working directory. The change is minimal and preserves the existing resolution priority order.

  • The logic restructuring (splitting the one-liner into an early if return) is clean and readable.
  • Cross-platform concern: process.env.HOME ?? \"\" is used to locate the home directory. On Windows, HOME is not set by default — USERPROFILE is used instead. The empty-string fallback causes path.resolve(\"\", \".openclaw\") to silently resolve to <cwd>/.openclaw, defeating the purpose of the change on that platform. The fix is to use os.homedir() from Node's standard library, which handles this correctly on all platforms.

Confidence Score: 3/5

Safe 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 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.

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");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 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:

Suggested change
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.

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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");
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

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");
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using process.env.HOME ?? "" instead of the established resolveHome() helper causes cross-platform issues on Windows and incorrect fallback behavior.

Fix on Vercel

@momothemage
Copy link
Copy Markdown
Member

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.

@gregb100
Copy link
Copy Markdown
Author

no worries.
~/.npm-global/lib/node_modules/openclaw/skills/ — 55 bundled skills (OpenClaw team), none used
• ~/workspaces/otto/skills/ — 27 custom clawhub-installed skills, all in use
• The two paths are completely separate by design, but clawhub install defaults to cwd, so skills land wherever you ran the command

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:

  1. clawhub install scatters skills wherever you happen to run it from
  2. The symlink clara → ~/projects/clara/skills triggers the sandboxing warning because it resolves outside the workspace root — that's the Skipping skill path that resolves outside its configured root WARN you see 2x every ~30s
  3. No clean separation between "OpenClaw-bundled" vs "custom-installed" skills

My proposed fix: ~/.openclaw/ as clawhub's default would give a predictable, centralized location for custom skills that's:

• Not workspace-dependent
• Not mixed with npm-bundled skills
• Easy to back up / manage as a unit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants