thedotmack/claude-mem · error

Folder does not exist

Error message

Folder does not exist: ${folderPath}

What it means

writeClaudeMdToFolder throws a plain Error('Folder does not exist: <path>') when existsSync(folderPath) is false after skipping .git directories. It writes CLAUDE.md into a target folder and refuses to create missing directories implicitly.

Solutions

  1. Create the directory before calling (fs.mkdirSync(folderPath, { recursive: true })) or pass an existing folder
  2. Verify the stored/registered folder path still exists and correct stale entries (project moved/renamed)
  3. Pass an absolute path, not a relative one resolved against an unexpected cwd
  4. Catch the error and skip/log the folder instead of letting regeneration abort
  5. Check the path points to a directory, not a file

Example fix

// before
await writeClaudeMdToFolder(removedFolder); // throws
// after
if (!existsSync(folderPath)) mkdirSync(folderPath, { recursive: true });
await writeClaudeMdToFolder(folderPath);
Defensive patterns

Strategy: try-catch

Validate before calling

if (!existsSync(folderPath) || !statSync(folderPath).isDirectory()) {
  throw new Error(`Folder does not exist: ${folderPath}`);
}

Type guard

null

Try / catch

try { await writeClaudeMdToFolder(folderPath); } catch (e) { if (e.message.startsWith('Folder does not exist')) { mkdirSync(folderPath, { recursive: true }); await writeClaudeMdToFolder(folderPath); } else throw e; }

Prevention

When it happens

Trigger: Calling writeClaudeMdToFolder (directly or via regenerateFolder) with a folderPath that has been deleted, was never created, is a file instead of a directory, or differs only by casing/trailing slash from the real path; also when a stale registry points at a removed project folder.

Common situations: CLAUDE.md regeneration after a project directory was moved/renamed; relative paths resolved from the wrong base; network drives/temp dirs that disappeared between registration and regeneration; typos in stored folder paths.

Related errors


AI-assisted analysis of thedotmack/claude-mem@d8bc9755e7 (2026-09-17). Data as JSON: /api/errors/3810c369021646f9. Report an issue: GitHub.

Appendix: source

Thrown at src/cli/claude-md-commands.ts:248

      }

      lines.push('');
    }
  }

  return lines.join('\n').trim();
}

function writeClaudeMdToFolder(folderPath: string, newContent: string): void {
  const resolvedPath = path.resolve(folderPath);

  if (resolvedPath.includes('/.git/') || resolvedPath.includes('\\.git\\') || resolvedPath.endsWith('/.git') || resolvedPath.endsWith('\\.git')) return;

  const claudeMdPath = path.join(folderPath, 'CLAUDE.md');
  const tempFile = `${claudeMdPath}.tmp`;

  if (!existsSync(folderPath)) {
    throw new Error(`Folder does not exist: ${folderPath}`);
  }

  let existingContent = '';
  if (existsSync(claudeMdPath)) {
    existingContent = readFileSync(claudeMdPath, 'utf-8');
  }

  const startTag = '<claude-mem-context>';
  const endTag = '</claude-mem-context>';

  let finalContent: string;
  if (!existingContent) {
    finalContent = `${startTag}\n${newContent}\n${endTag}`;
  } else {
    const startIdx = existingContent.indexOf(startTag);
    const endIdx = existingContent.indexOf(endTag);

    if (startIdx !== -1 && endIdx !== -1) {

View on GitHub (pinned to d8bc9755e7)