gastownhall/beads · error

workspace already initialized as database %q, but --prefix %

Error message

workspace already initialized as database %q, but --prefix %q was requested.
Remove --prefix (or pass a matching value) to reuse the existing workspace

What it means

Same idempotency guard as the --database variant, but triggered by an explicit --prefix flag that does not match the database already recorded for this workspace. bd init refuses to reuse a workspace whose existing database conflicts with the requested prefix.

Source

Thrown at cmd/bd/init.go:787

				// benign "workspace already initialized" case. An operational
				// error from the check (e.g. an unreadable .beads/embeddeddolt
				// directory) must still abort rather than be masked as a
				// successful skip.
				if initIfMissing && errors.Is(err, errWorkspaceAlreadyInitialized) {
					// Guard against masking a genuine mismatch: an explicit
					// --prefix or --database that does not match the existing
					// workspace must abort, since silently skipping would ignore
					// the request and reuse a different database. --database is
					// the authoritative selector, so it is checked even when
					// --prefix is also set.
					existing := existingWorkspaceDBName()
					if cmd.Flags().Changed("database") {
						if initIfMissingDatabaseMismatch(existing, database) {
							return fmt.Errorf("workspace already initialized as database %q, but --database %q was requested.\nRemove --database (or pass a matching value) to reuse the existing workspace", existing, database)
						}
					} else if cmd.Flags().Changed("prefix") {
						if initIfMissingPrefixMismatch(existing, prefix) {
							return fmt.Errorf("workspace already initialized as database %q, but --prefix %q was requested.\nRemove --prefix (or pass a matching value) to reuse the existing workspace", existing, prefix)
						}
					}
					if !quiet {
						fmt.Fprintln(os.Stderr, "Skipping init: workspace already initialized.")
					}
					return nil
				}
				return fmt.Errorf("%v", err)
			}
		}

		// Check BEADS_DB environment variable if --db flag not set
		// (PersistentPreRun doesn't run for init command)
		if dbPath == "" {
			if envDB := os.Getenv("BEADS_DB"); envDB != "" {
				dbPath = envDB
			}
		}

View on GitHub (pinned to 71377f2769)

Solutions

  1. Remove the --prefix flag to reuse the existing workspace
  2. Or pass a prefix consistent with the existing database shown in the message
  3. If a different database is genuinely wanted, remove .beads and re-init deliberately

Example fix

// before
bd init --prefix newproj   # existing db: oldproj
// after
bd init --prefix oldproj   # or omit --prefix entirely
Defensive patterns

Strategy: validation

Validate before calling

[ -d .beads ] && echo "Already initialized; skipping prefix" || bd init --prefix "$PREFIX"

Prevention

When it happens

Trigger: `bd init --prefix new_prefix` in an already-initialized workspace where initIfMissingPrefixMismatch(existingWorkspaceDBName(), prefix) is true (and --database was not changed).

Common situations: Re-running init after renaming a directory (prefix is often auto-derived from it); scripts passing --prefix from a repo name that differs from the original init; users unaware the workspace is already bound to a database.

Related errors


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