thedotmack/claude-mem · warning

Native Codex hooks registered, but failed to remove legacy…

Error message

  Native Codex hooks registered, but failed to remove legacy AGENTS.md context from ${CODEX_AGENTS_MD_PATH}.

What it means

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.

Solutions

  1. Open CODEX_AGENTS_MD_PATH and manually remove the claude-mem legacy context block, then re-run the installer
  2. Check file permissions on AGENTS.md and ensure the user can write to it
  3. Back up AGENTS.md, delete the managed section, and let claude-mem native hooks provide context instead
  4. Ignore if you intentionally keep AGENTS.md context and disabled native memory injection

Example fix

// before: AGENTS.md contains stale block
<!-- claude-mem:start -->
...old context...
<!-- claude-mem:end -->
// after: manually remove the managed block, keep user content
My own AGENTS.md rules.
Defensive patterns

Strategy: fallback

Validate before calling

import { accessSync, constants } from 'fs';
try { accessSync(CODEX_AGENTS_MD_PATH, constants.W_OK); } catch { console.warn('AGENTS.md not writable; legacy cleanup will fail'); }

Try / catch

if (!cleanupLegacyCodexAgentsMdContext()) {
  console.warn(`Manually remove legacy claude-mem block from ${CODEX_AGENTS_MD_PATH}.`);
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "failed to write file", "Could not save figure", "Error saving remote file" — file write failed: causes and fixes across languages and libraries — this error's family across 38 libraries.

Related errors


AI-assisted analysis of thedotmack/claude-mem@d8bc9755e7 (2026-09-17). Data as JSON: /api/errors/de5a259df0ce458c. Report an issue: GitHub.

Appendix: source

Thrown at src/services/integrations/CodexCliInstaller.ts:510

    return performCodexInstall(marketplaceRootOverride);
  } catch (error) {
    const message = error instanceof Error ? error.message : String(error);
    console.error(`\nInstallation failed: ${message}`);
    return 1;
  }
}

function performCodexInstall(marketplaceRootOverride?: string): number {
  assertCodexMarketplaceSupported();
  const marketplaceRoot = resolvePluginMarketplaceRoot(marketplaceRootOverride);

  console.log(`  Registering Codex plugin marketplace: ${marketplaceRoot}`);
  registerCodexMarketplace(marketplaceRoot);
  enableCodexPluginConfig();
  runCodex(['plugin', 'add', CODEX_PLUGIN_ID]);
  console.log('  Installed Codex plugin cache.');
  if (!cleanupLegacyCodexAgentsMdContext()) {
    console.warn(`  Native Codex hooks registered, but failed to remove legacy AGENTS.md context from ${CODEX_AGENTS_MD_PATH}.`);
  }
  if (!cleanupLegacyCodexTranscriptAgentsContext()) {
    console.warn(`  Native Codex hooks registered, but failed to disable legacy transcript AGENTS.md context in ${CODEX_TRANSCRIPT_WATCH_CONFIG_PATH}.`);
  }

  console.log(`
Installation complete!

Codex marketplace: ${MARKETPLACE_NAME}
Plugin source:     ${marketplaceRoot}

Next steps:
  1. Open Codex CLI in your project
  2. Review and trust the five claude-mem hooks when Codex prompts you
  3. Restart sessions opened before trusting the hooks

For a fresh setup, the supported entry point is:
  npx claude-mem@latest install

View on GitHub (pinned to d8bc9755e7)