# Kimi Code adapter

Shows the sessions of Kimi Code, the program `kimi` of Moonshot AI, in the notch: working, done when a turn completes or you interrupt it, failed when a turn ends on an error, needing you while Kimi Code waits for your approval of a tool or asks you a question, what the tool in use does, its first prompt, its repository and its branch as its name, its tool calls as steps and how many subagents it runs.
Kimi Code reports through hooks: each hook posts its event with `curl` to a Unix socket in your own folder, `~/Library/Application Support/Blossom/kimi/socket`, where this adapter listens. Blossom launches the adapter.
**Permissions and questions are answered in Kimi Code.** Blossom shows that the session needs you, and you answer in the terminal: every hook of Kimi Code but three only observes, and none of the three can approve a call.
The hooks are entries `[[hooks]]` of the configuration file of Kimi Code, `~/.kimi-code/config.toml`, added after yours. Kimi Code has no hooks file per project.

**This adapter was written from the documentation and the source of Kimi Code and was never run against a real one.** What they say and what is only supposed is in [../../documentation/roadmap/kimi.md](../../documentation/roadmap/kimi.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.
- Kimi Code, `kimi`, the CLI written in TypeScript, signed in. The hooks follow the page [Hooks](https://moonshotai.github.io/kimi-code/en/customization/hooks) and the source of [MoonshotAI/kimi-code](https://github.com/MoonshotAI/kimi-code) at commit `701c7d609785f220969d6a26e3bd2f6c011a3250` of 2 December 2026: `docs/en/customization/hooks.md`, which that page is built from, and the code that runs the hooks, `packages/agent-core-v2/src/features/externalHooks`. The earlier Kimi CLI, written in Python and configured in `~/.kimi/config.toml`, is archived and not served.
- `curl`, `printf`, `cat` and `ps`, which every hook runs by their full paths under `/usr/bin` and `/bin`. Kimi Code runs a hook with `/bin/sh -c`; the hooks were tested with `sh`, `bash` and `zsh`.

## Connect from Blossom

The quickest way. Blossom finds `kimi` on your Mac, in your `PATH`, in the usual folders or in `~/.kimi-code/bin`, where its install script puts it, and connecting it is one click: "Continue" on the second step of the introduction, with Kimi Code checked, or its switch in Settings > Agents. Blossom then adds this adapter to its configuration, starts it, and adds the entries of `adapters/kimi/hooks.toml` to `~/.kimi-code/config.toml`, after the last `[[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/kimi/`, named after the moment in UTC, and it puts the new content in place in one rename, so a failure halfway leaves the file as it was. 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 `KIMI_CODE_HOME`: a Kimi Code that uses another folder does not read the file. What Blossom writes and why is in [the decision](../../documentation/decisions/connecting.md).

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

## Run Blossom with the adapter

From the root of the clone:

```sh
bun install && bun run bootstrap && bun run build
BLOSSOM_CONFIGURATION=adapters/kimi/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 Kimi Code 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 kimi` 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, so neither a path nor Bun is needed:

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

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

## Try it without touching your configuration

Kimi Code reads one configuration file, in `KIMI_CODE_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 KIMI_CODE_HOME="$(mktemp -d)"
cp "<absolute path of the clone>/adapters/kimi/hooks.toml" "$KIMI_CODE_HOME/config.toml"
kimi
```

What you should see:

- Nothing when the session opens. The tile appears next to the notch with the first prompt, named after the first line of that prompt 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 Kimi Code asks you to approve a tool or answer a question, and no request panel: answer there.
- The green badge when a turn completes or you interrupt it; the red one when it ends on an error.
- The tile gone when the session ends.

## Install by hand

For a clone without the app. Keep a copy of your file, then append the entries; TOML lets `[[hooks]]` entries follow any table:

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

## 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 `~/.kimi-code/config.toml` and delete each `[[hooks]]` entry whose `command` names `Blossom/kimi/socket`, from its `[[hooks]]` line to its `command` line. Then check that none is left:

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

## What to know

- **Permissions and questions are shown, not answered.** Kimi Code runs `PermissionRequest` just before it waits for your approval and `PermissionResult` once you gave it; both only observe. The session needs you between the two. A question is the tool `AskUserQuestion`: the session needs you from its `PreToolUse` until its `PostToolUse`. Only `PreToolUse`, `Stop` and `UserPromptSubmit` can change what Kimi Code does, and they can block or rewrite, never approve, so nothing here could answer from the notch.
- **A session shows up with its first prompt.** An open session with nothing typed shows nothing, and so does a session that was already running when Blossom started, until its next prompt. `SessionStart` is not installed.
- **The name comes from the first prompt and the repository.** The first line of the text of the first prompt is the title, cut to 60 characters, and stays; a prompt that starts with `/` or `!` titles nothing. Kimi Code sends the prompt as a list of parts; their text is read and the rest, an image for example, is not. The title Kimi Code gives a session itself, `session_title`, is never read. The project is the repository and the branch of its folder, 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 of a tool is a step, from its `PreToolUse` to its `PostToolUse`, or to `PostToolUseFailure` when it fails or is blocked, paired by the `tool_call_id` Kimi Code gives every call. A step still running when the turn ends is shown failed. A step is the `description` of `Bash` and `Agent`, never the command or the prompt; the verb and the name of the file of `Read`, `Edit` and `Write`, never its folder or its content; or a label for any other tool. Those fields are read from the input types in the source, not seen in a run. Nothing a tool printed is reported.
- **How a turn ends.** `Stop`, which Kimi Code runs once a turn completed, is done; `Interrupt`, when you press `esc`, is done too, since you stopped it; `StopFailure`, an error, is failed.
- **Subagents are counted, and their tools are steps of the session.** `SubagentStart` adds one and `SubagentStop`, which Kimi Code sends when a subagent completes, takes one away. A subagent runs in the same session, so its hooks carry the identifier of the session and nothing says they are its own: its tool calls show as steps of the session, and its own `Stop` would read as the end of the turn. So while a subagent runs, a `Stop` is taken for the subagent's and changes nothing, and a `StopFailure` or an `Interrupt`, which a subagent that fails or is stopped sends instead of `SubagentStop`, takes one subagent away. The end of the turn of the session sets the count to zero. A subagent left running in the background keeps the turn of the session working until it ends.
- **The hooks send the whole payload, and the adapter keeps a few fields.** Each hook sends `{"event":"<its event>","payload":<the payload>}`, the payload as it came, with your prompt, the input and the output of tools and the last answer. The adapter keeps the identifier of the session and of the call, the title taken from the first line of the prompt, the name of the tool and the words of its step, the folder, and drops the rest at once. Nothing else of your prompt or of a tool is kept, logged or sent to Blossom. The event is the one the hook is installed on, so no text of the payload can pass for another.
- **The terminal of a session.** The hook of `UserPromptSubmit` also finds the terminal the session runs in, the way the hook of Claude Code 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, which uses it to bring that terminal to the front. No other hook looks for it.
- **The hooks print nothing and always succeed.** Kimi Code adds what a `UserPromptSubmit` hook prints to the context of the model, reads a `deny` printed by `PreToolUse`, `Stop` or `UserPromptSubmit` as a block, and an exit status of 2 blocks. 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`, `printf`, `cat` or `ps` does not run in place of the full paths.
- **The hooks name `$HOME` and nothing else without a default.** The process and the variables of the terminal are read with `${NAME-}`, so a shell that refuses unset variables still runs them.
- **The hooks ignore your curl configuration.** `-q` keeps `curl` from reading `~/.curlrc` and its siblings.
- **Without Blossom, Kimi Code 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, well inside the thirty seconds Kimi Code gives a hook by default. Kimi Code waits for `PreToolUse`, `PostToolUse`, `UserPromptSubmit` and `Stop`, and runs the others in the background.
- **A session whose `kimi` 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`. Kimi Code starts the shell itself, so that is the process of Kimi Code. 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. `kimi web` runs many sessions in one process; they all leave when it ends.
- **Kimi Code writes the file too.** Signing in, and the refreshes of managed models, write `~/.kimi-code/config.toml`. Blossom recognizes its entries by the socket their `command` names, whatever the formatting Kimi Code gives them; whether Kimi Code keeps your comments when it writes is its own.
- **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 the payloads, your prompts 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.
- **Where hooks are turned off, nothing shows.** An organization whose managed policy allows managed hooks only, or turns off some events, keeps these hooks from running.
- **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 Kimi Code as its parent for the whole session, so that `$PPID` is the same on every event.
2. That a subagent's hooks carry the identifier of the session of its parent, and that its own `Stop` comes before its `SubagentStop`.
3. That `PermissionRequest` comes once the prompt is shown, and `PermissionResult` once you answered it.
4. That the session waits for you between the `PreToolUse` and the `PostToolUse` of `AskUserQuestion`.
5. That the input of `Bash`, `Agent`, `Read`, `Edit` and `Write` reaches a hook with the names of the fields of their types.
6. 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 payloads written from the documentation and the source, never captured from a run. Each check below needs `kimi` signed in. Write down what the line in italics asks.

Prepare once. To see the raw payloads first, point Kimi Code at a folder whose hooks log what they receive, and remove it afterwards:

```sh
export KIMI_CODE_HOME="$(mktemp -d)" && echo "$KIMI_CODE_HOME"
for event in UserPromptSubmit PreToolUse PostToolUse PostToolUseFailure PermissionRequest PermissionResult SubagentStart SubagentStop Stop StopFailure Interrupt SessionEnd; do printf '[[hooks]]\nevent = "%s"\ncommand = "{ /bin/echo %s process ${PPID-}; /bin/cat; /bin/echo; } >> %s/events.log 2>/dev/null; /usr/bin/true"\n\n' "$event" "$event" "$KIMI_CODE_HOME"; done > "$KIMI_CODE_HOME/config.toml"
kimi
```

1. **The payloads.** Ask `hi`, then `run the shell command ls`, allow it, and quit. *Is every event of `events.log` followed by one line of JSON with `session_id`, a `prompt` that is a list of parts on `UserPromptSubmit`, and `tool_call_id` on the tool events?*
2. **The process.** In a second terminal, `ps -ax -o pid,ppid,command | grep '[k]imi'`. *Is the process on every line the `kimi` of the session, the same for the whole session?*
3. **A permission.** Ask `run the shell command touch probe.txt` and wait. *Is there a `PermissionRequest`?* Decline it. *Do `PermissionResult` with `"decision":"rejected"` and `PostToolUseFailure` follow?*
4. **A question.** Ask `ask me to choose between two options before you answer`. *Is the tool `AskUserQuestion`, between a `PreToolUse` and a `PostToolUse`?*
5. **A subagent.** Ask for a task that Kimi Code hands to a subagent. *Do the events of the subagent carry the `session_id` of the session? Does a `Stop` of the subagent come, and before or after `SubagentStop`?*
6. **An interrupt.** Ask `count from 1 to 300, one number per line` and press `esc`. *Does `Interrupt` follow, and no `Stop`?*
7. **The field names.** *Does the `tool_input` of `Bash` carry `description`, and that of `Read` carry `path`?*

Then run Blossom with the adapter, `unset KIMI_CODE_HOME`, and connect Kimi Code, which adds the hooks to `~/.kimi-code/config.toml`. Delete the folder of the logger.

8. **A turn.** In a new folder, start `kimi` and ask `hi`. *Does the tile appear with the prompt, titled `hi` and named after the new folder, with no badge, and turn green when the answer ends?*
9. **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?*
10. **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?*
11. **A question.** Ask `ask me to choose between two options before you answer`. *Does the tile turn amber while Kimi Code asks?*
12. **A subagent.** Ask for a task handed to a subagent. *Does peek show one running subagent while it works, and none once it ends? Does the tile stay without a badge until the session itself ends its turn?*
13. **An interrupt.** Ask `count from 1 to 300, one number per line` and press `esc`. *Does the tile turn green?*
14. **The end.** Quit `kimi`. *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?*
15. **Quitting Blossom.** Quit Blossom and ask `run the shell command ls`. *Does the tool run, with nothing printed about a hook?*
16. **Disconnect.** Disconnect Kimi Code in Settings > Agents. *Is `~/.kimi-code/config.toml` as it was before connecting, and does a new session no longer show?*
