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

Source

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

    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. Restart any running Codex sessions so native hooks are loaded

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

View on GitHub (pinned to e2d1df569a)

Solutions

  1. Open ~/.codex/AGENTS.md and delete the `<claude-mem-context>...</claude-mem-context>` block manually.
  2. Fix file permissions so the installer can rewrite it.
  3. Re-run install to retry the cleanup.
Defensive patterns

Strategy: fallback

Validate before calling

import { readFileSync } from 'node:fs';

const agentsMd = `${process.env.HOME}/.codex/AGENTS.md`;
const hasLegacyBlock = readFileSync(agentsMd, 'utf8').includes('<claude-mem-context>');

Prevention

When it happens

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

Common situations: Read-only or permission-restricted AGENTS.md, hand-edited file with broken tag pairing, or another tool writing it simultaneously.

Related errors


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