{"record":{"id":"71b6c8fb3de85a1d","repo":"thedotmack/claude-mem","slug":"critical-code-json-mode-file-missing","errorCode":null,"errorMessage":"Critical: code.json mode file missing","messagePattern":"Critical: code\\.json mode file missing","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"src/services/domain/ModeManager.ts","lineNumber":122,"sourceCode":"\n    if (!inheritance.hasParent) {\n      try {\n        const mode = this.loadModeFile(modeId);\n        this.activeMode = mode;\n        this.activeModeId = modeId;\n        logger.debug('SYSTEM', `Loaded mode: ${mode.name} (${modeId})`, undefined, {\n          types: mode.observation_types.map(t => t.id),\n          concepts: mode.observation_concepts.map(c => c.id)\n        });\n        return mode;\n      } catch (error) {\n        if (error instanceof Error) {\n          logger.warn('WORKER', `Mode file not found: ${modeId}, falling back to 'code'`, { message: error.message });\n        } else {\n          logger.warn('WORKER', `Mode file not found: ${modeId}, falling back to 'code'`, { error: String(error) });\n        }\n        if (modeId === 'code') {\n          throw new Error('Critical: code.json mode file missing');\n        }\n        return this.loadMode('code');\n      }\n    }\n\n    const { parentId, overrideId } = inheritance;\n\n    let parentMode: ModeConfig;\n    try {\n      parentMode = this.loadMode(parentId);\n    } catch (error) {\n      if (error instanceof Error) {\n        logger.warn('WORKER', `Parent mode '${parentId}' not found for ${modeId}, falling back to 'code'`, { message: error.message });\n      } else {\n        logger.warn('WORKER', `Parent mode '${parentId}' not found for ${modeId}, falling back to 'code'`, { error: String(error) });\n      }\n      parentMode = this.loadMode('code');\n    }","sourceCodeStart":104,"sourceCodeEnd":140,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/services/domain/ModeManager.ts#L104-L140","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n// modes dir empty -> loadMode('code') throws 'Critical: code.json mode file missing'\n// after\ncp node_modules/claude-mem/modes/code.json ~/.claude-mem/modes/code.json\nawait modeManager.loadMode('code');","handlingStrategy":"try-catch","validationCode":"const codePath = path.join(modesDir, 'code.json');\nif (!fs.existsSync(codePath)) throw new Error('code.json missing; reinstall the package before using modes');","typeGuard":null,"tryCatchPattern":"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; }","preventionTips":["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."],"tags":["mode-manager","missing-asset","fallback-failed"],"backgroundTag":"missing-config-file","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"}