Claude Code's /goal: How a Stop Hook Prevents Unintended Early Session Termination
Ado Kukic demonstrates the underlying mechanism of the /goal feature: a session-level stop prompt hook reads the defined goal and full conversation history, and blocks session termination with actionable next-step guidance if the task is not finished. This design turns the stated goal into a formal exit condition, while exposing the core challenges of building long-running task agents.
Ado Kukic dissected the internal implementation of Claude Code's /goal feature. Claude Code is Anthropic's command-line coding agent, and while /goal appears to simply let users assign a target to the agent on the surface, the actual core component that drives the functionality in the demo is a session-level stop prompt hook.
The workflow is not complicated. Right before a session is marked to end, the stop hook is triggered. The checker embedded in the hook reads two sets of data: the goal you set, and the full current conversation history. If the goal is not yet achieved, the hook denies the session permission to stop, and attaches an explanation that tells the model what direction to take for the next round. Every time the hook rejects session termination, it comes with clear operational guidance.
This implementation is far more rigorous and production-ready than a generic prompt line like "please complete the target first". The goal is no longer a vague slogan, but a hard exit condition, so the model cannot stop working just because its current response looks complete enough. For long-running task agents, this difference has very tangible practical value. When writing code, modifying configurations and running tests, half-finished work is most often incorrectly marked as done the moment it "looks almost right". The stop hook acts here as a strict checkpoint that does not greenlight completion easily.
However, this design also exposes obvious pain points. The checker itself must be completely reliable, and the target has to be objectively verifiable. If you set a vague goal like "optimize the project", the checker can only infer progress from the conversation context, which can easily lead to endless loops of repeated rejections. Only when the goal is clearly defined as something verifiable such as "all tests pass with zero lint errors", can the hook have a clear and definite basis to block premature termination. The most valuable part of the demo is the demonstration of how exit conditions are implemented through proper engineering, rather than the fancy trick prompt hacks that many people pay extra attention to.
Original source link: https://x.com/adocomplete/status/2129653467438624817
via AIHOT:https://aihot.news/items/esdmdcb323qh4itvayb0zzlpp
发布时间: 2026-12-07 03:05