gastownhall/beads · error

failed to get current directory: %v

Error message

failed to get current directory: %v

What it means

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.

Source

Thrown at cmd/bd/init.go:818

		// (PersistentPreRun doesn't run for init command)
		if dbPath == "" {
			if envDB := os.Getenv("BEADS_DB"); envDB != "" {
				dbPath = envDB
			}
		}

		// Determine prefix with precedence: flag > config > auto-detect from git > auto-detect from directory name
		if prefix == "" {
			// Try to get from config file
			prefix = config.GetString("issue-prefix")
		}

		// auto-detect prefix from directory name
		if prefix == "" {
			// Auto-detect from directory name
			cwd, err := os.Getwd()
			if err != nil {
				return fmt.Errorf("failed to get current directory: %v", err)
			}
			prefix = filepath.Base(cwd)
		}

		// Normalize prefix before storing it in config or deriving the Dolt
		// database name. Dots are not valid in issue prefixes and must match the
		// underscore form used for DoltDatabase/metadata.json. Leading dots
		// produce invalid names (e.g. ".claude" -> "claude"), the trailing
		// hyphen is added automatically during ID generation, and a leading
		// non-letter is prefixed with "bd_" so the derived MySQL identifier is
		// valid (directory names like "001" are common in temp dirs).
		prefix = normalizeIssuePrefix(prefix)
		remoteDivergenceConfirmed := false

		// Cross-boundary safety (bd-q83 / ADR 0002): check remote state
		// BEFORE any filesystem side-effects so a refusal exits cleanly.
		// We only refuse here; bootstrap decisions happen later once
		// beadsDir is computed. See CheckRemoteSafety in init_safety.go.

View on GitHub (pinned to 71377f2769)

Solutions

  1. cd into a valid directory (e.g. cd . or re-open the shell) and retry
  2. Pass an explicit --prefix so os.Getwd() path is avoided
  3. Check filesystem/mount health if the directory genuinely exists

Example fix

// before
bd init                      # run from deleted dir
// after
bd init --prefix myproject   # or cd back into the project dir
Defensive patterns

Strategy: validation

Validate before calling

[ -d "$(pwd)" ] || { echo "CWD deleted; cd back"; exit 1; }

Prevention

When it happens

Trigger: Running `bd init` without --prefix in a shell whose CWD has been removed (deleted directory, re-created path, stale shell after worktree removal).

Common situations: Shell sitting in a deleted directory; container volume remounts; symlinked paths invalidated mid-session.

Related errors


AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30). Data as JSON: /api/errors/1012d4046e2b74eb. Report an issue: GitHub.