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.
Workflow demonstrated in this lesson:
- Configure a
StopHook: Set up a hook in your local settings that triggers on every conversation stop. - Create a Blocking Script: Write a simple script that returns a
"decision": "block"JSON object, preventing the agent from stopping. - Prompt for Next Steps: Include a
reasonin the JSON to instruct the agent to use theAskUserQuestiontool and continue the conversation. - Build Iteratively: Watch as the agent completes a task (like creating a file) and immediately asks for the next action (like adding features), creating a seamless, multi-step development session.
Key benefits:
- Create Continuous Workflows: Eliminate the start-stop cycle of typical AI interactions.
- Guided Development: Turn your AI into a proactive partner that helps you plan and execute the next steps.
- Improve Efficiency: Chain multiple related tasks together in a single, unbroken conversation.
- Full Programmatic Control: Gain fine-grained control over the agent's lifecycle.
Summary
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.
Prompts
Terminal Commands
Code Snippets
The settings.local.json file is configured to run a command whenever the agent attempts to stop.
The hook script (index.ts) returns a JSON object that blocks the stop action and provides a reason for the AI to continue.
A helper ZSH function to quickly initialize this hook setup in any project.
