rohitg00/agentmemory · warning
Codex runs only trusted hooks: launch `codex` (the TUI) once
Error message
Codex runs only trusted hooks: launch `codex` (the TUI) once and choose "Trust all and continue" at the "Hooks need review" prompt. `codex exec` never shows the prompt, so hooks stay inert until approved in the TUI.
What it means
After installing Codex hooks, agentmemory warns that OpenAI Codex only executes hooks the user has explicitly trusted. Hooks are written to the hooks file, but Codex shows a "Hooks need review" prompt only in the interactive TUI; `codex exec` (non-interactive) never shows it, so the hooks remain inert until approved. This is an upstream behavior (workaround note references openai/codex#16430), not an agentmemory failure.
Source
Thrown at src/cli/connect/codex.ts:172
const merged = buildMergedHooks(existing, pluginRoot);
if (opts.dryRun) {
p.log.info(
`[dry-run] Would ${existing ? "merge" : "create"} ${CODEX_HOOKS} with ${Object.keys(merged.hooks).length} event(s)`,
);
return { kind: "installed", mutatedPath: CODEX_HOOKS };
}
let backupPath: string | undefined;
if (existsSync(CODEX_HOOKS)) {
backupPath = backupFile(CODEX_HOOKS, "codex-hooks", "json");
logBackup(backupPath);
}
writeJsonAtomic(CODEX_HOOKS, merged);
logInstalled("Codex hooks (workaround for openai/codex#16430)", CODEX_HOOKS);
p.log.warn(
"Codex runs only trusted hooks: launch `codex` (the TUI) once and choose \"Trust all and continue\" at the \"Hooks need review\" prompt. `codex exec` never shows the prompt, so hooks stay inert until then.",
);
p.log.info(
"User-scope hooks reference absolute paths under the bundled plugin/ dir. Re-run `agentmemory connect codex --with-hooks` after upgrading agentmemory to refresh them, then re-approve in the TUI.",
);
return {
kind: "installed",
mutatedPath: CODEX_HOOKS,
...(backupPath !== undefined && { backupPath }),
};
}
View on GitHub (pinned to e04ba88819)
Solutions
- Launch `codex` (the TUI) once and choose "Trust all and continue" at the "Hooks need review" prompt.
- After upgrading agentmemory, re-run `agentmemory connect codex --with-hooks` (hooks reference absolute paths under the bundled plugin/ dir) and re-approve in the TUI.
- Avoid relying on Codex hooks in `codex exec`-only workflows; they will never be approved there — run the TUI once interactively first.
- Verify MCP wiring independently if hooks are still needed only for context injection; the MCP server works without hook approval.
Example fix
// before (headless only) codex exec "..." # hooks inert, never prompted // after codex # TUI -> "Hooks need review" -> Trust all and continue codex exec "..." # hooks now run
Defensive patterns
Strategy: fallback
Validate before calling
// Cannot be pre-validated programmatically — Codex only shows the trust
// prompt in the TUI. Detect a likely-inert state by checking for an approval record,
// otherwise prompt the user:
if (process.env.CI || process.env.CLAUDE_CODE_EXEC_MODE === "exec") {
console.warn("codex exec never shows the hooks trust prompt — run `codex` TUI once to approve hooks.");
} Type guard
function hooksApproved(approvedHooks: unknown, hookName: string): boolean {
return Array.isArray(approvedHooks) && approvedHooks.includes(hookName);
} Try / catch
try {
installCodexHooks(opts);
console.warn("Hooks written. If they do not fire, launch `codex` (TUI) and choose 'Trust all and continue'.");
} catch (err) {
console.warn("Hook install failed:", err);
} Prevention
- After every `connect codex --with-hooks` (including upgrades), open the Codex TUI once and approve the hooks.
- Never expect Codex hooks to run in `codex exec`-only or CI workflows without prior TUI approval.
- Re-run `connect codex --with-hooks` after upgrading agentmemory (hooks reference absolute plugin/ paths), then re-approve.
- Verify hooks fire (e.g. check agentmemory audit/state) rather than assuming installation equals activation.
When it happens
Trigger: Always logged right after `agentmemory connect codex --with-hooks` successfully writes the merged hooks file (writeJsonAtomic(CODEX_HOOKS, merged)). It fires on every hook install, including re-installs after upgrades.
Common situations: CI pipelines or scripts using `codex exec` where hooks silently never fire; users who installed hooks but never opened the Codex TUI; users who re-installed hooks after an agentmemory upgrade and forgot to re-approve them in the TUI.
Related errors
- Codex hooks fallback skipped: ${hookResult.reason}. MCP wiri
- agentmemory: could not locate bundled plugin/ directory (sea
- Claude Code hooks fallback skipped: ${hookResult.reason}.
- Claude Code hooks fallback skipped: ${hookResult.reason}. MC
- ${config.displayName} hooks skipped: ${hookResult.reason}.
AI-assisted analysis of rohitg00/agentmemory@e04ba88819 (2026-08-30).
Data as JSON: /api/errors/d99d47fd3644ddf3.
Report an issue: GitHub.