{"record":{"id":"3810c369021646f9","repo":"thedotmack/claude-mem","slug":"folder-does-not-exist-folderpath","errorCode":null,"errorMessage":"Folder does not exist: ${folderPath}","messagePattern":"Folder does not exist: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli/claude-md-commands.ts","lineNumber":248,"sourceCode":"      }\n\n      lines.push('');\n    }\n  }\n\n  return lines.join('\\n').trim();\n}\n\nfunction writeClaudeMdToFolder(folderPath: string, newContent: string): void {\n  const resolvedPath = path.resolve(folderPath);\n\n  if (resolvedPath.includes('/.git/') || resolvedPath.includes('\\\\.git\\\\') || resolvedPath.endsWith('/.git') || resolvedPath.endsWith('\\\\.git')) return;\n\n  const claudeMdPath = path.join(folderPath, 'CLAUDE.md');\n  const tempFile = `${claudeMdPath}.tmp`;\n\n  if (!existsSync(folderPath)) {\n    throw new Error(`Folder does not exist: ${folderPath}`);\n  }\n\n  let existingContent = '';\n  if (existsSync(claudeMdPath)) {\n    existingContent = readFileSync(claudeMdPath, 'utf-8');\n  }\n\n  const startTag = '<claude-mem-context>';\n  const endTag = '</claude-mem-context>';\n\n  let finalContent: string;\n  if (!existingContent) {\n    finalContent = `${startTag}\\n${newContent}\\n${endTag}`;\n  } else {\n    const startIdx = existingContent.indexOf(startTag);\n    const endIdx = existingContent.indexOf(endTag);\n\n    if (startIdx !== -1 && endIdx !== -1) {","sourceCodeStart":230,"sourceCodeEnd":266,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/cli/claude-md-commands.ts#L230-L266","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Create the directory before calling (fs.mkdirSync(folderPath, { recursive: true })) or pass an existing folder","Verify the stored/registered folder path still exists and correct stale entries (project moved/renamed)","Pass an absolute path, not a relative one resolved against an unexpected cwd","Catch the error and skip/log the folder instead of letting regeneration abort","Check the path points to a directory, not a file"],"exampleFix":"// before\nawait writeClaudeMdToFolder(removedFolder); // throws\n// after\nif (!existsSync(folderPath)) mkdirSync(folderPath, { recursive: true });\nawait writeClaudeMdToFolder(folderPath);","handlingStrategy":"try-catch","validationCode":"if (!existsSync(folderPath) || !statSync(folderPath).isDirectory()) {\n  throw new Error(`Folder does not exist: ${folderPath}`);\n}","typeGuard":"null","tryCatchPattern":"try { await writeClaudeMdToFolder(folderPath); } catch (e) { if (e.message.startsWith('Folder does not exist')) { mkdirSync(folderPath, { recursive: true }); await writeClaudeMdToFolder(folderPath); } else throw e; }","preventionTips":["mkdirSync(folderPath, { recursive: true }) before writing","Use absolute paths and re-resolve before each regeneration","Prune registry entries whose folders were moved or deleted","Verify the path is a directory, not a file"],"tags":["filesystem","folder","write"],"backgroundTag":"directory-not-found","analyzedSha":"d8bc9755e74915e5c3b999181e10a67c889bce2a","analyzedAt":"2026-09-17T16:40:26.182Z","contentChangedAt":"2026-09-17T16:40:26.182Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}