gastownhall/beads · error
workspace already initialized as database %q, but --database
Error message
workspace already initialized as database %q, but --database %q was requested. Remove --database (or pass a matching value) to reuse the existing workspace
What it means
The workspace (.beads) is already initialized against a recorded Dolt database, and bd init was invoked with an explicit --database flag naming a different database. Since --database is the authoritative selector, bd refuses to silently re-point the workspace and asks you to drop or match the flag.
Source
Thrown at cmd/bd/init.go:783
// engdocs/adr/0002-init-safety-invariants.md).
if !reinitLocal {
if err := checkExistingBeadsData(prefix); err != nil {
// --init-if-missing makes init idempotent, but ONLY for the
// 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 == "" {View on GitHub (pinned to 71377f2769)
Solutions
- Remove the --database flag so the existing workspace is reused
- Or pass the same value already recorded: bd init --database <existing-name>
- Delete/reinitialize the workspace intentionally if you truly want a fresh database
Example fix
// before bd init --database proj_v2 # workspace is proj_v1 // after bd init # reuse existing, or: bd init --database proj_v1
Defensive patterns
Strategy: validation
Validate before calling
existing=$(cat .beads/database.name 2>/dev/null); [ -n "$existing" ] && [ "$existing" != "$DB" ] && echo "Refusing: workspace is $existing" && unset DB
Prevention
- In scripts, omit --database on re-init; bd reuses the existing workspace safely
- Store the canonical database name in CI config once and reuse it
- Check .beads contents before re-initializing a cloned repo
When it happens
Trigger: `bd init --database new_name` in a directory where .beads already exists and existingWorkspaceDBName() returns a different name, and initIfMissingDatabaseMismatch flags the mismatch.
Common situations: Re-running init in a cloned repo with a leftover config but a different database name; renaming the project and wanting a new database name without wiping; scripted init with a templated name that drifted.
Related errors
- workspace already initialized as database %q, but --prefix %
- %s
- %s
- %w. Hint: run 'bd init' to create a database in the current
- backend %q cannot be created by bd init; it can only open an
AI-assisted analysis of gastownhall/beads@71377f2769 (2026-08-30).
Data as JSON: /api/errors/f85a1e7b91058294.
Report an issue: GitHub.