openclaw - ✅(Solved) Fix [Bug]: CLI crashes when current working directory is deleted (uv_cwd error not handled) [2 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#73676Fetched 2026-04-29 06:16:35
View on GitHub
Comments
1
Participants
2
Timeline
7
Reactions
0
Timeline (top)
cross-referenced ×2labeled ×2referenced ×2commented ×1

CLI exits with uv_cwd error when the current working directory is deleted, without handling or fallback.

Error Message

Error output:

Error: ENOENT: no such file or directory, uv_cwd

Root Cause

CLI exits with uv_cwd error when the current working directory is deleted, without handling or fallback.

Fix Action

Fixed

PR fix notes

PR #73700: fix(cli): tolerate deleted cwd in shouldLoadCliDotEnv (#73676)

Description (problem / solution / changelog)

What

Fixes #73676. When the current working directory has been removed (cd into a directory, delete it from another shell, then run any CLI command), process.cwd() throws:

Error: ENOENT: no such file or directory, uv_cwd

Before this fix the exception escaped through shouldLoadCliDotEnv — which is called eagerly during CLI bootstrap — and aborted the entire CLI before any command (including openclaw tui) could run. Users had to manually cd to a valid directory just to recover.

Fix

Wrap the process.cwd() call in a try/catch in shouldLoadCliDotEnv. On throw, treat it as "no cwd-local .env" and fall through to the state-dir .env lookup, which already uses resolveStateDir(env) (does not depend on cwd).

let cwd: string | undefined;
try {
  cwd = process.cwd();
} catch {
  cwd = undefined;
}
if (cwd && existsSync(path.join(cwd, ".env"))) {
  return true;
}
return existsSync(path.join(resolveStateDir(env), ".env"));

shouldLoadCliDotEnv is also exported now so the regression test can pin the no-throw behavior with a process.cwd mock.

Pre-implement audit

  1. Existing-helper check (vincentkoc #57341). A safeCwd() helper exists in src/agents/bash-tools.shared.ts:186 (returns string | null on try { process.cwd() } catch { return null }), but it is module-private and used only by the bash-tool runtime path. Inlining the same 5-line guard at this CLI bootstrap site is cheaper than reshaping the helper into a shared infra export and adjusting both callers, and keeps the blast radius narrow. ✅
  2. Shared-helper caller check (steipete #60623). shouldLoadCliDotEnv was module-private; promoting it to export function gives the regression test access. The only in-file call site is line 324; no external contract change. ✅
  3. Broader-fix rival scan (steipete #68270). Zero rival PRs reference #73676. ✅

Verified locally

npx oxlint src/cli/run-main.ts src/cli/run-main.cwd-deleted.test.ts
# Found 0 warnings and 0 errors.

npx vitest run src/cli/run-main.cwd-deleted.test.ts src/cli/run-main.test.ts
# Tests  25 passed (25)

The new test mocks process.cwd to throw the canonical ENOENT … uv_cwd shape and asserts shouldLoadCliDotEnv does not throw and returns cleanly.

Note

This patch only touches the bootstrap-time shouldLoadCliDotEnv call. Other process.cwd() call sites (e.g. update-cli, proxy-cli) are not on the bare-CLI critical path that fires before any command resolves; if a user reports the same uv_cwd family throwing later in the lifecycle (e.g. mid-command), those can be addressed in follow-ups. The reporter explicitly identified openclaw tui as the failing path, which is gated by this exact bootstrap function.

lobster-biscuit: 73676-cli-cwd-deleted-crash

Sign-Off:

  • I have read and agree to the OpenClaw Contributor License Agreement.

Changed files

  • CHANGELOG.md (modified, +2/-0)
  • src/cli/run-main.cwd-deleted.test.ts (added, +43/-0)
  • src/cli/run-main.ts (modified, +14/-2)

PR #74062: fix(cli): handle uv_cwd error when working directory is deleted

Description (problem / solution / changelog)

Summary

Fixes #73676

CLI now gracefully handles the uv_cwd error that occurs when the current working directory has been deleted before running openclaw commands.

Changes

  • run-main.ts: Add safeProcessCwd() that catches uv_cwd error and exits with a clear message:
    Current working directory has been deleted. Please cd to a valid directory before running openclaw.
  • dotenv.ts: Add safeProcessCwd() fallback to HOME if cwd is deleted (error already surfaced in run-main.ts shouldLoadCliDotEnv())
  • skills-cli.ts: Add safeProcessCwd() that returns undefined to use default agent if cwd is deleted

Testing

Manually tested by:

  1. Creating and entering a directory: mkdir test-dir && cd test-dir
  2. Deleting the directory from another shell: rm -rf ../test-dir
  3. Running openclaw tui - now shows clear error message instead of crash

Security

No security implications. Purely error handling improvement for better UX.

Notes

  • Pattern follows existing error handling in run-main.ts (using console.error and process.exit(1))
  • Error message matches similar cwd issues in other CLIs (npm, etc.)
  • Fallback paths use HOME/USERPROFILE or "/" as safe defaults

Changed files

  • src/cli/dotenv.ts (modified, +11/-1)
  • src/cli/run-main.ts (modified, +14/-1)
  • src/cli/skills-cli.ts (modified, +10/-1)

Code Example

Error output:

Error: ENOENT: no such file or directory, uv_cwd
RAW_BUFFERClick to expand / collapse

Bug type

Behavior bug (incorrect output/state without crash)

Beta release blocker

No

Summary

CLI exits with uv_cwd error when the current working directory is deleted, without handling or fallback.

Steps to reproduce

  1. Create and enter a directory: mkdir test-dir cd test-dir

  2. Delete the directory: rm -rf ../test-dir

  3. Run: openclaw tui

  4. Observe error

Expected behavior

CLI should handle missing working directory and provide a clear error or fallback.

Actual behavior

CLI exits with:

Error: ENOENT: no such file or directory, uv_cwd

OpenClaw version

2026.4.24

Operating system

macOS 15.4

Install method

npm global

Model

NOT_RELEVANT

Provider / routing chain

NOT_RELEVANT

Additional provider/model setup details

NOT_RELEVANT

Logs, screenshots, and evidence

Error output:

Error: ENOENT: no such file or directory, uv_cwd

Impact and severity

Affected: CLI users Severity: Medium (command cannot run) Frequency: Reproducible when cwd is removed Consequence: Requires manual recovery (cd to another directory)

Additional information

This behavior also occurs with npm commands in the same environment.

extent analysis

TL;DR

The CLI should be modified to handle the case when the current working directory is deleted, providing a clear error message or fallback instead of exiting with a uv_cwd error.

Guidance

  • Check the current working directory before executing the CLI command to anticipate potential directory deletion issues.
  • Implement a try-catch block to catch the uv_cwd error and provide a user-friendly error message or fallback directory.
  • Consider using a temporary directory or a default fallback directory when the current working directory is not accessible.
  • Review the openclaw tui command to ensure it properly handles directory changes and deletions.

Example

try {
  const cwd = process.cwd();
  // execute openclaw tui command
} catch (error) {
  if (error.code === 'ENOENT' && error.syscall === 'uv_cwd') {
    console.error('Error: Current working directory has been deleted. Please change to a valid directory.');
    // provide fallback or exit with a clear error message
  } else {
    throw error;
  }
}

Notes

This solution assumes that the openclaw tui command is executed in a Node.js environment and that the process.cwd() function is used to get the current working directory.

Recommendation

Apply workaround: Modify the CLI to handle the uv_cwd error and provide a clear error message or fallback directory, as this is a specific and reproducible issue that can be addressed with a targeted code change.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

CLI should handle missing working directory and provide a clear error or fallback.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

openclaw - ✅(Solved) Fix [Bug]: CLI crashes when current working directory is deleted (uv_cwd error not handled) [2 pull requests, 1 comments, 2 participants]