# Hooks afterAgentResponse / afterAgentThought not firing in headless CLI

**URL:** <https://forum.cursor.com/t/hooks-afteragentresponse-afteragentthought-not-firing-in-headless-cli/156220>\
**Category:** Bug Reports\
**Tags:** hooks, cli\
**Created:** [March 30, 2026, 9:39am UTC](https://forum.cursor.com/t/hooks-afteragentresponse-afteragentthought-not-firing-in-headless-cli/156220 "2026-03-30T09:39:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![weiji](https://avatars.discourse-cdn.com/v4/letter/w/85f322/32.png) [@weiji](https://forum.cursor.com/u/weiji)\
**Post date:** [March 30, 2026, 9:39am UTC](https://forum.cursor.com/t/hooks-afteragentresponse-afteragentthought-not-firing-in-headless-cli/156220/1 "2026-03-30T09:39:08Z")

</div>

I’ve been experimenting with Cursor hooks in **headless CLI mode** (`agent --print`) and noticed that only `sessionStart` fires, while `afterAgentResponse` and `afterAgentThought` do not. I wanted to confirm whether this is by design or a gap worth addressing.

### **Environment**

- Cursor CLI version: `2026.02.27-e7d2ef6`

- Cursor IDE version: `2.6.21` (same machine, same workspace, same `hooks.json`)

- OS: Linux (Ubuntu)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/colin/32/90452_2.png) [@Colin](https://forum.cursor.com/u/Colin)\
**Post date:** [March 30, 2026, 10:27am UTC](https://forum.cursor.com/t/hooks-afteragentresponse-afteragentthought-not-firing-in-headless-cli/156220/6 "2026-03-30T10:27:05Z")

</div>

Hey there!

Thanks for the report — this is a known gap! `afterAgentResponse` and `afterAgentThought` are not currently dispatched in the CLI. We’re tracking this internally as a bug.

A few workarounds depending on your use case:

- The `stop` hook fires at the end of each agent turn in CLI mode and is the closest substitute for `afterAgentResponse`. Tool-level hooks like `postToolUse`, `afterFileEdit`, and `afterShellExecution` also work in CLI if you need per-action visibility.

- If you’re mainly after the response text and thinking content, `--output-format stream-json` streams structured JSON events to stdout — including `thinking` deltas/completion and the full `assistant` message, plus a final `result` event with token usage and request ID. Same data the hooks would give you, just via stdout rather than hook invocation.

What’s your use case for these hooks? Knowing that would help us point you to the best workaround. 🙂 Or maybe you were just testing, in which case thank you for reporting the issue. 🙏

---

<div class="post-metadata">

**Author:** ![weiji](https://avatars.discourse-cdn.com/v4/letter/w/85f322/32.png) [@weiji](https://forum.cursor.com/u/weiji)\
**Post date:** [March 30, 2026, 10:45am UTC](https://forum.cursor.com/t/hooks-afteragentresponse-afteragentthought-not-firing-in-headless-cli/156220/7 "2026-03-30T10:45:17Z")

</div>

Thanks for confirming and for the workaround tips — really helpful!

Our use case: we run Cursor’s headless CLI (`agent --print`) as the execution backend for an internal automation platform. Each task is a fully unattended agent session driven by custom skills.

We need to capture the intermediate steps — thinking, per-turn responses, and tool calls — for:

1. **Observability / audit** : Understanding what the agent did and why, especially when a task produces unexpected results.

2. **Skill optimization** : Analyzing traces across runs to identify where our skills lead to unnecessary tool call loops, poor reasoning paths, or excessive token usage, so we can iteratively improve them.

Good to know `stop` and `postToolUse` / `afterFileEdit` / `afterShellExecution` already work in CLI — we’ll wire those up in the meantime. Looking forward to the fix!

---

<div class="post-metadata">

**Author:** ![system](https://sea3.discourse-cdn.com/cursor1/user_avatar/forum.cursor.com/system/32/99069_2.png) [@system](https://forum.cursor.com/u/system)\
**Post date:** [April 30, 2026, 2:40pm UTC](https://forum.cursor.com/t/hooks-afteragentresponse-afteragentthought-not-firing-in-headless-cli/156220/9 "2026-04-30T14:40:36Z")

</div>

Closed on April 30, 2026, 2:40pm UTC

This topic was automatically closed 22 days after the last reply. New replies are no longer allowed.
