{"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":510,"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. Review and trust the five claude-mem hooks when Codex prompts you\n  3. Restart sessions opened before trusting the hooks\n\nFor a fresh setup, the supported entry point is:\n  npx claude-mem@latest install","sourceCodeStart":492,"sourceCodeEnd":528,"githubUrl":"https://github.com/thedotmack/claude-mem/blob/d8bc9755e74915e5c3b999181e10a67c889bce2a/src/services/integrations/CodexCliInstaller.ts#L492-L528","documentation":"After installing native Codex hooks, claude-mem cleans up its older AGENTS.md-based context injection via cleanupLegacyCodexAgentsMdContext, which edits CODEX_AGENTS_MD_PATH. A false return means the legacy file could not be cleaned (missing, unreadable, or write failed); the install still succeeded for hooks, but stale legacy context remains and may double-inject memory context alongside native hooks.","triggerScenarios":"performCodexInstall registers hooks successfully, then cleanupLegacyCodexAgentsMdContext() returns false — e.g. AGENTS.md exists but is malformed (no expected markers), is read-only, or its write fails.","commonSituations":"User hand-edited AGENTS.md; file permissions changed; a different tool manages AGENTS.md and rewrote the managed block; partial older install left corrupted markers.","solutions":["Open CODEX_AGENTS_MD_PATH and manually remove the claude-mem legacy context block, then re-run the installer","Check file permissions on AGENTS.md and ensure the user can write to it","Back up AGENTS.md, delete the managed section, and let claude-mem native hooks provide context instead","Ignore if you intentionally keep AGENTS.md context and disabled native memory injection"],"exampleFix":"// before: AGENTS.md contains stale block\n<!-- claude-mem:start -->\n...old context...\n<!-- claude-mem:end -->\n// after: manually remove the managed block, keep user content\nMy own AGENTS.md rules.","handlingStrategy":"fallback","validationCode":"import { accessSync, constants } from 'fs';\ntry { accessSync(CODEX_AGENTS_MD_PATH, constants.W_OK); } catch { console.warn('AGENTS.md not writable; legacy cleanup will fail'); }","typeGuard":null,"tryCatchPattern":"if (!cleanupLegacyCodexAgentsMdContext()) {\n  console.warn(`Manually remove legacy claude-mem block from ${CODEX_AGENTS_MD_PATH}.`);\n}","preventionTips":["Do not hand-edit the claude-mem-managed block in AGENTS.md","Keep AGENTS.md writable by the installing user","Back up AGENTS.md before reinstalling or upgrading claude-mem","After install, grep AGENTS.md for leftover legacy markers"],"tags":["codex","cleanup","installer","agents-md"],"backgroundTag":"file-write-failed","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"}