Live Pharo/Bloc view of what Claude Code does (commands, why, results), fed by Claude Code hooks
# ClaudeMonitor
A live view, in a Pharo window built with [Toplo](https://github.com/pharo-graphics/Toplo) (widgets on top of [Bloc](https://github.com/pharo-graphics/Bloc)), of what Claude Code does in a workspace: every tool call (shell commands, file edits, Pharo MCP calls...) with why it was made, its full input, its result and its duration, plus the prompts you submit.
Claude Code [hooks](https://docs.claude.com/en/docs/claude-code/hooks) POST each event to a small HTTP server in the image (localhost, port 8091).
## Load
```smalltalk
Metacello new
baseline: 'ClaudeMonitor';
repository: 'github://NicolasAnquetil/ClaudeMonitor:main/src';
load.
```
## Use
```smalltalk
CMMonitor start. "receive hook events on 127.0.0.1:8091 and open the window"
CMMonitor open. "open another window on the same activities"
CMMonitor stop. "stop receiving events"
CMMonitor reset. "stop and forget the activities"
```
This loads Bloc v3.0.0 and Toplo v0.11.0 (the Toplo version built on that Bloc).
The window shows a tree, newest on top: each Claude Code session, the prompts you submitted in it, and under each prompt what Claude did for it, in order:
- the messages Claude wrote and its thinking, read from the session transcript at each hook event (the transcript keeps the text of only part of the thinking: the rest is skipped),
- the tool calls, each under the message Claude wrote just before it (or under the prompt when there is none),
- for a to-do list (`TodoWrite`) or a plan (`ExitPlanMode`), one row per step under the call, with its state (done, in progress, pending).
Each row has a status icon (running, ok, failed), the tool, a summary, then the start time, the duration and the tokens in their own columns.
The tokens are the output tokens Claude wrote, read from the transcript, which gives them per model call:
- a thinking row has the exact thinking tokens of its call;
- a message or a tool call gets the rest of its call's output, shared by size when the call made several of them (shown with `~`, an estimate); thinking whose text was not kept counts for the call's first other row;
- a message row also counts its tool calls, and a prompt or a session row counts each of its calls once.
The details pane gives the tokens of the selected row and of its model call, including the input tokens it read (new, cache writes, cache reads). Calls made by subagents are not counted. The arrows fold and unfold sessions and prompts.
Keys: up and down move from the selected row (with no row selected, down goes to the first row of the current session and up to its last one); left folds a prompt or goes to its parent; right unfolds a prompt or goes to its first tool call. The selected row stays the same while new rows arrive or the list is redrawn.
Select a row to see its details on the right (the text can be selected and copied; drag the divider to resize the panes):
- **Why**: the description Claude gives with a shell command.
- **Explanation**: the text Claude wrote just before the call, read from the session transcript (best effort: not every text reaches the transcript).
- **Input**: the full command, code or file content, then the other arguments.
- **Response** or **Error**: what the tool answered (cut after 20000 characters).
*New session* starts a new session: type its name in the field that appears, then Return (Escape cancels). It becomes the current session: everything that comes from then on (the new prompts, from any Claude Code session, with all that follows them) is listed under it. What came before stays where it was; the Claude Code session of each row is still shown in its details. Without a current session, prompts go under their Claude Code session.
All sessions are alike: select any session row and click *Current session* to have the new prompts go under it; the current one is marked *(current)*. Selecting a row alone does not change where new rows go. Double-click a session to rename it (Return accepts); a renamed Claude Code session keeps your name instead of the title read from its transcript.
*Hide reads* hides the calls that only look at things (Read, Grep, Glob, Pharo searches...); *Collapse all* folds every prompt, message and plan (one row per prompt); *Clear* hides what happened until now; *A-* and *A+* change the font size.
## Claude Code hooks
Put this in the workspace's `.claude/settings.json` (only sessions started in that workspace are monitored). The hooks run asynchronously and fail silently, so Claude Code is never slowed down or blocked when the image is not running.
```json
{
"hooks": {
"PreToolUse": [{ "matcher": "*", "hooks": [{ "type": "command", "async": true,
"command": "curl -s -m 2 -X POST -H 'Content-Type: application/json' --data-binary @- http://127.0.0.1:8091/event >/dev/null 2>&1 || true" }] }],
"PostToolUse": [{ "matcher": "*", "hooks": [{ "type": "command", "async": true,
"command": "curl -s -m 2 -X POST -H 'Content-Type: application/json' --data-binary @- http://127.0.0.1:8091/event >/dev/null 2>&1 || true" }] }],
"PostToolUseFailure": [{ "matcher": "*", "hooks": [{ "type": "command", "async": true,
"command": "curl -s -m 2 -X POST -H 'Content-Type: application/json' --data-binary @- http://127.0.0.1:8091/event >/dev/null 2>&1 || true" }] }],
"UserPromptSubmit": [{ "hooks": [{ "type": "command", "async": true,
"command": "curl -s -m 2 -X POST -H 'Content-Type: application/json' --data-binary @- http://127.0.0.1:8091/event >/dev/null 2>&1 || true" }] }],
"Stop": [{ "hooks": [{ "type": "command", "async": true,
"command": "curl -s -m 2 -X POST -H 'Content-Type: application/json' --data-binary @- http://127.0.0.1:8091/event >/dev/null 2>&1 || true" }] }]
}
}
```
## Limits
- Only what happens while the image runs and `CMMonitor start` was done is shown; nothing is kept when the image is restarted without saving.
- Times are when the hook events reached the image (hooks are asynchronous, so a little late); durations are the ones Claude Code measured.