Skip to content

Ambients Suggestions feature uses UserPromptSubmit hook without Stop hook afterwards #18541

Open

Description

@Artein

What version of the Codex App are you using (From “About Codex” dialog)?

Version 26.415.40636 (1799)

What subscription do you have?

Pro

What platform is your computer?

Darwin 25.4.0 arm64 arm

What issue are you seeing?

I am using Codex CLI/App with Unity Editor. I wrote a custom Unity AI Agent Connector that enables Codex to behave appropriately in a Unity environment, especially in an AI-agentic loop. During agent work, I need to show in the UnityEditor that the task is in progress and its status, and block any user input to prevent interference with the agent work.

For that, I am utilizing 2 hooks: UserPromptSubmit and Stop.

It worked great until the recent CodexApp update that added ambient suggestions feature. It looks like they run after any thread is done and/or archived, and call the UserPromptSubmit hook without Stop at the end. That led to infinite "In progress" task in the Unity Editor

Here is how it looks in the Unity Editor:
Image

My hooks.json:

{
  "hooks": {
    "UserPromptSubmit": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "/bin/sh -lc 'dir=\"$PWD\"; while :; do script=\"$dir/.codex/hooks/unity-ai-agent-connector/user_prompt_submit.py\"; if [ -f \"$script\" ]; then exec /usr/bin/python3 \"$script\"; fi; parent=$(dirname \"$dir\"); if [ \"$parent\" = \"$dir\" ]; then printf \"%s\\n\" \"Managed Codex hook script not found: /.codex/hooks/unity-ai-agent-connector/user_prompt_submit.py\" >&2; exit 127; fi; dir=\"$parent\"; done'",
            "timeout": 610,
            "statusMessage": "Starting Unity task"
          }
        ]
      }
    ],
    "Stop": [
      {
        "hooks": [
          {
            "type": "command",
            "command": "/bin/sh -lc 'dir=\"$PWD\"; while :; do script=\"$dir/.codex/hooks/unity-ai-agent-connector/stop.py\"; if [ -f \"$script\" ]; then exec /usr/bin/python3 \"$script\"; fi; parent=$(dirname \"$dir\"); if [ \"$parent\" = \"$dir\" ]; then printf \"%s\\n\" \"Managed Codex hook script not found: /.codex/hooks/unity-ai-agent-connector/stop.py\" >&2; exit 127; fi; dir=\"$parent\"; done'",
            "timeout": 610,
            "statusMessage": "Ending Unity task"
          }
        ]
      }
    ]
  }
}

A few thoughts on how that might be fixed:

  1. Being able to activate/deactivate Ambients Suggestions feature on the project level (Codex App settings, config.toml, etc)
    — [I doubt you do that, cause it really has a product value]
  2. Don't run hooks for Ambient Suggestion feature
    — [still not the best solution]
  3. Fix running Stop hooks
    — [will be a workaround, cause it is still not obvious why should I wait for something CodexApp is doing in the background]
  4. Being able to control which hook should be run during Ambient Suggestion. In the hooks.json set something like runWithAmbientSuggestions for each hook (with true by default)

Severity:
This thing is really annoying. Thankfully, my connector has a Force End feature, which is a workaround for now

What steps can reproduce the bug?

Already explained in the What issue are you seeing? field

What is the expected behavior?

Already explained in the What issue are you seeing? field

Additional information

No response

Activity

  1. added
    appIssues related to the Codex desktop app
    on Apr 19, 2026
  2. added
    bugSomething isn't working
    hooksIssues related to event hooks
    on Apr 19, 2026
  3. github-actions commented on Apr 19, 2026

    @github-actions
    Contributor

    Potential duplicates detected. Please review them and close your issue if it is a duplicate.

    Powered by Codex Action

  4. removed
    appIssues related to the Codex desktop app
    on Apr 19, 2026
  5. Artein commented on Apr 19, 2026

    @Artein
    Author

    It is a separate feature request (which may be a part of the solution for this ticket).

    Anyway, this ticket is about the bug in the Ambient Suggestions feature

  6. oxysoft commented on May 8, 2026

    @oxysoft

    Indexed this hook ticket in the umbrella tracker: #21753

    Goal: collect the scattered Codex hook requests and bugs into one parity matrix for Full Claude Code Hook Parity (29+), while preserving this issue as the detailed thread for its specific behavior.

  7. normancates commented on Oct 1, 2026

    @normancates

    Adding a data point from Codex Desktop (codex.exe 0.158.0, Windows), plus what would fix it for hook authors.

    What we see:

    opening the Desktop app starts ambient suggestion threads and their safety checks, and each one runs the full set of user hooks: SessionStart, UserPromptSubmit, PreToolUse/PostToolUse, Stop and SessionEnd. Memory consolidation threads do too. Nothing in the hook payload says the thread is internal.

    Why it matters:

    our hooks do things that should happen only in a session the user is actually in:

    • A message-delivery hook marked queued messages as delivered to ambient threads that no user ever saw (27 messages lost).
    • Context that SessionStart injects is used by the ambient generator as material: one suggestion quoted our hook output word for word.
    • Consolidation threads followed instructions we inject at SessionStart and read our files before writing ~/.codex/memories.
    • Workaround: transcript_path is null at SessionStart and UserPromptSubmit in every background thread we've captured, and set to an existing rollout in every user thread. We plan to treat "no transcript_path" as "not a user session". But the docs only say "if any", so this is an inference, not a contract.

    Suggested fix:

    Codex already knows the thread kind internally (ambient_suggestions, ambient_suggestion_safety, memory_consolidation). Please either:

    1. pass it to hooks as a field such as thread_source (null or "user" for normal threads), or
    2. don't run user hooks in internal threads, or make that a config option.

    Also: document whether a null transcript_path is a guaranteed signal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghooksIssues related to event hooks

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions