rohitg00/agentmemory · error · Error

agentmemory: could not locate bundled plugin/ directory (sea

Error message

agentmemory: could not locate bundled plugin/ directory (searched up from ${here})

What it means

agentmemory ships hook installer assets in a bundled plugin/ directory. findPluginRoot walks up from the running module's location looking for that directory, and throws if none is found. This indicates a broken/partial installation rather than a user input problem.

Source

Thrown at src/cli/connect/codex-hooks.ts:58

 * module's own location looking for `plugin/scripts/` + `plugin/hooks/`,
 * both shipped via the npm `files` field. Works for both `dist/cli.mjs`
 * (bundled) and `src/cli/connect/codex-hooks.ts` (dev) layouts.
 */
export function findPluginRoot(startUrl: string = import.meta.url): string {
  const here = dirname(fileURLToPath(startUrl));
  let dir = here;
  for (let i = 0; i < 12; i++) {
    if (
      existsSync(join(dir, "plugin", "scripts")) &&
      existsSync(join(dir, "plugin", "hooks"))
    ) {
      return resolve(join(dir, "plugin"));
    }
    const parent = dirname(dir);
    if (parent === dir) break;
    dir = parent;
  }
  throw new Error(
    `agentmemory: could not locate bundled plugin/ directory (searched up from ${here})`,
  );
}

/**
 * Build the merged hooks.json content.
 *
 *   1. Strip any entry from `existing` whose first hook command points
 *      under `<pluginRoot>/scripts/`. This lets us re-install idempotently
 *      without leaving stale references.
 *   2. Append fresh entries from the bundled Codex manifest with
 *      `${CLAUDE_PLUGIN_ROOT}` rewritten to the absolute plugin path.
 *      Matcher values from the bundled manifest are preserved so PreToolUse
 *      event routing keeps working.
 */
export function buildMergedHooks(
  existing: HookManifest | null,
  pluginRoot: string,

View on GitHub (pinned to e04ba88819)

Solutions

  1. Reinstall agentmemory so plugin/ ships alongside dist/ (npm install -g agentmemory or fresh clone with npm install && npm run build).
  2. Run the CLI from the repository/package root instead of a copied dist/ directory.
  3. If packaging into a container/binary, explicitly include the plugin/ directory next to dist/.
  4. Check the package 'files' field / publish pipeline if you maintain a fork.

Example fix

// before (deploy script)
cp -r dist/ /app/
// after
cp -r dist/ /app/
cp -r plugin/ /app/
Defensive patterns

Strategy: validation

Validate before calling

import { existsSync } from 'node:fs';
import { join, dirname } from 'node:path';
let dir = __dirname;
while (dir !== dirname(dir)) {
  if (existsSync(join(dir, 'plugin'))) break;
  dir = dirname(dir);
}
if (!existsSync(join(dir, 'plugin'))) throw new Error('agentmemory installed without plugin/ assets');

Type guard

function hasPluginRoot(base: string): boolean {
  try { return existsSync(join(base, 'plugin')) && statSync(join(base, 'plugin')).isDirectory(); }
  catch { return false; }
}

Try / catch

try {
  await installCodexHooks();
} catch (e) {
  if (String(e.message).includes('could not locate bundled plugin/')) {
    console.error('Reinstall agentmemory: npm i -g agentmemory');
    process.exitCode = 1;
  } else throw e;
}

Prevention

When it happens

Trigger: Running `agentmemory connect` subcommands (codex, claude, droid, devin, antigravity hook installers) from an install where dist/ was copied without the plugin/ directory, or running from a globally installed package stripped of non-JS assets.

Common situations: npm global installs with --omit=optional or package 'files' whitelist excluding plugin/; copying dist/ into a container image without plugin/; running via a bundled binary or tsx from a temp dir.

Related errors


AI-assisted analysis of rohitg00/agentmemory@e04ba88819 (2026-08-30). Data as JSON: /api/errors/51f1aab1d37a4ec1. Report an issue: GitHub.