thedotmack/claude-mem · critical
Critical: code.json mode file missing
Error message
Critical: code.json mode file missing
What it means
Thrown by ModeManager.loadMode() when the fallback chain itself fails: a missing/invalid mode triggered the catch, which recursively calls loadMode('code'), and that too threw — meaning code.json (the always-required base mode) is absent from every modeDir. This is terminal because there is no further fallback.
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 d768ba3643)
Solutions
- Restore the bundled modes directory — reinstall the plugin or copy modes/code.json from the package into packageRoot/modes.
- Verify getPackageRoot() resolves to the directory that actually contains modes/code.json.
- If running from source, ensure the build/sync step copied src/modes (or plugin/modes) into place.
- As a last resort, manually place a valid code.json in dataDir/modes.
Example fix
// before — modes/code.json missing from all modeDirs
manager.loadMode('anything');
// logs 'Mode file not found: anything, falling back to code'
// then throws 'Critical: code.json mode file missing'
// after — restore the base mode
// copy from package into the durable user modes dir
cp node_modules/claude-mem/modes/code.json ~/.claude-mem/modes/code.json Defensive patterns
Strategy: validation
Validate before calling
import { existsSync } from 'fs';
// Ensure the base mode exists before any loadMode call.
const codePresent = modeDirs.some(d => existsSync(join(d, 'code.json')));
if (!codePresent) {
throw new Error('modes/code.json missing — reinstall the plugin or restore the file before continuing');
} Type guard
function baseModeAvailable(modeDirs: string[]): boolean {
return modeDirs.some(d => existsSync(join(d, 'code.json')));
} Prevention
- Always keep modes/code.json in the durable dataDir/modes as a safety net.
- Verify getPackageRoot() resolves correctly after install/relocation.
- Run a startup self-check that confirms code.json is present and valid JSON.
When it happens
Trigger: Any missing mode triggers fallback to 'code'; if modes/code.json is also missing (deleted, never installed, package corrupted), the recursive loadMode('code') re-enters the catch and throws this critical error.
Common situations: Plugin install was partial and the bundled modes/ directory (which ships code.json) is absent; a cleanup script deleted all .json modes; package was unpacked without preserving the modes directory; getPackageRoot() resolves to the wrong location so packageRoot/modes is empty.
Related errors
- Mode file not found: ${modeId}.json (searched: ${this.modeDi
- installPluginDependencies: no package.json at ${targetDir}
- Folder does not exist: ${folderPath}
- Invalid mode inheritance: ${modeId}. Only one level of inher
- Invalid mode ID: ${modeId}
AI-assisted analysis of thedotmack/claude-mem@d768ba3643 (2026-08-12).
Data as JSON: /api/errors/71b6c8fb3de85a1d.
Report an issue: GitHub.