{"record":{"id":"ca93b916a2bf01ff","repo":"abiosoft/colima","slug":"error-retrieving-current-working-directory-w","errorCode":null,"errorMessage":"error retrieving current working directory: %w","messagePattern":"error retrieving current working directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"app/app.go","lineNumber":313,"sourceCode":"\t}\n\n\tlog.Println(\"done\")\n\n\tif err := generateSSHConfig(false); err != nil {\n\t\tlog.Trace(\"error generating ssh_config: %w\", err)\n\t}\n\treturn nil\n}\n\nfunc (c colimaApp) SSH(args ...string) error {\n\tctx := context.Background()\n\tif !c.guest.Running(ctx) {\n\t\treturn fmt.Errorf(\"%s not running\", config.CurrentProfile().DisplayName)\n\t}\n\n\tworkDir, err := os.Getwd()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"error retrieving current working directory: %w\", err)\n\t}\n\t// peek the current directory to see if it is mounted to prevent `cd` errors\n\t// with limactl ssh\n\tif err := func() error {\n\t\tconf, err := configmanager.LoadInstance()\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tpwd, err := util.CleanPath(workDir)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tfor _, m := range conf.MountsOrDefault() {\n\t\t\tlocation := m.MountPoint\n\t\t\tif location == \"\" {\n\t\t\t\tlocation = m.Location\n\t\t\t}\n\t\t\tlocation, err := util.CleanPath(location)","sourceCodeStart":295,"sourceCodeEnd":331,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/app/app.go#L295-L331","documentation":"Inside SSH, colima resolves the current working directory with os.Getwd to check whether it is mounted in the guest (preventing cd errors with limactl ssh). This error means the process's cwd became invalid, typically a directory deleted or made unreadable while the shell was still in it.","triggerScenarios":"Invoking colima ssh from a directory that was removed (a cleaned tmp/project dir), an unmounted network volume, or a cwd with revoked permissions.","commonSituations":"A script runs in a scratch dir that another step deletes before calling colima ssh; cwd on an ejected/unmounted drive; permissions changed by another user.","solutions":["Change into an existing directory first: `cd ~ && colima ssh`","In scripts, invoke colima ssh from a stable directory (e.g. $HOME) instead of a temp workspace","Remount or restore access to the directory if it must be used","Avoid deleting the cwd of a long-lived shell session"],"exampleFix":"# before (cwd was deleted by a cleanup step)\ncd /tmp/build-42 && colima ssh\n\n# after\ncd \"$HOME\" && colima ssh","handlingStrategy":"validation","validationCode":"// ensure the cwd is still valid before ssh\nif wd, err := os.Getwd(); err != nil {\n    if cerr := os.Chdir(os.Getenv(\"HOME\")); cerr != nil {\n        return cerr\n    }\n} else if _, serr := os.Stat(wd); serr != nil {\n    if cerr := os.Chdir(os.Getenv(\"HOME\")); cerr != nil {\n        return cerr\n    }\n}","typeGuard":"func isCwdError(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"error retrieving current working directory\")\n}","tryCatchPattern":"if err := a.SSH(args...); err != nil {\n    if isCwdError(err) {\n        // the cwd vanished: chdir to $HOME and retry\n        if cerr := os.Chdir(os.Getenv(\"HOME\")); cerr == nil {\n            return a.SSH(args...)\n        }\n    }\n    return err\n}","preventionTips":["Launch colima ssh from stable directories like $HOME","Do not delete the working directory of running shells","In scripts, cd to a known-good dir before invoking colima"],"tags":["ssh","filesystem","cwd","precondition"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}