Mapping Coding Agent Tool-Call Events to Animated Mascot States
By the Charmotion team · Updated · How we write guides

Map each agent event to one mood number: a prompt or turn start to thinking (3), a running tool to loading (5), a finished step to happy (1), and a failure to sad (4). Claude Code hooks and the Codex CLI JSON stream supply the events, and a small local listener sends the number to the character's mood input.
Key takeaways
- Map each agent event to one fixed mood number, so the character never needs agent-specific animations.
- Claude Code hooks name each event in hook_event_name, and Codex CLI streams typed JSON events when you run codex exec with --json.
- Use happy for success and sad for failure, because Charmotion characters have no one-shot triggers.
- Hold short moods and debounce loading so bursts of tool calls do not make the character flicker.
- Log one real run of each agent before you write the mapping, because payload fields can differ by version.
Already have a character or logo? See examples in real app screens: splash, onboarding, loading and empty-state screens, with the animation that plays in each.
Which events do Claude Code and Codex CLI emit?
This guide covers how to map Claude Code and Codex CLI tool-call events to animated companion states, using one Rive character. Both agents report what they do in machine-readable form, so an app can follow a session without reading the terminal. Claude Code uses hooks. Codex CLI uses a JSON event stream and a hooks system. The events you need mark the start of a task, each tool call and its result, a failure, and the end of a turn.
- Claude Code hooks. Hooks run your own command, HTTP endpoint, MCP tool or prompt at points in a session. The events include SessionStart, UserPromptSubmit, PreToolUse, PostToolUse, Notification, SubagentStop, Stop and SessionEnd, among others.
- Codex CLI JSON events. Adding --json to codex exec prints newline-delimited JSON, one event per state change. Event types include thread.started, turn.started, turn.completed, turn.failed, item.* and error.
- Codex items. Items in the stream include command executions, file changes, MCP tool calls, web searches and plan updates.
Treat the list as a menu, not a contract. Claude Code has more hook events than the eight named here, and Codex item payloads are the part you should confirm in your own logs, as covered below.
Which mood number should each event drive?
Charmotion characters use a fixed mood list: idle 0, happy 1, wave 2, thinking 3, sad 4, loading 5, listening 6, talking 7, sleeping 8 and attention 9. Moods blend into each other, so a change from thinking to loading reads as a transition rather than a cut. Characters have no one-shot triggers, so a success is shown with happy and an error with sad. That fits coding agents well. For the design rules behind these states, see mascot animation states for loading, success and error, and use the mascot state planner to draft your own table.
| Agent event | Meaning | Mood |
|---|---|---|
| SessionStart or thread.started | Agent is ready | 2 wave |
| UserPromptSubmit or turn.started | Agent is planning | 3 thinking |
| PreToolUse, or a command or MCP item starting | A tool is running | 5 loading |
| PostToolUse with a clean result, or an item completing | Step succeeded | 1 happy |
| PostToolUse with an error, turn.failed or error | Something broke | 4 sad |
| Notification | Agent needs you | 9 attention |
| turn.completed or Stop | Turn finished | 0 idle |
| No events for a while, for example 10 minutes | Nobody is watching | 8 sleeping |
Hold happy for about the length of its 1.6 second clip, then return to idle. Otherwise the character stays cheerful through a long run.
How do you connect Claude Code hooks to a mascot?
Claude Code hooks are configured under the hooks key in ~/.claude/settings.json for all projects, .claude/settings.json for a shared project, or .claude/settings.local.json for your own local copy. Each hook entry has an event, an optional matcher such as a tool name, and a list of handlers. A command handler receives JSON on stdin. An http handler sends the same JSON as a POST to a URL. Every event includes fields such as session_id, cwd and hook_event_name, and PreToolUse adds tool_name and tool_input.
The simplest bridge is a command script that maps the event name to a mood number and sends it to a local listener. Save this as ~/.claude/hooks/mood.sh and make it executable:
#!/bin/sh
event=$(jq -r '.hook_event_name')
case "$event" in
UserPromptSubmit) mood=3 ;;
PreToolUse) mood=5 ;;
PostToolUse) mood=1 ;;
Notification) mood=9 ;;
Stop) mood=0 ;;
*) exit 0 ;;
esac
curl -s "http://localhost:4317/mood?value=$mood" > /dev/null
exit 0Point the relevant hook events at this script in settings, using the command handler type. Copy the exact field names from the official hooks page rather than from a blog post. A command hook that exits with 0 reports success. Exit code 2 is a blocking error on events that can block, so keep this bridge exiting with 0, because it only observes.
The script above treats every PostToolUse as success. Check tool_response for an error marker before you trust that. Its shape can differ by tool, so log one failing run and write the check from what you see. When the check finds a failure, send mood 4 instead of 1.
How do you read Codex CLI tool-call events?
Start with a log, not a mapping. Run codex exec with --json and keep one event per line, so you can see the real event names and item shapes in your installed version:
codex exec --json "run the test suite and fix one failure" | jq -c '.type'The documented event types for codex exec with --json include thread.started, turn.started, turn.completed, turn.failed, item.* and error. A mapping for the turn-level events can be a plain lookup:
const codexMood: Record<string, number> = {
'thread.started': 2,
'turn.started': 3,
'turn.completed': 0,
'turn.failed': 4,
'error': 4,
};For item.* events, branch on the item type. A command execution or MCP tool call that starts sets mood 5. When it completes, check its result before choosing 1 or 4. OpenAI does not publish a full JSON schema for every item type as of December 2026, so read the field names from your log rather than from a guide.
Codex also has a notify setting in config.toml that runs an external program with one JSON argument. In the earlier notify design it fired only when a turn completed, so it suits the final idle, not every tool call. Codex hooks are the closer match to Claude Code. PreToolUse and PostToolUse inputs include tool_name and tool_input, PostToolUse adds tool_response, and hooks must be reviewed in /hooks before they run. Bash and apply_patch use tool_input.command. Check which of these mechanisms your installed version supports, because the setup has changed between releases.
How do you send the mood to a Rive character?
Run a small listener that stores the latest mood and pushes it to the character. Keep it on the machine that runs the agent for a desktop companion, or on a backend if several people watch one shared dashboard. Each event only sets a number, so the listener never needs to send animation files or play clips. For the state model behind this, see how Rive state machines work.
Charmotion's character output is one Rive file with CharacterViewModelMachine, which has a number property named mood, and CharacterStateMachine, which has a number input named mood. Set the value through your Rive runtime's data binding API. The Rive runtime docs cover reading and writing ViewModelInstance values. Accents such as Z z z while sleeping and thinking dots are on by default, and the boolean accents hides them. A tool that runs all day may look calmer with accents off during long runs.
Charmotion turns one character image into this file, with up to 11 animations including a free idle. Its mood numbers match the table above, so the mapping stays the same. For the building blocks of an MCP-driven setup, see the Charmotion MCP server. The mapping works with any character you give the same mood integers.
What should the character do when events arrive in bursts?
Agent events arrive in bursts. A tool can start and finish in under a second, so a raw mapping makes the character flicker between loading and happy. Three rules keep it readable:
- Hold short moods. Keep happy for its clip length, then return to idle (mood 0).
- Let failures stay visible. If sad arrives during a run of successes, hold sad for a few seconds before the next state.
- Debounce loading. Wait a short moment, for example 300 ms, before showing loading, so quick commands never switch the character at all.
Use attention sparingly. A Notification means the agent is waiting for you, so keep attention on until the next UserPromptSubmit or PreToolUse event clears it. Characters have no triggers, so do not wait for a one-shot success signal. The success is simply a state change to happy. For a wider look at timing rules in product UI, see Duolingo-style mascot animation.
Does the mascot need to see tool inputs?
No. The mapping needs only the event name, and a command hook can ignore tool_input entirely. Keep the listener on localhost, and do not forward command text or file paths to a cloud service just to drive a mood. Hooks run commands you configure, so review each script before you accept it, and check the hooks page for your version when you change a matcher. Brand rules for how a mascot should behave in your product are covered in how to write brand motion guidelines.
How to map Claude Code and Codex CLI tool-call events to animated companion states
- Log real events. Run codex exec with --json and capture the hook JSON from one Claude Code session, so you see the real event names and fields in your versions.
- Write the mood table. Give each event one fixed mood integer from the Charmotion list: idle 0, happy 1, wave 2, thinking 3, sad 4, loading 5, attention 9, sleeping 8.
- Add a Claude Code hook. Put a small script in your hooks folder that maps hook_event_name to a mood number, then point the relevant events at it in settings.json under the hooks key.
- Map Codex events. Branch on the event type for turn-level events and on the item type for command and MCP tool items, then return the same mood integers.
- Send the mood to the character. Post the number to a local listener and set the mood property in CharacterViewModelMachine through your Rive runtime's data binding API.
- Add holds and debounce. Hold happy briefly, debounce loading and keep attention on until the next prompt or tool event, so bursts of events look calm.
Frequently asked questions
Does Codex CLI support hooks the same way Claude Code does?
Both can run your own scripts at tool-call points and both pass JSON. Codex hooks must be reviewed in /hooks before they run, and the notify setting is an older, turn-level option that receives one JSON argument. Check which mechanism your installed Codex CLI version supports. Pricing and usage limits for Codex CLI are not covered here, so check OpenAI's Codex pages as of December 2026.
Can one character serve both Claude Code and Codex CLI?
Yes. Both agents map to the same mood integers, so the character does not need to know which tool sent an event. Run one listener per user that accepts events from either source and writes a single mood value. That keeps one companion on screen even when you switch between agents during a day.
How do I show a success or an error without triggers?
Characters have no one-shot triggers, so a success is happy (mood 1) and an error is sad (mood 4). After a clean result, set happy, then return to idle (mood 0) once the clip has played. Keep sad until the next prompt or successful tool result, so a failure stays visible long enough to read.
Sources
- Hooks: Claude Code documentation, Anthropic
- Codex CLI reference, OpenAI
- Non-interactive mode: Codex, OpenAI
- Hooks documentation, OpenAI
- Codex hooks explained, IdlePal
- Rive data binding runtime parameters, Rive