{"record":{"id":"4e2bd03338af3be8","repo":"lima-vm/lima","slug":"cannot-use-workdir-and-sync-at-the-same-ti","errorCode":null,"errorMessage":"cannot use `--workdir` and `--sync` at the same time","messagePattern":"cannot use `--workdir` and `--sync` at the same time","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/limactl/shell.go","lineNumber":277,"sourceCode":"\t\t\treturn fmt.Errorf(\"expected the depth of the host working directory (%#q) to be at least %d, only got %d (Hint: %s)\",\n\t\t\t\thostCurrentDirNative, rsyncMinimumSrcDirDepth, srcWdDepth, \"cd to a deeper directory\")\n\t\t}\n\t\t// rsync acts on hostCurrentDir, so measure that too: cygpath can report\n\t\t// success without writing a path, and an fstab can map a deep directory\n\t\t// onto a shallow one. It is always POSIX form, even on Windows.\n\t\tif dstWdDepth := pathDepth(hostCurrentDir, false); dstWdDepth < rsyncMinimumSrcDirDepth {\n\t\t\treturn fmt.Errorf(\"expected the depth of the converted host working directory (%#q) to be at least %d, only got %d\",\n\t\t\t\thostCurrentDir, rsyncMinimumSrcDirDepth, dstWdDepth)\n\t\t}\n\t}\n\n\tvar destRsyncDir string\n\tworkDir, err := cmd.Flags().GetString(\"workdir\")\n\tif err != nil {\n\t\treturn err\n\t}\n\tif workDir != \"\" && syncHostWorkdir {\n\t\treturn errors.New(\"cannot use `--workdir` and `--sync` at the same time\")\n\t}\n\tif syncHostWorkdir {\n\t\tdestRsyncDir = *inst.Config.User.Home + hostCurrentDir\n\t}\n\thostHomeDir, err := os.UserHomeDir()\n\tif err == nil && runtime.GOOS == \"windows\" {\n\t\thostHomeDir, err = mountDirFromWindowsDir(ctx, inst, hostHomeDir)\n\t}\n\tif err != nil {\n\t\tlogrus.WithError(err).Warn(\"failed to get the home directory\")\n\t\thostHomeDir = \"\"\n\t}\n\n\tswitch {\n\tcase workDir != \"\":\n\t\tchangeDirCmd = fmt.Sprintf(\"cd %s || exit 1\", shellescape.Quote(workDir))\n\tcase mountsContainPath(inst.Config.Mounts, hostCurrentDir) || inst.VMType == limatype.WSL2:\n\t\tchangeDirCmd = fmt.Sprintf(\"cd %s\", shellescape.Quote(hostCurrentDir))","sourceCodeStart":259,"sourceCodeEnd":295,"githubUrl":"https://github.com/lima-vm/lima/blob/dd909d0973cd84fa35f9e1693181b4585ea616c1/cmd/limactl/shell.go#L259-L295","documentation":"`--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.","triggerScenarios":"Running `limactl shell <instance> --sync <dir> --workdir <guest-dir>` — both flags set on the same invocation.","commonSituations":"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.","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."],"exampleFix":"# before\nlimactl shell default --sync . --workdir /tmp/build\n# after\nlimactl shell default --sync .","handlingStrategy":"validation","validationCode":"[ -z \"$WORKDIR_FLAG\" ] || [ -z \"$SYNC_FLAG\" ] || { echo 'use --workdir or --sync, not both'; exit 1; }","typeGuard":"null","tryCatchPattern":"null","preventionTips":["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."],"tags":["cli","limactl","flags-conflict","sync","workdir"],"backgroundTag":"mutually-exclusive-flags","analyzedSha":"dd909d0973cd84fa35f9e1693181b4585ea616c1","analyzedAt":"2026-09-01T14:24:59.842Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}