Skip to content

feat: add example for Stop hook — task completes and stop is actually enforced #40

@NiveditJain

Description

@NiveditJain

Summary

Add a new example policy file demonstrating a non-trivial Stop hook: the user's chat/task finishes, Claude triggers a stop, and the hook actively enforces it (e.g. blocks the stop, logs it, or takes a side-effect action).

Motivation

Current examples cover Notification and SessionEnd but there is no example showing how to intercept and act on a Stop event. A real-world scenario — "task is done, stop fires, and the hook actually did something meaningful with it" — would help users understand:

  • How to detect that a session is stopping vs just idling
  • How to run cleanup / finalization logic before exit
  • How to conditionally block or allow the stop (e.g. require confirmation, flush a queue, post a summary)

Proposed example

New file: examples/policies-stop.js

Scenario: when Claude finishes a task and emits a Stop event, the hook:

  1. Posts a task-complete summary somewhere (Slack, file, etc.)
  2. Optionally blocks the stop if some condition isn't met (e.g. uncommitted changes detected)
  3. Returns allow() or deny() with a human-readable reason

Acceptance criteria

  • examples/policies-stop.js exists and is runnable with failproofai p -i -c
  • Demonstrates both the "let it stop" and "block the stop" code paths
  • Inline comments explain why each decision is made, not just what the code does
  • Added to the examples README / comment header with a usage snippet

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions