{"record":{"id":"12f5d41337280215","repo":"thedotmack/claude-mem","slug":"missing-cwd-in-fileedit-hook-input-for-session-s","errorCode":null,"errorMessage":"Missing cwd in FileEdit hook input for session ${sessionId}, file ${filePath}","messagePattern":"Missing cwd in FileEdit hook input for session (.+?), file (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cli/handlers/file-edit.ts","lineNumber":23,"sourceCode":"import { HOOK_EXIT_CODES } from '../../shared/hook-constants.js';\nimport { normalizePlatformSource } from '../../shared/platform-source.js';\nimport { shouldTrackProject } from '../../shared/should-track-project.js';\n\nexport const fileEditHandler: EventHandler = {\n  async execute(input: NormalizedHookInput): Promise<HookResult> {\n    const { sessionId, cwd, filePath, edits } = input;\n    const platformSource = normalizePlatformSource(input.platform);\n\n    if (!filePath) {\n      throw new Error('fileEditHandler requires filePath');\n    }\n\n    logger.dataIn('HOOK', `FileEdit: ${filePath}`, {\n      editCount: edits?.length ?? 0\n    });\n\n    if (!cwd) {\n      throw new Error(`Missing cwd in FileEdit hook input for session ${sessionId}, file ${filePath}`);\n    }\n\n    if (!shouldTrackProject(cwd)) {\n      logger.debug('HOOK', 'Project excluded from tracking, skipping file edit observation', { cwd, filePath });\n      return { continue: true, suppressOutput: true, exitCode: HOOK_EXIT_CODES.SUCCESS };\n    }\n\n    const result = await executeWithWorkerFallback<{ status?: string }>(\n      '/api/sessions/observations',\n      'POST',\n      {\n        contentSessionId: sessionId,\n        platformSource,\n        tool_name: 'write_file',\n        tool_input: { filePath, edits },\n        tool_response: { success: true },\n        cwd,\n      },","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/cli/handlers/file-edit.ts#L5-L41","documentation":"The FileEdit hook handler requires the `cwd` field on the normalized hook input so it can decide whether the project is tracked and record the edit against the right project. claude-mem throws this error when the hook input arrives without a working directory, because an edit cannot be attributed to any project. It is an input-contract failure of the hook pipeline, not a runtime condition the handler can recover from.","triggerScenarios":"fileEditHandler.execute() is invoked with a NormalizedHookInput whose `cwd` is undefined/empty (falsy), while `filePath` is present — e.g. a hook payload constructed by a platform integration that omits cwd.","commonSituations":"Custom or third-party platform adapters calling the internal handler directly with a partially populated input; a hook JSON envelope missing the cwd key; a broken/old hook invocation script that drops the cwd field.","solutions":["Ensure the hook invocation payload includes the cwd field (the directory of the Claude session).","If building the input programmatically, pass `cwd: process.cwd()` or the session's project directory into the handler.","Check for a mismatched claude-mem version where the hook entry script and handler expect different input shapes; upgrade both via npm run build-and-sync.","Catch this in the hook dispatcher and skip observation instead of failing the hook."],"exampleFix":"// before\nawait fileEditHandler.execute({ sessionId, filePath, edits });\n// after\nawait fileEditHandler.execute({ sessionId, cwd: process.cwd(), filePath, edits });","handlingStrategy":"validation","validationCode":"if (!input.cwd) throw new TypeError('fileEditHandler requires cwd; pass the session working directory');","typeGuard":"function hasCwd(input: Partial<NormalizedHookInput>): input is NormalizedHookInput & { cwd: string } { return typeof input.cwd === 'string' && input.cwd.length > 0; }","tryCatchPattern":"try { await fileEditHandler.execute(input); } catch (e) { if (String(e.message).includes('Missing cwd')) { logger.warn('skipping file-edit observation: no cwd'); } else throw e; }","preventionTips":["Always include cwd in hook payloads from custom integrations","Validate NormalizedHookInput with a schema (zod) before dispatching to handlers","Keep hook entry scripts and handlers on the same plugin version"],"tags":["hooks","missing-field","input-validation"],"backgroundTag":"missing-required-argument","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"}