plans/2026-01-22-Fix Auto-Sync Workspace Registration Issue-v1.md
Issue: #2288
Problem: The zsh plugin automatically syncs workspaces in the background on every directory change, causing unintended parent directories to be registered as workspaces. When users run forge workspace list, ancestor directories appear as "Current" instead of the actual working directory.
Root Cause: _forge_start_background_sync() in shell-plugin/lib/helpers.zsh:114-131 unconditionally runs forge workspace sync without checking if the workspace or its ancestors are already registered.
Prevent auto-sync from creating unintended workspace registrations while maintaining the convenience of automatic syncing for already-indexed workspaces.
forge workspace is-indexed [PATH] that checks if a path (or any ancestor) is already registered as a workspacecrates/forge_main/src/cli.rs - add IsIndexed variant to WorkspaceCommand enumcrates/forge_main/src/ui.rs that calls existing is_indexed() service method--verbose flag to show which workspace was found (exact or ancestor)_forge_start_background_sync() in shell-plugin/lib/helpers.zsh:114-131$_FORGE_BIN workspace is-indexed "$workspace_path"FORGE_DEBUG=true) to indicate when sync is skippedforge workspace sync still works for first-time registrationforge workspace sync to enable auto-syncon_list_workspaces() in crates/forge_main/src/ui.rs:3266-3311 to distinguish between exact match and ancestor match[Current via ancestor] or similarcd /Users/username (parent directory)forge workspace sync oncecd /Users/username/Documents/Projects/forge (subdirectory)forge workspace list/Users/username/Documents/Projects/forge is incorrectly registered as a workspacecd /Users/username/Documents/Projects/forgeforge workspace list/Users/username appears (no auto-sync of subdirectory)[Current via ancestor] or similar indicationforge workspace sync in subdirectoryFORGE_SYNC_ENABLED=false (should still respect flag)Mitigation: Users who rely on automatic workspace creation will need to run forge workspace sync once per workspace. This is a one-time migration cost for better UX long-term.
Mitigation: The workspace is-indexed check is a fast database query (already exists in is_indexed() method). It should add negligible overhead.
Mitigation: The check and sync are not atomic, but this is acceptable - worst case, a sync happens when it shouldn't have. No data corruption risk.
Instead of checking if workspace exists, require users to explicitly enable auto-sync per workspace via a flag or configuration file.
Pros: More explicit control
Cons: More complex UX, requires additional configuration management
Just improve the workspace list display to show [Current via ancestor] without changing auto-sync behavior.
Pros: Simpler implementation, no behavior changes
Cons: Doesn't solve the root problem of unintended workspace registrations
Only auto-sync directories within N levels of an existing workspace.
Pros: Prevents deep directory pollution
Cons: Arbitrary limit, still creates unintended workspaces
is_indexed() method in WorkspaceService can be reused$_FORGE_BIN for CLI callsworkspace is-indexed command in CLI testsshell-plugin/README.md to explain auto-sync behaviorworkspace sync requirement for new workspacesFORGE_SYNC_ENABLED environment variableis-indexed subcommand