How do hooks work in Cursor CLI?

It’s unclear for me how to use hooks.
Fir example, grind loop based on stop event.
This loop will be triggered any time I have any chat?
If I’m just discussing in Cursor chat how to fix a complicated failed test it will still run failed tests and try to fix them 5 times?

hi @Ilnur_Ismagilov Cursor CLI does use hooks hooks to observe, control, and extend the agent loop with custom scripts. These hooks are spawned processes that communicate via stdin/stdout using JSON and can run before or after defined stages of the agent loop. They are triggered automatically: e.g.

stop - on agent completion => when agent finishes the reply

Hooks can be configured in hooks.json at project level (<project>/.cursor/hooks.json) or globally (~/.cursor/hooks.json)

Hooks at Cursor Docs

For your specific issue you could use Cursor IDE since it has the Debug Mode already built in which is better for that task.