# Codewhale adapter

Shows the sessions of Codewhale, the program `codewhale`, in the notch: working, done when a turn completes, failed when it ends on an error, needing you while Codewhale waits for your approval or for an answer to its question, what the tool in use does, its first message, its repository and its branch as its name, its tool calls as steps and how many subagents it runs.
Codewhale reports through hooks: each hook posts its event with `curl` to a Unix socket in your own folder, `~/Library/Application Support/Blossom/codewhale/socket`, where this adapter listens. Blossom launches the adapter.
**Permissions and questions are answered in Codewhale.** Blossom shows that the session needs you, and you answer in the terminal: the event that says Codewhale waits for you only observes, and the hook that could steer a tool call can deny it or ask for it, never approve it from outside.
The hooks are entries `[[hooks.hooks]]` of your configuration file, `~/.codewhale/config.toml`, added after yours, with `enabled = true` under `[hooks]` when the file does not say it.

**This adapter was written from the documentation and the source of Codewhale and was never run against a real one.** What they say and what is only supposed is in [../../documentation/roadmap/codewhale.md](../../documentation/roadmap/codewhale.md); the checks at the end say what to look at.

You need:

- Blossom. It includes this adapter and the Bun that runs it; from a clone, `bun run build` makes one.
- Codewhale, `codewhale`, signed in to a provider, run in its terminal interface. The hooks follow `docs/HOOKS.md` of [codewhale-hq/Codewhale](https://github.com/codewhale-hq/Codewhale) at commit `fc6bdaacf6af887c9d37d2a9137e1c81af361da9` of 2 December 2026, and the code that runs them, `crates/engine/src/hooks/executor.rs`, the payloads of `crates/tui/src/tui/ui/observer_hooks.rs` and the configuration of `crates/config/src/hooks.rs`.
- `curl` and `ps`, which every hook runs by their full paths under `/usr/bin` and `/bin`. Codewhale runs a hook with `sh -c`; the hooks were tested with `sh`, `bash` and `zsh`.

## Connect from Blossom

The quickest way. Blossom finds `codewhale` on your Mac, in your `PATH` or in the usual folders, `~/.local/bin` among them, where its install script puts it, and connecting it is one click: "Continue" on the second step of the introduction, with Codewhale checked, or its switch in Settings > Agents. Blossom then adds this adapter to its configuration, starts it, and adds the entries of `adapters/codewhale/hooks.toml` to `~/.codewhale/config.toml`, after the last `[[hooks.hooks]]` of yours, or after the last table of the file when it has none.

The file is yours, with your providers and your settings, so Blossom edits it by lines and never writes it again from what it read: your comments, your order, your quotes and your own hooks stay as they are, byte for byte. When the file is missing, Blossom creates it with its entries alone, readable by you alone. Before each write it keeps a copy of the file in `~/Library/Application Support/Blossom/backups/codewhale/`, named after the moment in UTC, and it puts the new content in place in one rename. A file that is not valid TOML, or that writes its hooks inline, `hooks = { … }`, is left alone, and the row says why. "Repair" in the row puts the entries back when they are missing or not the ones this Blossom installs. "Disconnect", shown while the agent is off, takes the adapter out of Blossom and its entries out of the file, which then holds what it held before connecting. Blossom does not follow `CODEWHALE_HOME` or `CODEWHALE_CONFIG_PATH`: a Codewhale that reads another file does not see the hooks. What Blossom writes and why is in [the decision](../../documentation/decisions/connecting.md).

Codewhale reads its hooks when it starts. A session that was open when you connected reports from its next start.

### The switch of the hooks

`[hooks]` holds `enabled`, the switch of every hook of Codewhale.

- **When the file does not say it**, Blossom adds `enabled = true` under your `[hooks]`, or `[hooks]` and the key after the last table of the file. Disconnect takes the key out again with the last entry of Blossom's, and `[hooks]` when nothing else is under it, so a file that had neither gets both back as it was.
- **When it says `enabled = false`**, you turned every hook off. Blossom writes nothing, and the row of Codewhale in Settings says that its configuration turns its hooks off. Turn the switch on yourself, or take the line out, and press Try again.
- **Turning the switch on also turns on the hooks you already had under `[hooks]`**, and, since a file of a project cannot change the switch, the hooks of a project you approved with `/hooks approve`. Before you connect, `/hooks list` in Codewhale shows them. With `[hooks]` in the file and no `enabled`, Codewhale already reads the switch as on, so only a file without `[hooks]` changes.
- **When you wrote `enabled = true` yourself with no hook of your own under it**, Disconnect takes your line out with Blossom's entries, since nothing tells the two apart; your approved hooks of a project are then off until you put it back.
- **`Blossom --uninstall`** does not read the templates: it takes out the entries of Blossom's and leaves `[hooks]` and `enabled = true`, which a test of the uninstaller checks. Codewhale then runs no hook of Blossom's; if you had no `[hooks]` before, delete those two lines by hand.

`default_timeout_secs`, when you set it, replaces the `timeout_secs` of every hook. Blossom's entries set none, so they take the thirty seconds of Codewhale or yours; a hook ends within about a second either way.

### A configuration still in `~/.deepseek`

Codewhale reads `~/.deepseek/config.toml` only while `~/.codewhale/config.toml` does not exist, and copies it there once on its first launch. Blossom writes only `~/.codewhale/config.toml`. If you still have a configuration in `~/.deepseek` and never launched a recent Codewhale, launch it once before you connect: a file Blossom created with its entries alone would be the one Codewhale reads, and it would no longer copy yours.

## Run Blossom with the adapter

From the root of the clone:

```sh
bun install && bun run bootstrap && bun run build
BLOSSOM_CONFIGURATION=adapters/codewhale/configuration.json apps/macos/build/Build/Products/Debug/Blossom.app/Contents/MacOS/Blossom
```

`bootstrap` installs the toolchain the build needs; see [../../documentation/contributing.md](../../documentation/contributing.md).

The notch shows nothing until a session of Codewhale reports. Run one Blossom at a time: the adapter holds the socket, and the adapter of a second Blossom logs `cannot listen for the hooks of codewhale` and exits.

### From Finder

An app opened from Finder reads `~/Library/Application Support/Blossom/configuration.json`. Name the adapter by its package, which Blossom includes:

```json
{ "adapters": [{ "package": "codewhale" }] }
```

If the file already exists, add the adapter to its `adapters` list instead.

## Try it without touching your configuration

Codewhale reads its folder from `CODEWHALE_HOME` when it is set. Point it at a folder made for the try, with the hooks alone, and nothing of yours changes; sign in there the first time:

```sh
export CODEWHALE_HOME="$(mktemp -d)"
cp "<absolute path of the clone>/adapters/codewhale/hooks.toml" "$CODEWHALE_HOME/config.toml"
codewhale
```

What you should see:

- Nothing when the session opens. The tile appears next to the notch with the first message, named after its first line and the repository, `blossom · Fix the flaky notch tests`, with its branch beside it.
- No badge while it works, and the tool in use in live.
- The amber badge while Codewhale asks you to approve a tool or answer a question, and no request panel: answer there.
- The green badge when a turn completes; the red one when it ends on an error.
- The tile gone when you quit Codewhale.

## Install by hand

For a clone without the app. Keep a copy of your file. If it has no `[hooks]` table, append the template whole:

```sh
cp ~/.codewhale/config.toml ~/.codewhale/config.toml.before-blossom
{ printf '\n'; cat adapters/codewhale/hooks.toml; } >> ~/.codewhale/config.toml
```

If it has one, add `enabled = true` under it unless it says it already, and append the template without its first two lines: `tail -n +4 adapters/codewhale/hooks.toml`. TOML lets `[[hooks.hooks]]` entries follow any table.

## Remove by hand

After an install by hand; after connecting from Blossom, Disconnect does it, and removing Blossom takes out the hooks of every tool, see [Removing it](../../documentation/privacy.md#removing-it). Open `~/.codewhale/config.toml` and delete each `[[hooks.hooks]]` entry whose `command` names `Blossom/codewhale/socket`, from its `[[hooks.hooks]]` line to its `command` line, and `enabled = true` and `[hooks]` if you had neither before. Then check that none is left:

```sh
grep -c 'Blossom/codewhale/socket' ~/.codewhale/config.toml
```

## What to know

- **Where the hooks run.** Codewhale runs them in its terminal interface. `codewhale exec` runs none unless you pass `--hooks`, and then only `tool_call_before` and `shell_env`, so no session of it shows; the threads of its desktop app and web run `tool_call_before` and `tool_call_after` but no event of a message, so none of them shows either. The app server and ACP run none.
- **Permissions and questions are shown, not answered.** `waiting_for_user` comes when Codewhale opens an approval or presents a question of `request_user_input`, with the reason `approval` or `user_input`: the session needs you until `session_busy` says it works again. A wait of the reason `goal_continuation`, a goal parked between two passes, does not. Of the sixteen events only `message_submit`, `tool_call_before` and `shell_env` steer, and `tool_call_before` can allow, deny or ask, which only lets Codewhale go on to its own prompt, so nothing here answers from the notch.
- **Which events.** `message_submit`, `tool_call_before`, `tool_call_after`, `waiting_for_user`, `session_busy`, `subagent_spawn`, `subagent_complete`, `turn_end`, `session_idle`, `session_error` and `session_end`. `shell_env` is never installed: what it prints becomes the environment of your commands. Nor are `session_start`, `mode_change`, `on_error` and `pre_compact`, which add nothing the others do not say.
- **How the hooks send what Codewhale gives them.** Codewhale gives a hook most of what it knows in variables of its environment, `DEEPSEEK_SESSION_ID`, `DEEPSEEK_WORKSPACE`, `DEEPSEEK_MESSAGE`, `DEEPSEEK_TOOL_NAME`, `DEEPSEEK_TOOL_CALL_ID`, `DEEPSEEK_TOOL_ARGS` and `DEEPSEEK_TOOL_SUCCESS`, and some events a document of JSON on standard input as well. A hook hands each value to `curl` as one argument of `--data-urlencode "name=${VARIABLE-}"`, and the standard input as `--data-urlencode "input@-"`: the shell expands the variable inside double quotes once, and runs nothing it holds, `$(…)`, backticks and quotes included, and `curl` encodes every byte, so a value cannot add a field, end one or pass for the event. The body is a form, `application/x-www-form-urlencoded`, which the adapter reads field by field. The tests send values with quotes, line breaks, `$(…)`, backticks and ten thousand bytes through `sh`, `bash` and `zsh`, and check that each arrives as it was and that nothing ran.
- **A session shows up with its first message.** `message_submit` starts it; a session already running when Blossom started shows from its next message. The title is the first line of `DEEPSEEK_MESSAGE`, cut to 60 characters; a message that starts with `/` or `!` titles nothing. The project is the repository and the branch of `DEEPSEEK_WORKSPACE`, read from `HEAD` and the pointers of `.git` at most once every five seconds, without running `git`. See [../../documentation/decisions/names.md](../../documentation/decisions/names.md).
- **Steps are tool calls, saying what they do.** Each call is a step from its `tool_call_before` to its `tool_call_after`, paired by `DEEPSEEK_TOOL_CALL_ID`, failed when `DEEPSEEK_TOOL_SUCCESS` is `false`. A step still running when the turn ends is shown failed. `tool_call_before` runs for the calls of the session itself, not those of its subagents. A step is the `description` a shell tool, `bash`, `Bash` or `exec_shell`, may carry, never its command; the verb and the name of the file of `read`, `edit` and `write` and of `read_file`, `edit_file` and `write_file`, read from `path`, never its folder or its content; or a label for any other tool. Codewhale cuts `DEEPSEEK_TOOL_ARGS` at 10,000 bytes, which leaves it no longer JSON: such a step shows the label of its tool, never a guess.
- **How a turn ends.** `turn_end` with the status `failed`, or `session_error`, is failed; any other status is done. `session_idle` ends a turn that is still open the same way, from its `last_turn_status`.
- **Subagents are counted by their identifier.** `subagent_spawn` adds the `agent_id` of its input and `subagent_complete`, which comes when a subagent completes, fails or is cancelled, takes it away. The count is not set to zero at the end of a turn, since a subagent may run in the background beyond it.
- **What the adapter keeps.** The identifier of the session and of the call, the title, the name of the tool and the words of its step, whether it failed, the folder, the reason of a wait, the status of a turn and the identifier of a subagent; the rest of what a hook sends, your message, the arguments of a tool and the previews of a subagent, is dropped at once and never logged or sent to Blossom.
- **The terminal of a session.** The hook of `message_submit` also finds the terminal the session runs in, as the hook of a prompt of the other agents does: it walks up from the process that started it with `/bin/ps` and reads the variables a terminal sets, such as `TERM_PROGRAM`, and sends what it found in headers. The adapter passes it to Blossom through `SessionPlaces` of the SDK, which uses it only to bring that terminal to the front. With the experimental extension host of Codewhale on, a hook gets a short list of variables, `TERM` among them but no variable of a terminal program, so only the device and the processes are found.
- **The hooks print nothing and always succeed.** What `message_submit` prints replaces your message, what `tool_call_before` prints decides the call, and an exit status of 2 blocks either. Every command sends everything it runs to `/dev/null` and ends with `|| /usr/bin/true`, so neither a configuration file of `curl` nor whatever answers on the socket can make a hook decide anything, and with Blossom closed every tool still runs. A function of your shell named `curl` or `ps` does not run in place of the full paths.
- **The hooks name `$HOME` and nothing else without a default.** Every other variable is read with `${NAME-}`, so a shell that refuses unset variables still runs them, and a variable Codewhale did not set travels empty.
- **The hooks ignore your curl configuration.** `-q` keeps `curl` from reading `~/.curlrc` and its siblings.
- **Without Blossom, Codewhale works as before.** With Blossom closed nothing listens on the socket: each hook gives up at once, prints nothing and ends without an error. When the adapter is alive but does not answer, every event waits one second. Codewhale waits for `message_submit` and `tool_call_before`, and runs the other events in two workers of its own, which never hold the screen.
- **Events may arrive a little out of order.** Codewhale runs the events that only observe in two workers, so two that fire together may reach the socket in either order. The adapter takes `turn_end` and `session_idle` as one end of the turn, whichever comes first.
- **A session whose `codewhale` was killed leaves within seconds, if the process is the one supposed.** Every command names the process that started its shell, in the header `Blossom-Process`, which is Codewhale itself. The adapter watches a process only once two events in a row name it, and every five seconds asks the system whether it still exists. `session_end`, on a clean quit, closes the session at once.
- **The socket is yours alone.** It lives in a folder only your user can open. A process that runs as you can still post events to it, or listen on it while Blossom is closed and read what the hooks send, your messages included. See [../../documentation/decisions/socket.md](../../documentation/decisions/socket.md).
- **Sixty-four sessions at most.** When a sixty-fifth starts, the adapter closes the one it heard from least recently.
- **The hooks find the socket through `$HOME`.** A session started with another `HOME` does not report.

### Not confirmed

Read in the documentation and the source, never seen in a run:

1. That the shell of a hook has the process of Codewhale as its parent for the whole session, so that `$PPID` is the same on every event.
2. That `waiting_for_user` comes once the approval or the question is shown, and `session_busy` once you answered it.
3. That `DEEPSEEK_TOOL_ARGS` is the JSON of the input of the tool with the names of the fields of its schema, `path` and `description`.
4. That `turn_end` comes after the last `tool_call_after` of the turn.
5. That a file whose only content were Blossom's entries loads as one without hooks once Disconnect emptied it.

## Checks by hand

The adapter was tested with its hook commands run by `sh`, `bash` and `zsh` against the socket, with values and payloads written from the documentation and the source, never captured from a run. Each check below needs `codewhale` signed in. Write down what the line in italics asks.

Prepare once. To see what the hooks receive first, point Codewhale at a folder whose hooks log it, and remove it afterwards:

```sh
export CODEWHALE_HOME="$(mktemp -d)" && echo "$CODEWHALE_HOME"
{ printf '[hooks]\nenabled = true\n'; for event in message_submit tool_call_before tool_call_after waiting_for_user session_busy subagent_spawn subagent_complete turn_end session_idle session_error session_end; do printf '\n[[hooks.hooks]]\nevent = "%s"\ncommand = "{ /bin/echo %s process ${PPID-} session ${DEEPSEEK_SESSION_ID-} call ${DEEPSEEK_TOOL_CALL_ID-}; /usr/bin/env | /usr/bin/grep ^DEEPSEEK_TOOL_ARGS; /bin/cat; /bin/echo; } >> %s/events.log 2>/dev/null; /usr/bin/true"\n' "$event" "$event" "$CODEWHALE_HOME"; done; } > "$CODEWHALE_HOME/config.toml"
codewhale
```

1. **The events.** Ask `hi`, then `read the README and run ls`, allow it, and quit. *Does every line of `events.log` name the same session and the same process, the process of `codewhale`? Do `waiting_for_user`, `subagent_*`, `turn_end` and `session_idle` carry one line of JSON?*
2. **The arguments.** *Does `DEEPSEEK_TOOL_ARGS` of a read carry `path`, and that of a command `description` when the model wrote one?*
3. **A permission.** In the mode that asks, ask `run the shell command touch probe.txt` and wait. *Is there a `waiting_for_user` with `"reason":"approval"`, and a `session_busy` once you answered?*
4. **A question.** Ask `ask me to choose between two options before you answer`. *Is there a `waiting_for_user` with `"reason":"user_input"`?*
5. **A subagent.** Ask for a task that Codewhale hands to a subagent. *Do `subagent_spawn` and `subagent_complete` carry the same `agent_id`?*
6. **The order.** *Does `turn_end` come after the last `tool_call_after` of the turn?*

Then run Blossom with the adapter, `unset CODEWHALE_HOME`, and connect Codewhale, which adds the hooks to `~/.codewhale/config.toml`. Delete the folder of the logger.

7. **A turn.** In a new folder, start `codewhale` and ask `hi`. *Does the tile appear with the message, titled `hi` and named after the new folder, with no badge, and turn green when the answer ends?*
8. **A tool.** Ask `run the shell command sleep 5` and allow it. *Does live show the tool, does detail list it as a step, and does the tile turn green at the end?*
9. **A permission.** Ask `run the shell command touch probe.txt` and do not answer yet. *Does the tile turn amber, with no request panel?* Allow it. *Does it go back to working, and turn green at the end?*
10. **A subagent.** *Does peek show one running subagent while it works, and none once it ends?*
11. **The end.** Quit `codewhale`. *Does the tile leave at once?* Start it again, ask `hi`, and `kill -9` its process from another terminal. *Does the tile leave within about five seconds?*
12. **The switch.** Disconnect, set `enabled = false` under `[hooks]`, and connect again. *Does the row say that the configuration turns the hooks off, and is the file unchanged?*
13. **Disconnect.** Put the file back, connect, then disconnect. *Is `~/.codewhale/config.toml` as it was before connecting?*
