gemini-cli - 💡(How to fix) Fix SessionStart hook's systemMessage renders twice (BeforeAgent/BeforeTool render once) [1 participants]

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…
GitHub stats
google-gemini/gemini-cli#25655Fetched 2026-04-20 12:15:52
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Participants
Timeline (top)
labeled ×2

When a SessionStart hook emits a systemMessage response, Gemini CLI v0.38.2 renders it twice at session start — once with a trailing [node "…"] command-annotation tag, once without. The same hook wired to BeforeAgent or BeforeTool renders only once, so the duplication appears specific to the SessionStart event.

Root Cause

When a SessionStart hook emits a systemMessage response, Gemini CLI v0.38.2 renders it twice at session start — once with a trailing [node "…"] command-annotation tag, once without. The same hook wired to BeforeAgent or BeforeTool renders only once, so the duplication appears specific to the SessionStart event.

Fix Action

Fix / Workaround

  • Also observed: systemMessage is not ANSI-interpreted — escape sequences like \x1b[1m render as literal \u001b[... text. This is likely intentional (safety) but worth documenting.
  • Setting "notifications": false on the hook entry (suggested by Gemini CLI itself as a workaround) does not change behavior — the key appears to be silently dropped.

Code Example

let _=''; process.stdin.on('data',d=>_+=d);
process.stdin.on('end',()=>{
  console.log(JSON.stringify({ systemMessage: 'hello from the hook' }));
});

---

{
  "hooks": {
    "SessionStart": [
      {
        "matcher": "*",
        "hooks": [
          { "type": "command", "command": "node C:/tmp/hello-hook.js" }
        ]
      }
    ]
  }
}

---

ℹ hello from the hook
   --- [node "C:/tmp/hello-hook.js"]

ℹ hello from the hook
   ---
RAW_BUFFERClick to expand / collapse

Summary

When a SessionStart hook emits a systemMessage response, Gemini CLI v0.38.2 renders it twice at session start — once with a trailing [node "…"] command-annotation tag, once without. The same hook wired to BeforeAgent or BeforeTool renders only once, so the duplication appears specific to the SessionStart event.

Version

  • Gemini CLI v0.38.2
  • Windows 11 (PowerShell / Git Bash, same behavior)
  • Node 24.14.0

Minimal repro

  1. Save this script as C:/tmp/hello-hook.js:
let _=''; process.stdin.on('data',d=>_+=d);
process.stdin.on('end',()=>{
  console.log(JSON.stringify({ systemMessage: 'hello from the hook' }));
});
  1. Add to ~/.gemini/settings.json:
{
  "hooks": {
    "SessionStart": [
      {
        "matcher": "*",
        "hooks": [
          { "type": "command", "command": "node C:/tmp/hello-hook.js" }
        ]
      }
    ]
  }
}
  1. Run gemini in any directory.

Expected

Single hello from the hook banner.

Actual

Two identical banners:

ℹ hello from the hook
   --- [node "C:/tmp/hello-hook.js"]

ℹ hello from the hook
   ---

Swap the event name to BeforeAgent or BeforeTool (with an appropriate trigger) — only one banner renders. So the double-rendering path is specific to SessionStart.

Additional notes

  • Also observed: systemMessage is not ANSI-interpreted — escape sequences like \x1b[1m render as literal \u001b[... text. This is likely intentional (safety) but worth documenting.
  • Setting "notifications": false on the hook entry (suggested by Gemini CLI itself as a workaround) does not change behavior — the key appears to be silently dropped.

extent analysis

TL;DR

The issue can be potentially resolved by modifying the SessionStart hook to handle the response differently or by exploring alternative events like BeforeAgent or BeforeTool that do not exhibit the double-rendering behavior.

Guidance

  • Investigate the SessionStart event handling in Gemini CLI v0.38.2 to understand why systemMessage responses are rendered twice, specifically focusing on how the event differs from BeforeAgent or BeforeTool.
  • Consider modifying the hook script (hello-hook.js) to conditionally handle or suppress the duplicate output based on the event type or environment.
  • Test the behavior with different hook configurations and events to isolate the cause of the duplication and identify potential workarounds.
  • Review the Gemini CLI documentation and source code for any clues on handling systemMessage responses uniquely for the SessionStart event.

Example

No specific code example can be provided without further investigation into the Gemini CLI's internal handling of hooks and events. However, the issue suggests that the solution may involve customizing the hook script or exploring different event triggers.

Notes

The provided information suggests that the issue is specific to the SessionStart event in Gemini CLI v0.38.2. The behavior of rendering systemMessage responses twice with this event, but not with others, indicates a potential bug or undocumented feature in the CLI's event handling mechanism.

Recommendation

Apply a workaround by using the BeforeAgent or BeforeTool events instead of SessionStart for hooks that emit systemMessage responses, as these events do not exhibit the double-rendering issue. This approach allows for functional hooks without waiting for a potential fix in a future version of Gemini CLI.

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