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

  1. Restore code.json into one of the configured mode directories (reinstall or rebuild the package).
  2. Check/fix modeDirs configuration so it points at the directory containing code.json.
  3. Re-run the build/sync step (e.g. npm run build-and-sync) so default assets are copied.
  4. 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

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


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)