{"record":{"id":"388afc0e3ef3ff60","repo":"thedotmack/claude-mem","slug":"failed-to-clean-agents-md-context","errorCode":null,"errorMessage":"Failed to clean AGENTS.md context","messagePattern":"Failed to clean AGENTS\\.md context","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/services/integrations/CodexCliInstaller.ts","lineNumber":341,"sourceCode":"  }\n\n  if (version.localeCompare(MIN_CODEX_MARKETPLACE_VERSION, undefined, { numeric: true }) < 0) {\n    throw new Error(`Codex CLI ${version} is too old for plugin marketplace support. Update Codex CLI to ${MIN_CODEX_MARKETPLACE_VERSION} or newer, then run: npx claude-mem@latest install`);\n  }\n}\n\nfunction removeCodexAgentsMdContext(): boolean {\n  if (!existsSync(CODEX_AGENTS_MD_PATH)) return true;\n\n  const startTag = '<claude-mem-context>';\n  const endTag = '</claude-mem-context>';\n\n  try {\n    readAndStripContextTags(startTag, endTag);\n    return true;\n  } catch (error) {\n    const message = error instanceof Error ? error.message : String(error);\n    logger.warn('WORKER', 'Failed to clean AGENTS.md context', { error: message });\n    return false;\n  }\n}\n\nfunction readAndStripContextTags(startTag: string, endTag: string): void {\n  const content = readFileSync(CODEX_AGENTS_MD_PATH, 'utf-8');\n\n  const startIdx = content.indexOf(startTag);\n  const endIdx = content.indexOf(endTag);\n\n  if (startIdx === -1 || endIdx === -1) return;\n\n  const before = content.substring(0, startIdx).replace(/\\n+$/, '');\n  const after = content.substring(endIdx + endTag.length).replace(/^\\n+/, '');\n  const finalContent = (before + (after ? '\\n\\n' + after : '')).trim();\n\n  if (finalContent) {\n    writeFileSync(CODEX_AGENTS_MD_PATH, finalContent + '\\n');","sourceCodeStart":323,"sourceCodeEnd":359,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/e2d1df569a8f04075d40e92461128ece7cf04c82/src/services/integrations/CodexCliInstaller.ts#L323-L359","documentation":"While disabling the codex integration, claude-mem strips its managed <claude-mem-context>...</claude-mem-context> block from CODEX_AGENTS_MD_PATH. readAndStripContextTags reads the file and rewrites it without the block; any throw — read EACCES, write failure, or a locked file — surfaces as this warning and the function returns false, leaving the stale context block in the file.","triggerScenarios":"readFileSync or the rewrite inside readAndStripContextTags throws: AGENTS.md is read-only or owned by another user, an editor or antivirus holds an exclusive lock (Windows), the path is a symlink to nowhere, or the file is deleted between existsSync and read (race).","commonSituations":"AGENTS.md owned by root after a sudo run; file open in an editor with exclusive locking; repository permissions changed; the codex config directory reorganized between versions.","solutions":["Check permissions and ownership on the AGENTS.md file and its directory; fix ownership if a sudo run changed it.","Close editors holding the file (or exclude it from antivirus locking) and retry the disable step.","Verify no <claude-mem-context> block remains — an earlier partial run may have already stripped it.","As a last resort, delete the managed block by hand and re-run to confirm a clean report."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// confirm writable before the strip runs\nimport { accessSync, constants } from 'node:fs';\naccessSync(CODEX_AGENTS_MD_PATH, constants.W_OK); // throws with a clear errno","typeGuard":null,"tryCatchPattern":"try {\n  removeCodexAgentsMdContext();\n} catch (e) {\n  // false return leaves the managed block: surface it instead of ignoring\n  throw new Error(`AGENTS.md context strip failed: ${(e as Error).message}`);\n}","preventionTips":["Never run claude-mem under sudo against user-owned config files.","Close editors holding AGENTS.md during uninstall/disable steps.","After disabling, grep AGENTS.md for 'claude-mem-context' to confirm removal."],"tags":["codex","agents-md","file-io","uninstall"],"backgroundTag":"file-access-denied","analyzedSha":"e2d1df569a8f04075d40e92461128ece7cf04c82","analyzedAt":"2026-08-20T23:58:13.836Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}