{"record":{"id":"d99d47fd3644ddf3","repo":"rohitg00/agentmemory","slug":"codex-runs-only-trusted-hooks-launch-codex-the","errorCode":null,"errorMessage":"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.","messagePattern":"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\\.","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"src/cli/connect/codex.ts","lineNumber":172,"sourceCode":"  const merged = buildMergedHooks(existing, pluginRoot);\n\n  if (opts.dryRun) {\n    p.log.info(\n      `[dry-run] Would ${existing ? \"merge\" : \"create\"} ${CODEX_HOOKS} with ${Object.keys(merged.hooks).length} event(s)`,\n    );\n    return { kind: \"installed\", mutatedPath: CODEX_HOOKS };\n  }\n\n  let backupPath: string | undefined;\n  if (existsSync(CODEX_HOOKS)) {\n    backupPath = backupFile(CODEX_HOOKS, \"codex-hooks\", \"json\");\n    logBackup(backupPath);\n  }\n\n  writeJsonAtomic(CODEX_HOOKS, merged);\n\n  logInstalled(\"Codex hooks (workaround for openai/codex#16430)\", CODEX_HOOKS);\n  p.log.warn(\n    \"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.\",\n  );\n  p.log.info(\n    \"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.\",\n  );\n\n  return {\n    kind: \"installed\",\n    mutatedPath: CODEX_HOOKS,\n    ...(backupPath !== undefined && { backupPath }),\n  };\n}\n","sourceCodeStart":154,"sourceCodeEnd":185,"githubUrl":"https://github.com/rohitg00/agentmemory/blob/e04ba88819c365c9acf9d6661ea802143e728bd6/src/cli/connect/codex.ts#L154-L185","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before (headless only)\ncodex exec \"...\"   # hooks inert, never prompted\n\n// after\ncodex              # TUI -> \"Hooks need review\" -> Trust all and continue\ncodex exec \"...\"   # hooks now run","handlingStrategy":"fallback","validationCode":"// Cannot be pre-validated programmatically — Codex only shows the trust\n// prompt in the TUI. Detect a likely-inert state by checking for an approval record,\n// otherwise prompt the user:\nif (process.env.CI || process.env.CLAUDE_CODE_EXEC_MODE === \"exec\") {\n  console.warn(\"codex exec never shows the hooks trust prompt — run `codex` TUI once to approve hooks.\");\n}","typeGuard":"function hooksApproved(approvedHooks: unknown, hookName: string): boolean {\n  return Array.isArray(approvedHooks) && approvedHooks.includes(hookName);\n}","tryCatchPattern":"try {\n  installCodexHooks(opts);\n  console.warn(\"Hooks written. If they do not fire, launch `codex` (TUI) and choose 'Trust all and continue'.\");\n} catch (err) {\n  console.warn(\"Hook install failed:\", err);\n}","preventionTips":["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."],"tags":["codex","hooks","trust","interactive"],"backgroundTag":"hooks-not-trusted","analyzedSha":"e04ba88819c365c9acf9d6661ea802143e728bd6","analyzedAt":"2026-08-30T01:07:40.754Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}