Skip to content
Back to skills

Prove Hook Output

ASecurity

Prove that a hook's output actually reaches the person at the terminal, not just the model's context. Use when changing what a hook prints or returns — systemMessage, additionalContext, terminalSequence, a block reason — or when a hook "fires correctly" and the user still reports seeing nothing.

  • 2 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added October 11, 2026
ai-agentspythonrustgogitdocumentation

Works with

  • claude code
  • cursor
  • terminal
  • cli

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned October 11, 2026

npx -y skills add Agulhas-Labs/claude-plugins --skill prove-hook-output --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Prove Hook Output?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Prove Hook Output
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/agulhas-labs-prove-hook-output/badge)](https://www.skillsdirectory.com/skills/agulhas-labs-prove-hook-output)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: prove-hook-output
description: >-
  Prove that a hook's output actually reaches the person at the terminal, not just the model's
  context. Use when changing what a hook prints or returns — systemMessage, additionalContext,
  terminalSequence, a block reason — or when a hook "fires correctly" and the user still reports
  seeing nothing.
---

# prove-hook-output

**Read this when** a hook's visible output is in question. Sections: the three levels of proof, an installed plugin shadows your working copy, the PTY proof, reading the log by hand, the hook contract in the binary, when it is proven.

A hook firing is not a hook being seen. These go to different readers, and a change that looks right
in the hook's own tests can still leave the person in front of the terminal staring at a blank prompt:

| What the hook returns | Who receives it |
| --- | --- |
| stdout (plain text) | the model's context |
| `hookSpecificOutput.additionalContext` | the model's context |
| `systemMessage` | the person, rendered in the terminal |
| `terminalSequence` | the terminal itself, as an escape sequence |
| `decision: "block"` + `reason` | the person, and the prompt is held back |

So "the hook ran and returned the right JSON" answers a different question from "the user saw it".
Prove the second one, in a real terminal, before saying a visibility change works.

## The three levels of proof

Use the cheapest one that answers the question you actually have.

1. **Unit tests** on the hook's own functions. Fast, and they pin the content. They cannot tell you
   whether the host accepts the field or shows it to anyone.
2. **Headless** (`claude -p --output-format stream-json --verbose`). Proves the hook is registered,
   runs, and that its JSON was parsed and accepted — look for a `hook_response` event with
   `"exit_code": 0` and `"outcome": "success"`. It does **not** prove rendering: headless has no UI,
   and `systemMessage` appears only inside the `hook_response` blob, never as its own event.
   Measured on Claude Code 2.1.293, stream-json carries `hook_response` events for `SessionStart` only.
   For a `PreToolUse` or any other event, add `--debug-file <path>` and read that log for
   `Hook <Event>:<matcher> (<Event>) success`, which carries the hook's output (an `updatedInput`, say).
   And at a first turn's `PreToolUse`, the transcript does not yet hold the message making the call, so
   a hook that reads "the last assistant turn" finds the turn before it, or nothing.
   Two more, from proving a `PostToolUseFailure` hook: a probe prompt must forbid the agent from
   changing the command it is given (a runner appended `echo "exit=$?"` to a failing command, the call
   succeeded, and the wrong event fired), and `--debug-file` leaves a `latest` symlink beside the log that
   cleanup has to remove too.
3. **A real PTY.** The only thing that proves a person would see it. This is what the rest of this
   skill is for.

## Before anything: an installed plugin shadows your working copy

If a plugin of the same name is installed, `--plugin-dir` loads yours but the installed one wins —
silently. Hooks from the working copy never register and the proof passes for the wrong reason.

Renaming the copy is not enough on its own: the installed plugin still loads beside it and can draw
the same output, so the proof passes on the installed code. Copy the plugin to a scratch directory,
rename it in `.claude-plugin/plugin.json`, load that, and switch the installed one off for that
session (`--settings` with `enabledPlugins: {"<name>@<marketplace>": false}`).
`scripts/prove-render.sh` does all of this, prints which installed plugin it switched off, and lists
the hooks modules the session loaded, from its debug log, so you can see whose code drew.

## A session started from inside a session saves no transcript

Claude Code sets `CLAUDE_CODE_CHILD_SESSION` in the environment of everything it runs, and a
`claude` started with it set saves no transcript. Anything that reads the transcript (a band that
shows token counts, a handoff) then shows nothing, and the proof fails for a reason that has nothing
to do with the hook. The script unsets it and gives the probe its own `--session-id`.

A `/clear` inside the probe starts a second session under a new id. The debug log does not name it,
and measured on Claude Code 2.1.295 its transcript does not name the first id either. So the script
gives the probe a `SessionStart` hook, through its `--settings`, that records each session's id and
transcript path, and lists the probe's own project folder (the one the transcript store names after
the working directory) before the run. When it ends, it removes by exact path every new transcript
there that is the probe's: the one named by its id and each one the hook recorded. It removes the
project folder too if the run made it and it is now empty. Any other new transcript in that folder
may belong to a session running beside it in the same directory, so the script reports it and
leaves it; nothing older than the run is touched, and no other project folder is read. A file that
vanishes or refuses during the cleanup (a parallel run removing its own) is reported and skipped,
the rest still goes, and the exit status stays the proof's verdict.

## The PTY proof

```sh
.claude/skills/prove-hook-output/scripts/prove-render.sh \
  --plugin plugins/<name> \
  --grep '<a distinctive phrase from the message>' \
  --env SOME_PLUGIN_VAR=/tmp/somewhere \
  --prompt 'reply with the single word ok' \
  --send /clear
```

Give `--prompt` only when the output appears after a turn, and `--send` only when it appears after a
further input. `--send` is repeatable and applied in order after `--prompt`, each typed and entered after a settle
wait (`--settle`, default 8 seconds, which is also the wait for the session to start before the
first input; `--settle` and `--seconds` take whole seconds). A slash command works, so does a second
prompt: `--send /clear --send 'reply with the single word yes'` proves what shows in the session that
`/clear` starts.

It copies the plugin under a scratch name, starts Claude Code under `expect` in a PTY, sends the
inputs, waits, quits with Ctrl-C, removes the transcripts the run wrote, and then reports three
things from the captured session:

- whether the phrase appears in the ANSI-stripped output — the message was **rendered**;
- every OSC escape sequence the terminal received — a `terminalSequence` was **emitted**;
- any `rejected by the allowlist` line — a `terminalSequence` was **refused**.

Read what it prints. A missing phrase with a clean exit means the hook ran and the person saw
nothing, which is exactly the bug this skill exists to catch.

### Four things that will waste your time

The first three cost three failed attempts the first time round; the fourth froze a probe until it
was told to quit. All four are avoided by the script, but you need to know them when you drive
`expect` yourself.

- **A fresh directory triggers the trust dialog**, and the session stops there forever. Don't run
  from a temp directory. Run from a directory already trusted, and point the plugin's *output* 
  somewhere else with `--env`. Answering the dialog with arrow keys works, but it is fragile and
  there is no reason to.
- **The TUI writes cursor-moves between words**, so an `expect` pattern of more than one word never
  matches — `"trust this folder"` matches nothing while `"trust"` matches. Don't pattern-match the
  screen at all: sleep, quit, and grep the captured log afterwards.
- **`timeout(1)` is not on every machine.** Use the harness's own timeout, or `expect`'s.
- **A session nobody reads from stops.** Claude Code blocks writing to a terminal whose output is not
  being read, so an `expect` script that `sleep`s while it waits leaves the session frozen: measured
  on Claude Code 2.1.295, its debug log went silent for the whole 40 seconds of sleeps and the
  inputs typed meanwhile were never submitted. Wait with `expect` and a timeout, which reads as it
  waits, never with `sleep`.

### Reading the log by hand

Strip the ANSI to see what a person saw:

```sh
LC_ALL=C sed -e 's/\x1b\[[0-9;?]*[a-zA-Z]//g' -e 's/\r/\n/g' session.log
```

A rendered `systemMessage` from a SessionStart hook looks like this, prefixed by the host:

```
⎿  SessionStart:startup says: <your message>
```

Find escape sequences in the **raw** bytes, not the stripped text — stripping removes the evidence:

```sh
python3 -c "import re,sys;print(re.findall(rb'\x1b\][0-9]+;[^\x07]*\x07', open(sys.argv[1],'rb').read()))" session.log
```

## If the question is about the hook contract, read the binary

The documentation site paginates and truncates, and it will not reliably tell you whether a given
field applies to a given event. The installed CLI is a single executable that carries its own schema
text and its own error strings, and it answers in one command:

```sh
CLI=$(command -v claude); CLI=$(readlink -f "$CLI" 2>/dev/null || echo "$CLI")
LC_ALL=C strings -a "$CLI" | grep -o '.\{200\}systemMessage.\{200\}' | head
```

Keep the context window small (a few hundred characters) — a wide one produces megabytes of output
and some `grep` builds refuse it outright as too complex.

That is how the table at the top of this file was established, and how these constraints on
`terminalSequence` were, which the host enforces and silently drops anything that breaks:

- only OSC `0`, `1`, `2`, `9`, `99` and `777`, terminated by BEL or ST;
- the whole sequence under 4096 bytes;
- an OSC `9` body may not begin with a digit unless it is the `9;4` progress form;
- control characters are stripped from the payload;
- the host wraps the sequence for tmux and screen itself, so never do that in a hook.

## When it is proven

Say what was rendered, quoting it, and say which level of proof it came from. "The hook returns the
right JSON" is level 2 and should be described as that, not as evidence that anyone saw anything.

Files in this skill

  • SKILL.md9.8 KB
  • scripts/prove-render.sh13.8 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.