can1357/oh-my-pi · critical · Error

Unable to determine an accessible working directory

Error message

Unable to determine an accessible working directory

What it means

getProjectDir() resolves the project directory by probing candidate working directories and chdir-ing into the first accessible one. If every candidate throws (e.g. deleted or permission-denied directories) and no project dir can be established, it throws this error. All downstream helpers (cwd, resolveTargetDir, absolutePath, component, makeMarketplaceManager, actionClient) depend on it, so nothing that needs a working directory can proceed.

Source

Thrown at packages/utils/src/dirs.ts:200

let projectDir: string | undefined;

/** Get the project directory. */
export function getProjectDir(): string {
	if (projectDir === undefined) {
		try {
			projectDir = standardizeMacOSPath(process.cwd());
		} catch {
			const candidates = [process.env.PWD, os.homedir(), os.tmpdir()];
			for (const candidate of candidates) {
				if (!candidate || !path.isAbsolute(candidate)) continue;
				try {
					process.chdir(candidate);
					projectDir = standardizeMacOSPath(candidate);
					break;
				} catch {}
			}
			if (projectDir === undefined) {
				throw new Error("Unable to determine an accessible working directory");
			}
		}
	}
	return projectDir;
}

/** Set the project directory. */
export function setProjectDir(dir: string): void {
	const resolved = standardizeMacOSPath(path.resolve(dir));
	process.chdir(resolved);
	projectDir = resolved;
}

/** Reset the cached project directory (test seam). */
export function __resetProjectDirCacheForTests(): void {
	projectDir = undefined;
}

View on GitHub (pinned to 9690622007)

Solutions

  1. Check that the process's current working directory exists and is accessible: run `pwd`/`ls` from the same context that launched the process.
  2. Relaunch the process from a valid, existing directory (e.g. `cd /path/to/project && omp ...`).
  3. Fix permissions on the directory (chmod/chown) so the process user can read and execute it.
  4. If the cwd was deleted at runtime, set an explicit project/config root env var or start from a stable directory instead of a temporary one.

Example fix

// before (launched from a dir that was deleted)
$ cd /tmp/build && rm -rf /tmp/build &
$ omp  // throws: Unable to determine an accessible working directory

// after
$ cd ~/projects/myapp && omp
Defensive patterns

Strategy: fallback

Validate before calling

import { existsSync, accessSync, constants } from "node:fs";
function isAccessibleDir(p: string): boolean {
  try { accessSync(p, constants.R_OK | constants.X_OK); return true; } catch { return false; }
}
if (!isAccessibleDir(process.cwd())) {
  process.chdir(isAccessibleDir("/tmp") ? "/tmp" : os.homedir());
}

Try / catch

try {
  const dir = getProjectDir();
} catch (err) {
  if (err instanceof Error && err.message === "Unable to determine an accessible working directory") {
    process.chdir(os.tmpdir()); // or fail fast with a clear startup message
  } else throw err;
}

Prevention

When it happens

Trigger: Calling any API that resolves the project dir (cwd(), resolveTargetDir(), absolutePath(), component(), makeMarketplaceManager(), actionClient) when the current working directory and all fallback candidates are inaccessible: deleted cwd, no read/execute permission, or running from a nonexistent directory.

Common situations: A shell or process manager spawned the process after its cwd was deleted (common with rm -rf of the launch dir); running inside a container with an invalid WORKDIR; permission-stripped sandbox environments; NFS/network mounts that dropped; launching from a path that no longer exists after a checkout switch.

Related errors


AI-assisted analysis of can1357/oh-my-pi@9690622007 (2026-08-31). Data as JSON: /api/errors/9a4cf9e883beafa2. Report an issue: GitHub.