codex - 💡(How to fix) Fix SessionStart hook fires on startup but not after /clear

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Root Cause

This does not look like a hook trust or command execution issue because the same hook configuration successfully fires on startup.

Fix Action

Fix / Workaround

This suggests hook discovery, trust, command execution, cwd, Python, and command substitution are working. The failure appears specific to / clear not dispatching SessionStart with source clear.

When a `SessionStart` hook has matcher `clear` or `startup|clear`, running `/clear` should dispatch the hook with `source: "clear"`.

At minimum, if `/clear` is not meant to dispatch `SessionStart`, the docs and `/hooks` UI should make that clear.

Code Example

codex doctor --json returned overallStatus: "ok". I redacted local usernames and absolute paths from the report before pasting.

{
    "schemaVersion": 1,
    "generatedAt": "1779334509s since unix epoch",
    "overallStatus": "ok",
    "codexVersion": "0.132.0",
    "checks": {
      "app_server.status": {
        "id": "app_server.status",
        "category": "app-server",
        "status": "ok",
        "summary": "background server is not running",
        "details": {
          "control socket": "/home/<user>/.codex/app-server-control/app-server-control.sock",
          "daemon state dir": "/home/<user>/.codex/app-server-daemon",
          "mode": "ephemeral",
          "pid file": "/home/<user>/.codex/app-server-daemon/app-server.pid (missing)",
          "settings": "/home/<user>/.codex/app-server-daemon/settings.json (missing)",
          "status": "not running",
          "update-loop pid file": "/home/<user>/.codex/app-server-daemon/app-server-updater.pid (missing)"
        },
        "remediation": null,
        "durationMs": 0
      },
      "auth.credentials": {
        "id": "auth.credentials",
        "category": "auth",
        "status": "ok",
        "summary": "auth is configured",
        "details": {
          "auth file": "/home/<user>/.codex/auth.json",
          "auth storage mode": "File",
          "stored API key": "false",
          "stored ChatGPT tokens": "true",
          "stored agent identity": "false",
          "stored auth mode": "chatgpt"
        },
        "remediation": null,
        "durationMs": 0
      },
      "config.load": {
        "id": "config.load",
        "category": "config",
        "status": "ok",
        "summary": "config loaded",
        "details": {
          "CODEX_HOME": "/home/<user>/.codex",
          "config.toml": "/home/<user>/.codex/config.toml",
          "config.toml parse": "ok",
          "cwd": "/home/<user>/projects/<repo>",
          "enabled feature flags": "shell_tool, unified_exec, shell_snapshot, terminal_resize_reflow, sqlite, memories, hooks,
  enable_request_compression, multi_agent, apps, tool_search, tool_suggest, plugins, plugin_hooks, in_app_browser, browser_use,
  browser_use_external, computer_use, plugin_sharing, external_migration, image_generation, skill_mcp_dependency_install, steer,
  guardian_approval, collaboration_modes, tool_call_mcp_elicitation, personality, fast_mode, tui_app_server, workspace_dependencies",
          "feature flag overrides": "memories=true, external_migration=true",
          "feature flags enabled": "30",
          "log dir": "/home/<user>/.codex/log",
          "mcp servers": "0",
          "model": "<default>",
          "model provider": "openai",
          "sqlite home": "/home/<user>/.codex"
        },
        "remediation": null,
        "durationMs": 0
      },
      "installation": {
        "id": "installation",
        "category": "install",
        "status": "ok",
        "summary": "installation looks consistent",
        "details": {
          "PATH codex #1": "/home/<user>/.nvm/versions/node/v25.9.0/bin/codex",
          "PATH codex #2": "/mnt/c/Users/<windows-user>/AppData/Roaming/npm/codex",
          "PATH codex entries": "2",
          "current executable": "/home/<user>/.nvm/versions/node/v25.9.0/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/
  vendor/x86_64-unknown-linux-musl/codex/codex",
          "install context": "npm",
          "managed by bun": "false",
          "managed by npm": "true",
          "managed package root": "/home/<user>/.nvm/versions/node/v25.9.0/lib/node_modules/@openai/codex",
          "npm update target": "/home/<user>/.nvm/versions/node/v25.9.0/lib/node_modules/@openai/codex"
        },
        "remediation": null,
        "durationMs": 164
      },
      "mcp.config": {
        "id": "mcp.config",
        "category": "mcp",
        "status": "ok",
        "summary": "no MCP servers configured",
        "details": {},
        "remediation": null,
        "durationMs": 0
      },
      "network.env": {
        "id": "network.env",
        "category": "network",
        "status": "ok",
        "summary": "network-related environment looks readable",
        "details": {
          "proxy env vars": "none"
        },
        "remediation": null,
        "durationMs": 0
      },
      "network.provider_reachability": {
        "id": "network.provider_reachability",
        "category": "reachability",
        "status": "ok",
        "summary": "active provider endpoints are reachable over HTTP",
        "details": {
          "ChatGPT base URL": "https://chatgpt.com/backend-api/ reachable (HTTP 404)",
          "reachability mode": "ChatGPT auth"
        },
        "remediation": null,
        "durationMs": 224
      },
      "network.websocket_reachability": {
        "id": "network.websocket_reachability",
        "category": "websocket",
        "status": "ok",
        "summary": "Responses WebSocket handshake succeeded",
        "details": {
          "DNS": "2 IPv4, 2 IPv6, first IPv4",
          "auth mode": "chatgpt",
          "connect timeout": "15000 ms",
          "endpoint": "wss://chatgpt.com/backend-api/<redacted>",
          "handshake result": "HTTP 101 Switching Protocols",
          "model provider": "openai",
          "models etag present": "true",
          "provider name": "OpenAI",
          "proxy env vars": "none",
          "reasoning header": "false",
          "server model present": "false",
          "supports websockets": "true",
          "wire API": "responses"
        },
        "remediation": null,
        "durationMs": 910
      },
      "runtime.provenance": {
        "id": "runtime.provenance",
        "category": "runtime",
        "status": "ok",
        "summary": "running npm on linux-x86_64",
        "details": {
          "commit": "unknown",
          "current executable": "/home/<user>/.nvm/versions/node/v25.9.0/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/
  vendor/x86_64-unknown-linux-musl/codex/codex",
          "install method": "npm",
          "platform": "linux-x86_64",
          "version": "0.132.0"
        },
        "remediation": null,
        "durationMs": 0
      },
      "runtime.search": {
        "id": "runtime.search",
        "category": "search",
        "status": "ok",
        "summary": "search is OK (system)",
        "details": {
          "search command": "rg",
          "search command readiness": "ripgrep 15.1.0 (rev af60c2de9d)",
          "search provider": "system"
        },
        "remediation": null,
        "durationMs": 0
      },
      "sandbox.helpers": {
        "id": "sandbox.helpers",
        "category": "sandbox",
        "status": "ok",
        "summary": "sandbox configuration is readable",
        "details": {
          "approval policy": "OnRequest",
          "codex-linux-sandbox helper": "/home/<user>/.codex/tmp/arg0/<redacted>/codex-linux-sandbox",
          "execve wrapper helper": "/home/<user>/.codex/tmp/arg0/<redacted>/codex-execve-wrapper",
          "filesystem sandbox": "restricted",
          "network sandbox": "restricted"
        },
        "remediation": null,
        "durationMs": 0
      },
      "state.paths": {
        "id": "state.paths",
        "category": "state",
        "status": "ok",
        "summary": "state paths and databases are inspectable",
        "details": {
          "CODEX_HOME": "/home/<user>/.codex (dir)",
          "active rollout files": "9 files, 3660885 total bytes, 406765 average bytes",
          "archived rollout files": "0 files, 0 total bytes, 0 average bytes",
          "log DB": "/home/<user>/.codex/logs_2.sqlite (file)",
          "log DB integrity": "ok",
          "log dir": "/home/<user>/.codex/log (dir)",
          "sqlite home": "/home/<user>/.codex (dir)",
          "state DB": "/home/<user>/.codex/state_5.sqlite (file)",
          "state DB integrity": "ok"
        },
        "remediation": null,
        "durationMs": 986
      },
      "terminal.env": {
        "id": "terminal.env",
        "category": "terminal",
        "status": "ok",
        "summary": "terminal metadata was detected",
        "details": {
          "DISPLAY": "present",
          "WAYLAND_DISPLAY": "present",
          "WSL_DISTRO_NAME": "present",
          "WSL_INTEROP": "present",
          "WT_SESSION": "present",
          "color output": "enabled",
          "effective locale": "C.UTF-8",
          "stderr is terminal": "true",
          "stdin is terminal": "true",
          "stdout is terminal": "true",
          "terminal": "Windows Terminal",
          "terminal size": "143x32"
        },
        "remediation": null,
        "durationMs": 0
      },
      "updates.status": {
        "id": "updates.status",
        "category": "updates",
        "status": "ok",
        "summary": "update configuration is locally consistent",
        "details": {
          "cached latest version": "0.132.0",
          "check for update on startup": "true",
          "last checked at": "2026-05-21T01:44:40.704487735Z",
          "latest version": "0.132.0",
          "latest version status": "current version is not older",
          "npm update target": "/home/<user>/.nvm/versions/node/v25.9.0/lib/node_modules/@openai/codex",
          "update action": "npm install -g @openai/codex",
          "version cache": "/home/<user>/.codex/version.json"
        },
        "remediation": null,
        "durationMs": 405
      }
    }
  }

---

"matcher": "startup|clear"

  The hook is visible and trusted in /hooks.

  Diagnostics show:

  - startup triggers the hook successfully.
  - A shell-only command hook runs on startup.
  - An absolute-path Python command hook runs on startup.
  - A Python hook using $(git rev-parse --show-toplevel) also runs on startup.
  - After using /clear, no new hook log entries are written.

  This suggests hook discovery, trust, command execution, cwd, Python, and command substitution are working. The failure appears specific to /
  clear not dispatching SessionStart with source clear.

  Related docs issue: #19666

### What steps can reproduce the bug?

Uploaded thread: 019e4834-c283-7c41-a6d0-826e912862ba

I also tested absolute-path Python and `$(git rev-parse --show-toplevel)` Python probes. Both fired on `startup`, but none fired after `/
  clear`, so the minimal shell-only repro should be sufficient.

Steps:

---

{
    "hooks": {
      "SessionStart": [
        {
          "matcher": "startup|clear",
          "hooks": [
            {
              "type": "command",
              "command": "sh -c 'mkdir -p /tmp/codex-harness-hook-logs && printf \"%s sessionstart shell cwd=%s\\n\" \"$(date -Is)\" \"$PWD\"
  >> /tmp/codex-harness-hook-logs/session_start_shell.log'",
              "timeout": 10,
              "statusMessage": "Logging SessionStart shell probe"
            },
            {
              "type": "command",
              "command": "python3 /home/zeldrix/projects/harness/.codex/hooks/session_start_clear_debug.py",
              "timeout": 10,
              "statusMessage": "Logging SessionStart absolute Python probe"
            },
            {
              "type": "command",
              "command": "python3 \"$(git rev-parse --show-toplevel)/.codex/hooks/session_start_clear_debug.py\"",
              "timeout": 10,
              "statusMessage": "Logging SessionStart git-root Python probe"
            }
          ]
        }
      ]
    }
  }

  2. Open Codex in the repo.
  3. Open /hooks and trust the hook.
  4. Fully exit Codex.
  5. Start Codex again from the repo root.
  6. Confirm startup fired:

  tail -n 20 /tmp/codex-harness-hook-logs/session_start_shell.log

  7. In Codex, send any message, then run /clear.
  8. Check the same logs again.


### What is the expected behavior?

---

### Additional information
RAW_BUFFERClick to expand / collapse

What version of Codex CLI is running?

codex-cli 0.132.0

What subscription do you have?

ChatGPT Free. Signed in with ChatGPT using a Free account.

Which model were you using?

gpt-5.5

What platform is your computer?

Linux 6.6.114.1-microsoft-standard-WSL2 x86_64 x86_64

What terminal emulator and version are you using (if applicable)?

Windows Terminal on WSL2, TERM=xterm-256color, no tmux/zellij

Codex doctor report

codex doctor --json returned overallStatus: "ok". I redacted local usernames and absolute paths from the report before pasting.

{
    "schemaVersion": 1,
    "generatedAt": "1779334509s since unix epoch",
    "overallStatus": "ok",
    "codexVersion": "0.132.0",
    "checks": {
      "app_server.status": {
        "id": "app_server.status",
        "category": "app-server",
        "status": "ok",
        "summary": "background server is not running",
        "details": {
          "control socket": "/home/<user>/.codex/app-server-control/app-server-control.sock",
          "daemon state dir": "/home/<user>/.codex/app-server-daemon",
          "mode": "ephemeral",
          "pid file": "/home/<user>/.codex/app-server-daemon/app-server.pid (missing)",
          "settings": "/home/<user>/.codex/app-server-daemon/settings.json (missing)",
          "status": "not running",
          "update-loop pid file": "/home/<user>/.codex/app-server-daemon/app-server-updater.pid (missing)"
        },
        "remediation": null,
        "durationMs": 0
      },
      "auth.credentials": {
        "id": "auth.credentials",
        "category": "auth",
        "status": "ok",
        "summary": "auth is configured",
        "details": {
          "auth file": "/home/<user>/.codex/auth.json",
          "auth storage mode": "File",
          "stored API key": "false",
          "stored ChatGPT tokens": "true",
          "stored agent identity": "false",
          "stored auth mode": "chatgpt"
        },
        "remediation": null,
        "durationMs": 0
      },
      "config.load": {
        "id": "config.load",
        "category": "config",
        "status": "ok",
        "summary": "config loaded",
        "details": {
          "CODEX_HOME": "/home/<user>/.codex",
          "config.toml": "/home/<user>/.codex/config.toml",
          "config.toml parse": "ok",
          "cwd": "/home/<user>/projects/<repo>",
          "enabled feature flags": "shell_tool, unified_exec, shell_snapshot, terminal_resize_reflow, sqlite, memories, hooks,
  enable_request_compression, multi_agent, apps, tool_search, tool_suggest, plugins, plugin_hooks, in_app_browser, browser_use,
  browser_use_external, computer_use, plugin_sharing, external_migration, image_generation, skill_mcp_dependency_install, steer,
  guardian_approval, collaboration_modes, tool_call_mcp_elicitation, personality, fast_mode, tui_app_server, workspace_dependencies",
          "feature flag overrides": "memories=true, external_migration=true",
          "feature flags enabled": "30",
          "log dir": "/home/<user>/.codex/log",
          "mcp servers": "0",
          "model": "<default>",
          "model provider": "openai",
          "sqlite home": "/home/<user>/.codex"
        },
        "remediation": null,
        "durationMs": 0
      },
      "installation": {
        "id": "installation",
        "category": "install",
        "status": "ok",
        "summary": "installation looks consistent",
        "details": {
          "PATH codex #1": "/home/<user>/.nvm/versions/node/v25.9.0/bin/codex",
          "PATH codex #2": "/mnt/c/Users/<windows-user>/AppData/Roaming/npm/codex",
          "PATH codex entries": "2",
          "current executable": "/home/<user>/.nvm/versions/node/v25.9.0/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/
  vendor/x86_64-unknown-linux-musl/codex/codex",
          "install context": "npm",
          "managed by bun": "false",
          "managed by npm": "true",
          "managed package root": "/home/<user>/.nvm/versions/node/v25.9.0/lib/node_modules/@openai/codex",
          "npm update target": "/home/<user>/.nvm/versions/node/v25.9.0/lib/node_modules/@openai/codex"
        },
        "remediation": null,
        "durationMs": 164
      },
      "mcp.config": {
        "id": "mcp.config",
        "category": "mcp",
        "status": "ok",
        "summary": "no MCP servers configured",
        "details": {},
        "remediation": null,
        "durationMs": 0
      },
      "network.env": {
        "id": "network.env",
        "category": "network",
        "status": "ok",
        "summary": "network-related environment looks readable",
        "details": {
          "proxy env vars": "none"
        },
        "remediation": null,
        "durationMs": 0
      },
      "network.provider_reachability": {
        "id": "network.provider_reachability",
        "category": "reachability",
        "status": "ok",
        "summary": "active provider endpoints are reachable over HTTP",
        "details": {
          "ChatGPT base URL": "https://chatgpt.com/backend-api/ reachable (HTTP 404)",
          "reachability mode": "ChatGPT auth"
        },
        "remediation": null,
        "durationMs": 224
      },
      "network.websocket_reachability": {
        "id": "network.websocket_reachability",
        "category": "websocket",
        "status": "ok",
        "summary": "Responses WebSocket handshake succeeded",
        "details": {
          "DNS": "2 IPv4, 2 IPv6, first IPv4",
          "auth mode": "chatgpt",
          "connect timeout": "15000 ms",
          "endpoint": "wss://chatgpt.com/backend-api/<redacted>",
          "handshake result": "HTTP 101 Switching Protocols",
          "model provider": "openai",
          "models etag present": "true",
          "provider name": "OpenAI",
          "proxy env vars": "none",
          "reasoning header": "false",
          "server model present": "false",
          "supports websockets": "true",
          "wire API": "responses"
        },
        "remediation": null,
        "durationMs": 910
      },
      "runtime.provenance": {
        "id": "runtime.provenance",
        "category": "runtime",
        "status": "ok",
        "summary": "running npm on linux-x86_64",
        "details": {
          "commit": "unknown",
          "current executable": "/home/<user>/.nvm/versions/node/v25.9.0/lib/node_modules/@openai/codex/node_modules/@openai/codex-linux-x64/
  vendor/x86_64-unknown-linux-musl/codex/codex",
          "install method": "npm",
          "platform": "linux-x86_64",
          "version": "0.132.0"
        },
        "remediation": null,
        "durationMs": 0
      },
      "runtime.search": {
        "id": "runtime.search",
        "category": "search",
        "status": "ok",
        "summary": "search is OK (system)",
        "details": {
          "search command": "rg",
          "search command readiness": "ripgrep 15.1.0 (rev af60c2de9d)",
          "search provider": "system"
        },
        "remediation": null,
        "durationMs": 0
      },
      "sandbox.helpers": {
        "id": "sandbox.helpers",
        "category": "sandbox",
        "status": "ok",
        "summary": "sandbox configuration is readable",
        "details": {
          "approval policy": "OnRequest",
          "codex-linux-sandbox helper": "/home/<user>/.codex/tmp/arg0/<redacted>/codex-linux-sandbox",
          "execve wrapper helper": "/home/<user>/.codex/tmp/arg0/<redacted>/codex-execve-wrapper",
          "filesystem sandbox": "restricted",
          "network sandbox": "restricted"
        },
        "remediation": null,
        "durationMs": 0
      },
      "state.paths": {
        "id": "state.paths",
        "category": "state",
        "status": "ok",
        "summary": "state paths and databases are inspectable",
        "details": {
          "CODEX_HOME": "/home/<user>/.codex (dir)",
          "active rollout files": "9 files, 3660885 total bytes, 406765 average bytes",
          "archived rollout files": "0 files, 0 total bytes, 0 average bytes",
          "log DB": "/home/<user>/.codex/logs_2.sqlite (file)",
          "log DB integrity": "ok",
          "log dir": "/home/<user>/.codex/log (dir)",
          "sqlite home": "/home/<user>/.codex (dir)",
          "state DB": "/home/<user>/.codex/state_5.sqlite (file)",
          "state DB integrity": "ok"
        },
        "remediation": null,
        "durationMs": 986
      },
      "terminal.env": {
        "id": "terminal.env",
        "category": "terminal",
        "status": "ok",
        "summary": "terminal metadata was detected",
        "details": {
          "DISPLAY": "present",
          "WAYLAND_DISPLAY": "present",
          "WSL_DISTRO_NAME": "present",
          "WSL_INTEROP": "present",
          "WT_SESSION": "present",
          "color output": "enabled",
          "effective locale": "C.UTF-8",
          "stderr is terminal": "true",
          "stdin is terminal": "true",
          "stdout is terminal": "true",
          "terminal": "Windows Terminal",
          "terminal size": "143x32"
        },
        "remediation": null,
        "durationMs": 0
      },
      "updates.status": {
        "id": "updates.status",
        "category": "updates",
        "status": "ok",
        "summary": "update configuration is locally consistent",
        "details": {
          "cached latest version": "0.132.0",
          "check for update on startup": "true",
          "last checked at": "2026-05-21T01:44:40.704487735Z",
          "latest version": "0.132.0",
          "latest version status": "current version is not older",
          "npm update target": "/home/<user>/.nvm/versions/node/v25.9.0/lib/node_modules/@openai/codex",
          "update action": "npm install -g @openai/codex",
          "version cache": "/home/<user>/.codex/version.json"
        },
        "remediation": null,
        "durationMs": 405
      }
    }
  }

What issue are you seeing?

SessionStart hooks fire for startup, but do not fire after /clear.

I configured a trusted project hook in <repo>/.codex/hooks.json with:

"matcher": "startup|clear"

The hook is visible and trusted in /hooks.

Diagnostics show:

- startup triggers the hook successfully.
- A shell-only command hook runs on startup.
- An absolute-path Python command hook runs on startup.
- A Python hook using $(git rev-parse --show-toplevel) also runs on startup.
- After using /clear, no new hook log entries are written.

This suggests hook discovery, trust, command execution, cwd, Python, and command substitution are working. The failure appears specific to /
clear not dispatching SessionStart with source clear.

Related docs issue: #19666

### What steps can reproduce the bug?

Uploaded thread: 019e4834-c283-7c41-a6d0-826e912862ba

I also tested absolute-path Python and `$(git rev-parse --show-toplevel)` Python probes. Both fired on `startup`, but none fired after `/
clear`, so the minimal shell-only repro should be sufficient.

Steps:
````markdown
1. In a trusted repo, create `.codex/hooks.json`:

```json
{
  "hooks": {
    "SessionStart": [
      {
        "matcher": "startup|clear",
        "hooks": [
          {
            "type": "command",
            "command": "sh -c 'mkdir -p /tmp/codex-harness-hook-logs && printf \"%s sessionstart shell cwd=%s\\n\" \"$(date -Is)\" \"$PWD\"
>> /tmp/codex-harness-hook-logs/session_start_shell.log'",
            "timeout": 10,
            "statusMessage": "Logging SessionStart shell probe"
          },
          {
            "type": "command",
            "command": "python3 /home/zeldrix/projects/harness/.codex/hooks/session_start_clear_debug.py",
            "timeout": 10,
            "statusMessage": "Logging SessionStart absolute Python probe"
          },
          {
            "type": "command",
            "command": "python3 \"$(git rev-parse --show-toplevel)/.codex/hooks/session_start_clear_debug.py\"",
            "timeout": 10,
            "statusMessage": "Logging SessionStart git-root Python probe"
          }
        ]
      }
    ]
  }
}

2. Open Codex in the repo.
3. Open /hooks and trust the hook.
4. Fully exit Codex.
5. Start Codex again from the repo root.
6. Confirm startup fired:

tail -n 20 /tmp/codex-harness-hook-logs/session_start_shell.log

7. In Codex, send any message, then run /clear.
8. Check the same logs again.


### What is the expected behavior?

```markdown
When a `SessionStart` hook has matcher `clear` or `startup|clear`, running `/clear` should dispatch the hook with `source: "clear"`.

At minimum, if `/clear` is not meant to dispatch `SessionStart`, the docs and `/hooks` UI should make that clear.

Additional information

I updated Codex with `codex update`; the latest version remains `codex-cli 0.132.0`.

`codex doctor --json` reports `overallStatus: "ok"` in full-access mode.

This does not look like a hook trust or command execution issue because the same hook configuration successfully fires on `startup`.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

codex - 💡(How to fix) Fix SessionStart hook fires on startup but not after /clear