Lesson

Force Claude to Ask 'What's Next?' with a Continuous Stop Hook Workflow

Overcome the stop-and-go nature of AI interactions by using a powerful Stop hook in Claude Code. This lesson shows you how to intercept the end of a conversation to force the agent to ask "What's next?", creating a continuous, guided development workflow.

Access
Included
Transcript
Needs source

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 Stop Hook: 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 reason in the JSON to instruct the agent to use the AskUserQuestion tool 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

Please create a CLI.ts file, which is just a simple demo CLI in the root of the project.

Terminal Commands

# Start claude with the haiku model for speed
claude --model haiku

Code Snippets

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"
}