A common limitation of AI agents is that the conversation stops once a task is completed, breaking your flow and forcing you to manually figure out the next step. What if the agent could proactively ask you what to do next, every single time?
This lesson demonstrates a powerful technique using Claude Code's Stop hook to create a truly continuous and interactive workflow. By intercepting the agent's attempt to stop, you can programmatically block it and instead instruct it to use the AskUserQuestion tool. This transforms your AI into a persistent assistant that always guides you through the next phase of your project.
Stop Hook: Set up a hook in your local settings that triggers on every conversation stop."decision": "block" JSON object, preventing the agent from stopping.reason in the JSON to instruct the agent to use the AskUserQuestion tool and continue the conversation.This lesson teaches an advanced technique for creating a continuous AI workflow using Claude Code's Stop hook. Instead of letting the AI agent end the conversation after completing a task, you can intercept the "stop" event. By configuring a hook that runs a script to return a block decision, you programmatically prevent the agent from stopping. The script also provides a reason that instructs the agent to use the AskUserQuestion tool. This results in a powerful, guided loop where the AI always asks "What would you like to do next?", presenting you with context-aware options and allowing you to build and refine projects iteratively in a single, seamless session.
Please create a CLI.ts file, which is just a simple demo CLI in the root of the project.
# Start claude with the haiku model for speed
claude --model haiku
The settings.local.json file is configured to run a command whenever the agent attempts to stop.
{
"hooks": {
"Stop": [
{
"matcher": "",
"hooks": [
{
"type": "command",
"command": "bun run .claude/hooks/index.ts"
}
]
}
]
}
}
The hook script (index.ts) returns a JSON object that blocks the stop action and provides a reason for the AI to continue.
import type { HookJSONOutput } from "@anthropic-ai/claude-agent-sdk";
const output: HookJSONOutput = {
decision: "block",
reason: "Use the AskUserQuestion tool to continue refining what to do next",
};
console.log(JSON.stringify(output));
A helper ZSH function to quickly initialize this hook setup in any project.
hooks-init(){
mkdir -p .claude/hooks
# capture the current directory
local current_dir=$(pwd)
# set cwd to .claude/hooks
cd .claude/hooks
bun init --yes
bun i @anthropic-ai/claude-agent-sdk
cat <<'EOF' > index.ts
import type { } from "@anthropic-ai/claude-agent-sdk"
const input = await Bun.stdin.json();
EOF
# set cwd to the current directory
cd $current_dir
cursor .claude/hooks/index.ts
claude --model haiku "/hooks"
}
[00:00] An interesting way to use the ask user question tool is by forcing it to run in the stop hook. To demonstrate I'll start up Cloud with the model set to haiku for a little bit more speed, and I'll say please create a cli.ts file which is just a simple demo CLI in the root of the project. We'll let this run. I will allow all edits and now this is when the conversation normally would have stopped. It would have stopped with done I've created the file for you and here is what it includes.
[00:35] But if we force the ask user question tool into the stop hook and block it from stopping, we set up a continuous next steps so that no matter what we do in any conversation, let's say I'll press 1 to add more commands and hit submit, it's going to continue working. Let's select data manipulation, I'll tab over, hit enter, let's do some text processing, tab over, hit enter, and then as it continues working, again now it says done, it's completed the steps, the stopbook triggers, and it says okay now what do you want me to do? Do you want me to test it, add more features? And so you turn Claude into this system that forces input from you based on the current context of the conversation. And you could tweak this prompt that you send back however you want.
[01:26] Mine just says to use the ask question tool to continue refining what to do next. And you could add whatever text. And I'll share the snippet of code that I used to set up this hook. Since this isn't really a lesson about hooks, I have a zsh function defined which you could put into a script which will create a hooks directory, initialize bon, install the Clod SDK, set up the index file with the SDK, and then run you through the clod hook slash command to configure your settings for your hooks. And this wires it up so any time stop is attempted, then we run our hook defined in this index file.