{"record":{"id":"1012d4046e2b74eb","repo":"gastownhall/beads","slug":"failed-to-get-current-directory-v","errorCode":null,"errorMessage":"failed to get current directory: %v","messagePattern":"failed to get current directory: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/bd/init.go","lineNumber":818,"sourceCode":"\t\t// (PersistentPreRun doesn't run for init command)\n\t\tif dbPath == \"\" {\n\t\t\tif envDB := os.Getenv(\"BEADS_DB\"); envDB != \"\" {\n\t\t\t\tdbPath = envDB\n\t\t\t}\n\t\t}\n\n\t\t// Determine prefix with precedence: flag > config > auto-detect from git > auto-detect from directory name\n\t\tif prefix == \"\" {\n\t\t\t// Try to get from config file\n\t\t\tprefix = config.GetString(\"issue-prefix\")\n\t\t}\n\n\t\t// auto-detect prefix from directory name\n\t\tif prefix == \"\" {\n\t\t\t// Auto-detect from directory name\n\t\t\tcwd, err := os.Getwd()\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"failed to get current directory: %v\", err)\n\t\t\t}\n\t\t\tprefix = filepath.Base(cwd)\n\t\t}\n\n\t\t// Normalize prefix before storing it in config or deriving the Dolt\n\t\t// database name. Dots are not valid in issue prefixes and must match the\n\t\t// underscore form used for DoltDatabase/metadata.json. Leading dots\n\t\t// produce invalid names (e.g. \".claude\" -> \"claude\"), the trailing\n\t\t// hyphen is added automatically during ID generation, and a leading\n\t\t// non-letter is prefixed with \"bd_\" so the derived MySQL identifier is\n\t\t// valid (directory names like \"001\" are common in temp dirs).\n\t\tprefix = normalizeIssuePrefix(prefix)\n\t\tremoteDivergenceConfirmed := false\n\n\t\t// Cross-boundary safety (bd-q83 / ADR 0002): check remote state\n\t\t// BEFORE any filesystem side-effects so a refusal exits cleanly.\n\t\t// We only refuse here; bootstrap decisions happen later once\n\t\t// beadsDir is computed. See CheckRemoteSafety in init_safety.go.","sourceCodeStart":800,"sourceCodeEnd":836,"githubUrl":"https://github.com/gastownhall/beads/blob/71377f276968b452ee607177637970a4ff888584/cmd/bd/init.go#L800-L836","documentation":"When --prefix was not supplied, bd init auto-derives the prefix from the current directory name. If os.Getwd() fails (usually because the working directory was deleted or is unreadable), init aborts with this wrapped error.","triggerScenarios":"Running `bd init` without --prefix in a shell whose CWD has been removed (deleted directory, re-created path, stale shell after worktree removal).","commonSituations":"Shell sitting in a deleted directory; container volume remounts; symlinked paths invalidated mid-session.","solutions":["cd into a valid directory (e.g. cd . or re-open the shell) and retry","Pass an explicit --prefix so os.Getwd() path is avoided","Check filesystem/mount health if the directory genuinely exists"],"exampleFix":"// before\nbd init                      # run from deleted dir\n// after\nbd init --prefix myproject   # or cd back into the project dir","handlingStrategy":"validation","validationCode":"[ -d \"$(pwd)\" ] || { echo \"CWD deleted; cd back\"; exit 1; }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Run cd . or cd \"$PROJECT_DIR\" after filesystem operations that remove/recreate paths","Always pass --prefix in scripts so Getwd is not needed for the prefix path","Re-open shells after worktree or volume changes"],"tags":["cli","filesystem","prefix","getwd"],"backgroundTag":"current-directory-unavailable","analyzedSha":"71377f276968b452ee607177637970a4ff888584","analyzedAt":"2026-08-30T18:55:39.744Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}