lima-vm/lima · error
cannot use `--workdir` and `--sync` at the same time
Error message
cannot use `--workdir` and `--sync` at the same time
What it means
`--workdir` picks an explicit guest working directory while `--sync` makes the guest cwd a synced copy of the host directory; the two are mutually exclusive because each dictates a different destination directory. shellAction rejects a command that specifies both.
Source
Thrown at cmd/limactl/shell.go:277
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")
}
if syncHostWorkdir {
destRsyncDir = *inst.Config.User.Home + hostCurrentDir
}
hostHomeDir, err := os.UserHomeDir()
if err == nil && runtime.GOOS == "windows" {
hostHomeDir, err = mountDirFromWindowsDir(ctx, inst, hostHomeDir)
}
if err != nil {
logrus.WithError(err).Warn("failed to get the home directory")
hostHomeDir = ""
}
switch {
case workDir != "":
changeDirCmd = fmt.Sprintf("cd %s || exit 1", shellescape.Quote(workDir))
case mountsContainPath(inst.Config.Mounts, hostCurrentDir) || inst.VMType == limatype.WSL2:
changeDirCmd = fmt.Sprintf("cd %s", shellescape.Quote(hostCurrentDir))View on GitHub (pinned to dd909d0973)
Solutions
- Remove `--workdir` and let the synced host directory become the guest cwd.
- Or remove `--sync` if the explicit guest `--workdir` is what you actually need.
- If the goal is a synced copy at a specific guest location, use `--sync` alone; the destination is derived from the host path.
Example fix
# before limactl shell default --sync . --workdir /tmp/build # after limactl shell default --sync .
Defensive patterns
Strategy: validation
Validate before calling
[ -z "$WORKDIR_FLAG" ] || [ -z "$SYNC_FLAG" ] || { echo 'use --workdir or --sync, not both'; exit 1; } Type guard
null
Try / catch
null
Prevention
- In wrapper scripts, expose --workdir and --sync as mutually exclusive options and validate with getopts.
- Choose one workflow per instance: explicit guest workdir OR host-dir sync.
- Read `limactl shell --help` flag docs before combining directory-related flags.
When it happens
Trigger: Running `limactl shell <instance> --sync <dir> --workdir <guest-dir>` — both flags set on the same invocation.
Common situations: A developer who normally uses `--workdir` to jump into a project dir inside the guest adds `--sync` to also isolate host files, not realizing the flags conflict.
Understand the failure class
Background: "mutually exclusive" flag errors: what "can't supply both nx and xx", "--raw is not compatible with -i" and "cannot be used with" mean, and how to fix them — this error's family across 29 libraries.
Related errors
- cannot use `--sync` when the instance has host mounts config
- cannot use `--sync` with a wsl2 instance, the host directory
- failed to determine the host directory to sync: %w
- rsync is required for `--sync` but not found: %w
- expected the depth of the host working directory (%#q) to be
AI-assisted analysis of lima-vm/lima@dd909d0973 (2026-09-01).
Data as JSON: /api/errors/4e2bd03338af3be8.
Report an issue: GitHub.