thedotmack/claude-mem · warning
Failed to regenerate folder
Error message
Failed to regenerate folder
What it means
regenerateFolder formats observations for a folder's CLAUDE.md and writes the file inside a try/catch. Any exception — from formatting or from writeClaudeMdToFolder (fs writes, mkdir, permission checks) — is caught, logged as this warning, and converted into a { success: false, error } result rather than thrown.
Solutions
- Check that the folder exists and is writable by the process user (ls -ld, touch test)
- Recreate the missing folder or fix permissions (chmod/chown)
- Re-run the generation command after fixing the environment — the function already returns a structured error result
- Inspect result.error for the underlying fs message (EACCES/ENOENT/ENOSPC) and address that specific cause
Example fix
// before
mkdirSync(folder); // throws if parent missing
// after
mkdirSync(folder, { recursive: true }); Defensive patterns
Strategy: try-catch
Validate before calling
if (!existsSync(absoluteFolder)) mkdirSync(absoluteFolder, { recursive: true });
accessSync(absoluteFolder, fsConstants.W_OK); Type guard
function isWritableDir(p: string): boolean { try { accessSync(p, fsConstants.W_OK); return statSync(p).isDirectory(); } catch { return false; } } Try / catch
try {
writeClaudeMdToFolder(folder, formatted);
} catch (e) {
return { success: false, observationCount: 0, error: e instanceof Error ? e.message : String(e) };
} Prevention
- Ensure directories exist (recursive mkdir) before writing
- Run generation as a user with write access to the repo
- Check disk space before batch regeneration
- Retry per-folder failures after fixing the fs issue — results are structured and idempotent
When it happens
Trigger: Calling regenerateFolder when the target folder cannot be written: parent directory missing and mkdir fails, read-only filesystem, permission denied on the existing CLAUDE.md, or formatObservationsForClaudeMd throwing on malformed observation data.
Common situations: Running under a user without write access to project subfolders; folder deleted between scan and write; read-only CI checkout; disk-full; ENAMETOOLONG on deeply nested paths.
Understand the failure class
Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.
Related errors
- Error processing folder
- Error processing
- Folder does not exist
- CLAUDE_CODE_PATH is set to
- Corrupt JSON file, refusing to overwrite
AI-assisted analysis of thedotmack/claude-mem@d8bc9755e7 (2026-09-17).
Data as JSON: /api/errors/c02bb45fdb71b020.
Report an issue: GitHub.
Appendix: source
Thrown at src/cli/claude-md-commands.ts:314
}
const observations = findObservationsByFolder(db, relativeFolder, project, observationLimit);
if (observations.length === 0) {
return { success: false, observationCount: 0, error: 'No observations for folder' };
}
if (dryRun) {
return { success: true, observationCount: observations.length };
}
try {
const formatted = formatObservationsForClaudeMd(observations, relativeFolder);
writeClaudeMdToFolder(absoluteFolder, formatted);
return { success: true, observationCount: observations.length };
} catch (error) {
const errorMessage = error instanceof Error ? error.message : String(error);
logger.warn('CLAUDE_MD', 'Failed to regenerate folder', { folder: relativeFolder, error: errorMessage });
return { success: false, observationCount: 0, error: errorMessage };
}
}
function processAllFoldersForGeneration(
trackedFolders: Set<string>,
workingDir: string,
project: string,
dryRun: boolean,
observationLimit: number
): number {
const db = new Database(DB_PATH, { readonly: true, create: false });
let successCount = 0;
let skipCount = 0;
let errorCount = 0;
const foldersArray = Array.from(trackedFolders).sort();View on GitHub (pinned to d8bc9755e7)