claude-flow icon indicating copy to clipboard operation
claude-flow copied to clipboard

Fix: Agents creating duplicate .claude-flow and .swarm folders in subdirectories

Open ruvnet opened this issue 3 months ago • 1 comments

Problem

Agents are creating duplicate .claude-flow and .swarm folders in subdirectories instead of using the main workspace root folders. This causes:

  • Fragmented memory storage across multiple locations
  • Agents not sharing state properly
  • Increased disk usage with redundant folders
  • Confusion about which folder contains the actual data

Root Cause

The code was using process.cwd() to determine folder paths, which returns the current working directory. When agents operate in subdirectories, they create local folders instead of using the project root folders.

Locations Affected

Multiple duplicate folders were found:

  • ./docker/docker-test/.swarm
  • ./examples/litellm/.claude-flow
  • ./benchmark/.claude-flow
  • ./docs/.claude-flow
  • ./claude-flow-wiki/.claude-flow
  • And several others...

Solution Implemented

Created a project root detection utility that:

  1. Searches upward from any directory to find the main project root
  2. Prioritizes the main claude-flow package root over subdirectory markers
  3. Always returns paths relative to the true project root
  4. Ensures all agents use the same .claude-flow and .swarm folders

Files Modified

  • Created: src/utils/project-root.js - New utility for project root detection
  • Updated: src/memory/sqlite-store.js - Use project root instead of process.cwd()
  • Updated: src/memory/migration.js - Use project root for paths
  • Updated: src/memory/shared-memory.js - Use project root for database paths
  • Updated: src/memory/unified-memory-manager.js - Use project root for config paths

Testing

Verified that from any subdirectory, the utility correctly identifies the project root and returns the main workspace folders.

Impact

  • All agents will now use the same centralized folders
  • Memory and state will be properly shared
  • No more duplicate folder creation in subdirectories
  • Consistent behavior regardless of where agents operate

Fixes #763

ruvnet avatar Sep 22 '25 15:09 ruvnet

✅ Fix Verified and Implemented

The issue has been resolved with the implementation of a robust project root detection mechanism.

Verification Results

Tested the new project root detection from various subdirectories:

From root directory:

  • Project Root: /workspaces/claude-code-flow ✅
  • Claude Flow Dir: /workspaces/claude-code-flow/.claude-flow ✅
  • Swarm Dir: /workspaces/claude-code-flow/.swarm ✅

From src/memory subdirectory:

  • Project Root: /workspaces/claude-code-flow ✅
  • Claude Flow Dir: /workspaces/claude-code-flow/.claude-flow ✅
  • Swarm Dir: /workspaces/claude-code-flow/.swarm ✅

From examples/litellm subdirectory (previously problematic):

  • Project Root: /workspaces/claude-code-flow ✅
  • Claude Flow Dir: /workspaces/claude-code-flow/.claude-flow ✅
  • Swarm Dir: /workspaces/claude-code-flow/.swarm ✅

Key Improvements

  1. Intelligent Root Detection: The new utility prioritizes the main project root even when subdirectories have their own .claude-flow folders
  2. Consistent Paths: All agents now use the same root-level folders regardless of their working directory
  3. Backwards Compatible: Falls back to process.cwd() if no project root is found
  4. Cached Results: Project root is cached to avoid repeated filesystem lookups

Next Steps

  • Monitor agent behavior to ensure no new duplicate folders are created
  • Consider cleaning up existing duplicate folders in subdirectories
  • Update documentation to reflect the new behavior

The fix ensures all agents properly coordinate through the main workspace folders as intended.

ruvnet avatar Sep 22 '25 15:09 ruvnet