{"record":{"id":"de5a259df0ce458c","repo":"thedotmack/claude-mem","slug":"native-codex-hooks-registered-but-failed-to-rem","errorCode":null,"errorMessage":"  Native Codex hooks registered, but failed to remove legacy AGENTS.md context from ${CODEX_AGENTS_MD_PATH}.","messagePattern":"  Native Codex hooks registered, but failed to remove legacy AGENTS\\.md context from (.+?)\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/services/integrations/CodexCliInstaller.ts","lineNumber":461,"sourceCode":"    return performCodexInstall(marketplaceRootOverride);\n  } catch (error) {\n    const message = error instanceof Error ? error.message : String(error);\n    console.error(`\\nInstallation failed: ${message}`);\n    return 1;\n  }\n}\n\nfunction performCodexInstall(marketplaceRootOverride?: string): number {\n  assertCodexMarketplaceSupported();\n  const marketplaceRoot = resolvePluginMarketplaceRoot(marketplaceRootOverride);\n\n  console.log(`  Registering Codex plugin marketplace: ${marketplaceRoot}`);\n  registerCodexMarketplace(marketplaceRoot);\n  enableCodexPluginConfig();\n  runCodex(['plugin', 'add', CODEX_PLUGIN_ID]);\n  console.log('  Installed Codex plugin cache.');\n  if (!cleanupLegacyCodexAgentsMdContext()) {\n    console.warn(`  Native Codex hooks registered, but failed to remove legacy AGENTS.md context from ${CODEX_AGENTS_MD_PATH}.`);\n  }\n  if (!cleanupLegacyCodexTranscriptAgentsContext()) {\n    console.warn(`  Native Codex hooks registered, but failed to disable legacy transcript AGENTS.md context in ${CODEX_TRANSCRIPT_WATCH_CONFIG_PATH}.`);\n  }\n\n  console.log(`\nInstallation complete!\n\nCodex marketplace: ${MARKETPLACE_NAME}\nPlugin source:     ${marketplaceRoot}\n\nNext steps:\n  1. Open Codex CLI in your project\n  2. Restart any running Codex sessions so native hooks are loaded\n\nFor a fresh setup, the supported entry point is:\n  npx claude-mem@latest install\n`);","sourceCodeStart":443,"sourceCodeEnd":479,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/e2d1df569a8f04075d40e92461128ece7cf04c82/src/services/integrations/CodexCliInstaller.ts#L443-L479","documentation":"After native Codex hooks are installed, `cleanupLegacyCodexAgentsMdContext` strips the legacy `<claude-mem-context>` block from CODEX_AGENTS_MD_PATH (~/.codex/AGENTS.md). When it returns false — file present but the block could not be removed — the installer warns: native hooks work, but the legacy context may still be injected alongside them.","triggerScenarios":"AGENTS.md exists and contains (or partly contains) the legacy claude-mem context block, and the rewrite fails: unreadable/unwritable file, unexpected content, or concurrent modification.","commonSituations":"Read-only or permission-restricted AGENTS.md, hand-edited file with broken tag pairing, or another tool writing it simultaneously.","solutions":["Open ~/.codex/AGENTS.md and delete the `<claude-mem-context>...</claude-mem-context>` block manually.","Fix file permissions so the installer can rewrite it.","Re-run install to retry the cleanup."],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"import { readFileSync } from 'node:fs';\n\nconst agentsMd = `${process.env.HOME}/.codex/AGENTS.md`;\nconst hasLegacyBlock = readFileSync(agentsMd, 'utf8').includes('<claude-mem-context>');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep ~/.codex/AGENTS.md writable by your user.","Do not hand-edit the claude-mem context block tags."],"tags":["codex","agents-md","legacy-cleanup","filesystem"],"backgroundTag":"legacy-config-cleanup-failed","analyzedSha":"e2d1df569a8f04075d40e92461128ece7cf04c82","analyzedAt":"2026-08-20T23:58:13.836Z","schemaVersion":2},"datasetVersion":"2026-08-29T07:17:48.351Z"}