From 0106371e12563cf50691f30fd5a7a30ed41594b9 Mon Sep 17 00:00:00 2001 From: Steve Yegge Date: Thu, 6 Nov 2025 22:23:54 -0800 Subject: [PATCH] Prevent nested .beads directories (bd-eqjc) Add validation in bd init to detect if current directory is inside a .beads directory and exit with clear error message. This prevents the common issue of accidentally creating .beads/.beads/ nested directories. --- cmd/bd/init.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/cmd/bd/init.go b/cmd/bd/init.go index 8aa5d0ba..4493289a 100644 --- a/cmd/bd/init.go +++ b/cmd/bd/init.go @@ -87,6 +87,16 @@ With --no-db: creates .beads/ directory and issues.jsonl file instead of SQLite os.Exit(1) } + // Prevent nested .beads directories + // Check if current working directory is inside a .beads directory + if strings.Contains(filepath.Clean(cwd), string(filepath.Separator)+".beads"+string(filepath.Separator)) || + strings.HasSuffix(filepath.Clean(cwd), string(filepath.Separator)+".beads") { + fmt.Fprintf(os.Stderr, "Error: cannot initialize bd inside a .beads directory\n") + fmt.Fprintf(os.Stderr, "Current directory: %s\n", cwd) + fmt.Fprintf(os.Stderr, "Please run 'bd init' from outside the .beads directory.\n") + os.Exit(1) + } + localBeadsDir := filepath.Join(cwd, ".beads") initDBDir := filepath.Dir(initDBPath)