lima-vm/lima · error
expected the depth of the host working directory (%#q) to be
Error message
expected the depth of the host working directory (%#q) to be at least %d, only got %d (Hint: %s)
What it means
Rsync acts on the host working directory as the transfer root, so Lima requires the path to be at least `rsyncMinimumSrcDirDepth` components deep to avoid syncing an overly broad tree (e.g. a drive or home root). When the native host path's depth (counting extra Windows components like `/c/` or `/cygdrive/c/`) is below that minimum, shellAction aborts with this error.
Source
Thrown at cmd/limactl/shell.go:259
if err != nil {
// An empty hostCurrentDir would reach rsync as the toolchain root.
if syncHostWorkdir {
return fmt.Errorf("failed to determine the host directory to sync: %w", err)
}
changeDirCmd = "false"
logrus.WithError(err).Warn("failed to get the current directory")
}
if syncHostWorkdir {
if _, err := exec.LookPath(string(copytool.BackendRsync)); err != nil {
return fmt.Errorf("rsync is required for `--sync` but not found: %w", err)
}
// Measure the host's own path. The form hostCurrentDir carries on Windows
// adds one component (/c/...) or two (/cygdrive/c/...).
srcWdDepth := pathDepth(hostCurrentDirNative, runtime.GOOS == "windows")
if srcWdDepth < rsyncMinimumSrcDirDepth {
return fmt.Errorf("expected the depth of the host working directory (%#q) to be at least %d, only got %d (Hint: %s)",
hostCurrentDirNative, rsyncMinimumSrcDirDepth, srcWdDepth, "cd to a deeper directory")
}
// rsync acts on hostCurrentDir, so measure that too: cygpath can report
// success without writing a path, and an fstab can map a deep directory
// onto a shallow one. It is always POSIX form, even on Windows.
if dstWdDepth := pathDepth(hostCurrentDir, false); dstWdDepth < rsyncMinimumSrcDirDepth {
return fmt.Errorf("expected the depth of the converted host working directory (%#q) to be at least %d, only got %d",
hostCurrentDir, rsyncMinimumSrcDirDepth, dstWdDepth)
}
}
var destRsyncDir string
workDir, err := cmd.Flags().GetString("workdir")
if err != nil {
return err
}
if workDir != "" && syncHostWorkdir {
return errors.New("cannot use `--workdir` and `--sync` at the same time")View on GitHub (pinned to dd909d0973)
Solutions
- `cd` into a deeper, project-specific directory before running the command (as the error's Hint says).
- Pass an explicit deeper directory to `--sync <deep/dir>` instead of relying on the cwd.
- If you truly need to sync a shallow root, copy the tree into a deeper staging directory first.
Example fix
# before cd ~ && limactl shell default --sync # after cd ~/projects/myapp && limactl shell default --sync
Defensive patterns
Strategy: validation
Validate before calling
depth() { local p="$1"; local n=0; while [ "$p" != "/" ]; do n=$((n+1)); p=$(dirname "$p"); done; echo "$n"; }; [ "$(depth "$PWD")" -ge 3 ] || { echo 'cd to a deeper directory'; exit 1; } Type guard
null
Try / catch
null
Prevention
- Never run --sync from /, home, or drive roots; cd into the project first.
- Use explicit deep paths with `--sync <dir>` in scripts.
- Pin CI working directories to a project subdirectory, not the workspace root.
When it happens
Trigger: Running `limactl shell <instance> --sync <dir>` where `<dir>` (or the current directory) resolves to a shallow path such as `/`, `/home`, `/Users`, or on Windows a near-root path once the drive prefix components are counted.
Common situations: Developers `cd` to their home directory or drive root and run `--sync`, expecting only a small folder to sync; CI jobs running from a shallow workspace root like `/work`.
Related errors
- rsync is required for `--sync` but not found: %w
- expected the depth of the converted host working directory (
- failed to create the synced workdir in guest instance: %w
- failed to get rsync version: %w
- cannot use `--sync` when the instance has host mounts config
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/9b8b7bc5e0262e08.
Report an issue: GitHub.