thedotmack/claude-mem · critical
Critical: code.json mode file missing
Error message
Critical: code.json mode file missing
What it means
loadMode falls back to the built-in 'code' mode whenever a requested mode file cannot be loaded. If the fallback itself fails — i.e. the requested mode was 'code' and code.json is missing — there is no safe default, so it throws this critical error. It signals the mode asset bundle is broken, not just a bad mode name.
Solutions
- Restore code.json into one of the configured mode directories (reinstall or rebuild the package).
- Check/fix modeDirs configuration so it points at the directory containing code.json.
- Re-run the build/sync step (e.g. npm run build-and-sync) so default assets are copied.
- Verify file permissions allow reading the modes directory.
Example fix
// before
// modes dir empty -> loadMode('code') throws 'Critical: code.json mode file missing'
// after
cp node_modules/claude-mem/modes/code.json ~/.claude-mem/modes/code.json
await modeManager.loadMode('code'); Defensive patterns
Strategy: try-catch
Validate before calling
const codePath = path.join(modesDir, 'code.json');
if (!fs.existsSync(codePath)) throw new Error('code.json missing; reinstall the package before using modes'); Try / catch
try { await manager.loadMode('code'); } catch (e) { if (e.message.includes('Critical: code.json mode file missing')) { await reinstallDefaultModes(); return manager.loadMode('code'); } throw e; } Prevention
- Include mode .json assets in package files/build outputs and verify in CI.
- Do a startup health check that loadMode('code') succeeds.
- Never delete code.json even when customizing other modes.
- Restore assets automatically if the modes directory is empty at boot.
When it happens
Trigger: loadMode('code') when code.json is absent from every configured mode directory, or any loadMode call whose fallback to 'code' hits the same missing file.
Common situations: Partial install or build where mode JSON assets were not synced; user deleted/moved the modes directory; packaging bug excluded .json assets from the bundle; wrong working directory at runtime.
Related errors
- Invalid mode ID
- Invalid mode inheritance
- Mode file not found: .json (searched: )
- No mode loaded. Call loadMode() first.
AI-assisted analysis of thedotmack/claude-mem@d8bc9755e7 (2026-09-17).
Data as JSON: /api/errors/71b6c8fb3de85a1d.
Report an issue: GitHub.
Appendix: source
Thrown at src/services/domain/ModeManager.ts:122
if (!inheritance.hasParent) {
try {
const mode = this.loadModeFile(modeId);
this.activeMode = mode;
this.activeModeId = modeId;
logger.debug('SYSTEM', `Loaded mode: ${mode.name} (${modeId})`, undefined, {
types: mode.observation_types.map(t => t.id),
concepts: mode.observation_concepts.map(c => c.id)
});
return mode;
} catch (error) {
if (error instanceof Error) {
logger.warn('WORKER', `Mode file not found: ${modeId}, falling back to 'code'`, { message: error.message });
} else {
logger.warn('WORKER', `Mode file not found: ${modeId}, falling back to 'code'`, { error: String(error) });
}
if (modeId === 'code') {
throw new Error('Critical: code.json mode file missing');
}
return this.loadMode('code');
}
}
const { parentId, overrideId } = inheritance;
let parentMode: ModeConfig;
try {
parentMode = this.loadMode(parentId);
} catch (error) {
if (error instanceof Error) {
logger.warn('WORKER', `Parent mode '${parentId}' not found for ${modeId}, falling back to 'code'`, { message: error.message });
} else {
logger.warn('WORKER', `Parent mode '${parentId}' not found for ${modeId}, falling back to 'code'`, { error: String(error) });
}
parentMode = this.loadMode('code');
}View on GitHub (pinned to d8bc9755e7)