{"record":{"id":"137b9128f810f5e5","repo":"gastownhall/beads","slug":"failed-to-get-current-directory-w","errorCode":null,"errorMessage":"failed to get current directory: %w","messagePattern":"failed to get current directory: %w","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/worktree_cmd.go","lineNumber":378,"sourceCode":"\t)\n}\n\nfunc (err *worktreeRemovalPartialError) Unwrap() error {\n\treturn err.err\n}\n\nfunc runWorktreeInfo(cmd *cobra.Command, args []string) error {\n\tevt := metrics.NewCommandEvent(\"worktree-info\")\n\tdefer func() {\n\t\tif c := metrics.Global(); c != nil {\n\t\t\tc.CloseEventAndAdd(evt)\n\t\t}\n\t}()\n\n\tctx := context.Background()\n\tcwd, err := os.Getwd()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get current directory: %w\", err)\n\t}\n\n\t// Check if we're in a worktree (use RepoContext if available, fallback to git)\n\tvar isWorktree bool\n\trc, rcErr := beads.GetRepoContext()\n\tif rcErr == nil {\n\t\tisWorktree = rc.IsWorktree\n\t} else {\n\t\tisWorktree = git.IsWorktree()\n\t}\n\n\tif !isWorktree {\n\t\tif jsonOutput {\n\t\t\tresult := map[string]interface{}{\n\t\t\t\t\"is_worktree\": false,\n\t\t\t}\n\t\t\tencoder := json.NewEncoder(os.Stdout)\n\t\t\tencoder.SetIndent(\"\", \"  \")","sourceCodeStart":360,"sourceCodeEnd":396,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/worktree_cmd.go#L360-L396","documentation":"`bd worktree info` needs the current working directory (via os.Getwd) to report worktree name/path/branch. If the OS cannot resolve the CWD, the command aborts with this error wrapping the underlying syscall error. This happens when the directory the shell is sitting in has been deleted or is otherwise unresolvable.","triggerScenarios":"Running `bd worktree info` while the shell's working directory has been removed (e.g. a deleted worktree), or Getwd fails due to permission issues or PATH_MAX-length paths on some platforms.","commonSituations":"A git worktree was pruned/removed while the terminal was still cd'd into it; CI containers deleting the workspace before running bd; NFS/network mounts that have gone stale.","solutions":["cd to an existing directory (e.g. the main repo root) and rerun the command","Verify the directory exists: pwd / ls the path; recreate the worktree if it was deleted","If PATH_MAX is the cause, shorten the repository path (move repo closer to filesystem root)"],"exampleFix":"// before (shell)\ncd /repos/old-worktree && bd worktree info   # directory deleted\n// after\ncd /repos/main && bd worktree info","handlingStrategy":"validation","validationCode":"if cwd, err := os.Getwd(); err != nil {\n    // cd to a valid directory before running: bd worktree info\n    fmt.Println(\"working directory unresolvable; cd to repo root first\")\n}","typeGuard":null,"tryCatchPattern":"if _, err := os.Getwd(); err != nil {\n    return fmt.Errorf(\"cwd unavailable: %w\", err)\n}\n// then run: bd worktree info","preventionTips":["Always run bd from an existing directory","Recreate pruned worktrees before operating inside them","Avoid extremely long repo paths near PATH_MAX"],"tags":["go","filesystem","cwd","worktree"],"backgroundTag":"current-directory-unresolvable","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}