Files
tty7/docs/agents/sessions.mdx
Austin Spragginsandl0ng-ai 2cdc26f357 Wire hooks, resume and detection for Kimi Code CLI (#694)
* feat(agents): wire hooks, resume and detection for Kimi Code

Kimi Code CLI takes its hooks as [[hooks]] entries in the same
config.toml that holds the user's providers and models, so this adds a
third install strategy — a format-preserving TOML merge on toml_edit —
beside the JSON map merge and the owned files. Like Qwen it reports
permission requests first-class, so it gets no Notification hook.
Resume rides `kimi --session <id>`; fork stays unwired, Kimi
documents none.

Closes #693

Signed-off-by: Austin Spraggins <spragginsdesigns@gmail.com>

* fix(agents): harden the Kimi Code TOML hook merge and its resume flags

The TOML merge strategy the Kimi wiring introduces round-trips a shared
config.toml cleanly, but three gaps sat behind it.

`hooks_state` counted only the marked entries that still named an event,
so a hand-edit that dropped the key off one of nine entries left the
remaining eight matching the roster exactly and the file reported
Installed with a broken entry in it. Every marked entry now counts,
which is what the JSON merge already did and what `refresh_hooks` needs
to see.

A `hooks = []` spelled as an empty inline array made install fail
outright -- toml_edit keeps an empty array and an array of tables apart,
but the two say the same thing and neither carries any configuration. It
is now promoted rather than refused. Every other wrong-shaped `hooks`
key -- a string, a table, a non-empty inline array -- still refuses with
the file left byte-for-byte alone.

`Stop` is not the only way a Kimi turn ends: its own event reference says
`Stop` does not fire on interrupts and `Interrupt` fires instead, and a
turn that dies on an error reports `StopFailure`. Without those two an
Esc or a failed turn left the pane on "working" for good and `tty7 wait`
could only ever time out. Both are observation-only events and report
the same end of turn `Stop` does.

On resume, `--agent` and `--agent-file` join the stale flags: Kimi
rejects either next to `--session` at startup, and resuming rebinds the
session agent by itself, so replaying them turned a working resume into
a launch error.

Tests cover the wrong-shaped `hooks` keys, a config.toml that does not
parse on both install and uninstall, a file that does not exist yet, a
second install being byte-for-byte the first, mangled and surplus marked
entries, an uninstall threading between the user's own entries and the
tables after them, and the `--session=<id>`, bare `--session`,
`--continue` and `--agent` spellings on the resume path.

---------

Signed-off-by: Austin Spraggins <spragginsdesigns@gmail.com>
Co-authored-by: l0ng-ai <24760907+l0ng-ai@users.noreply.github.com>
2026-08-20 09:51:05 +08:00

61 lines
2.1 KiB
Plaintext

---
title: "Agent sessions"
description: "Resuming a conversation after a reboot, forking a live one, and getting at the session id."
---
Coding agents keep their own conversation history, addressed by a session id.
Because tty7's hooks learn that id, it can do three things with it.
## Resume after a restart
When the server goes away — a reboot, a crash, a deliberate restart — the shells
go with it. Panes that were running an agent relaunch the conversation on
restore instead of coming back to a bare prompt:
```bash
claude --dangerously-skip-permissions --resume 8f3c…
```
The original launch flags are replayed, so the pane comes back the way you
started it, not the way the defaults would.
Supported for every recognised agent except Aider. Turn it off with
`restore_agent_sessions: false`.
<Note>
Resume needs the agent's hooks installed, since the session id comes from
them. [Installing hooks →](/agents/status)
</Note>
## Fork a live session
Forking branches a running conversation into a second, independent one. The
original keeps going untouched; both continue separately from the same history.
Right-click a **pane** to fork into a split — the menu offers a placement —
or right-click the **tab or sidebar row** to open the fork in a new tab.
| Agent | What tty7 runs |
|---|---|
| Claude Code | `claude --resume <id> --fork-session` |
| Codex | `codex fork <id>` |
| Grok | `grok --resume <id> --fork-session` |
| OpenCode | `opencode --session <id> --fork` |
| Oh My Pi | `omp --fork <id>` |
It is the agent's own fork command, run in a new pane — nothing is copied by
tty7 itself.
<Warning>
A fork duplicates the whole transcript in the agent's session store, so
forking repeatedly costs real disk. A pane on a
[remote machine](/remote/workspaces) cannot fork, because the command would
run against the local agent.
</Warning>
## Copy the session id
**Copy Session ID** — in the tab's right-click menu, beside *Copy Working
Directory*, and in the command palette — puts the agent's native id on the
clipboard. Paste it into `codex resume`, a bug report, or another tool.