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
- Reinstall agentmemory so plugin/ ships alongside dist/ (npm install -g agentmemory or fresh clone with npm install && npm run build).
- Run the CLI from the repository/package root instead of a copied dist/ directory.
- If packaging into a container/binary, explicitly include the plugin/ directory next to dist/.
- 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
- Never copy dist/ without plugin/ when deploying.
- Verify package integrity after global installs (ls node_modules/agentmemory/plugin).
- Include plugin/ in Docker images and publish file lists.
- Prefer running the CLI via its npm bin entry, not ad-hoc script copies.
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
- ${adapter.displayName}: guideline not written (${gerr instan
- Default data dir ${dataDirResolution.relocatedFrom} is insid
- Claude Code hooks fallback skipped: ${hookResult.reason}. MC
- Codex hooks fallback skipped: ${hookResult.reason}. MCP wiri
- ${config.displayName} hooks skipped: ${hookResult.reason}.
AI-assisted analysis of rohitg00/agentmemory@e04ba88819 (2026-08-30).
Data as JSON: /api/errors/51f1aab1d37a4ec1.
Report an issue: GitHub.