{"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/d768ba364302d12b76e69e4f021f0bb1d2d50ed6/src/services/domain/ModeManager.ts#L104-L140","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before — modes/code.json missing from all modeDirs\nmanager.loadMode('anything');\n// logs 'Mode file not found: anything, falling back to code'\n// then throws 'Critical: code.json mode file missing'\n\n// after — restore the base mode\n// copy from package into the durable user modes dir\ncp node_modules/claude-mem/modes/code.json ~/.claude-mem/modes/code.json","handlingStrategy":"validation","validationCode":"import { existsSync } from 'fs';\n// Ensure the base mode exists before any loadMode call.\nconst codePresent = modeDirs.some(d => existsSync(join(d, 'code.json')));\nif (!codePresent) {\n  throw new Error('modes/code.json missing — reinstall the plugin or restore the file before continuing');\n}","typeGuard":"function baseModeAvailable(modeDirs: string[]): boolean {\n  return modeDirs.some(d => existsSync(join(d, 'code.json')));\n}","tryCatchPattern":null,"preventionTips":["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."],"tags":["modes","filesystem","bootstrap","critical"],"backgroundTag":null,"analyzedSha":"d768ba364302d12b76e69e4f021f0bb1d2d50ed6","analyzedAt":"2026-08-12T23:52:55.241Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}