Skip to content

Sessions & strands

Every ka session is a strand: one append-only JSONL file, a tree of records with a single live tip. The strand is the session’s state: replaying records to the tip reproduces everything, including the model, effort, and permission mode in use.

~/.local/share/ka/strands/<encoded-cwd>/<timestamp>_<id>.jsonl
spills: ~/.local/share/ka/spills/<id> (oversized tool output)
snapshots: per-session journals under the data dir (file undo)
waypoints: $TMPDIR/ka/<tty-hash> (strand id + tip per terminal)

Use KA_DATA_DIR to relocate the whole tree (handy for dev/prod separation).

Record Meaning
header First line: id, timestamp, cwd, versions, and a repo snapshot (branch + dirty list)
message User, assistant, or tool traffic; image parts persist on the message and on tool results (base64 in the JSONL, bounded by the read hand’s size cap)
change A settings change (model / effort / mode) with the role that made it
name A memorable alias set with /name <word>; the last one wins
digest A compaction record: summary + the kept-tail boundary
boundary A clear-context marker
custom Namespaced extensions (x.<vendor>.<name>); the engine reserves x.ka.*

ContextEdit is a protocol Command that edits or drops the context view of a single message while the ka session history stays append-only: the strand records the surgery, the raw history is never rewritten. /compactfrom [N] [focus] rewinds N turns and pins a summary (at most 6 sentences) of the dropped tail onto the kept branch; the same control lives in the Rewind modal.

  • An offshoot moves the tip to an earlier record (branching in place). /rewind (or ka rewind N) works this way, dropping the last N user turns.
  • A split copies a strand’s prefix into a new strand file with a parent link: a true fork.
  • A transfer (/transfer [focus]) digests the live context into a fresh child strand that carries only the summary, with the parent link set: a clean handoff when the old context is mostly noise.
  • A tree fork (/tree, then pick a past input) branches the strand at that point and prefills the composer with the picked prompt; the draft you already had is parked in the kill ring.
Terminal window
ka -c # this terminal's latest strand
ka --session 3f9c2a81 # by id prefix
ka --session auth-rework # by name (/name <word>)
ka serve → POST /sessions {"resume":"latest"} # over HTTP/SSE
ka --restore # resume the newest session, re-asking its dangling user turn (crash recovery)

On resume, ka streams-parses the strand, replays change records to restore settings, and synthesizes an aborted stop for any dangling turn (a killed process leaves nothing inconsistent; the log just ends). Names resolve exact-first (newest wins), then by unique prefix, identically in the TUI, ka serve, and ACP; ka sessions shows name · title.

Sessions can be pinned (★, sorted first in the picker) and archived: ka sessions --archived walks the archive tree, and ka session archive|unarchive moves strands in and out. With [context] recap_minutes set, a cheap model writes a one-line recap when a session goes idle, surfaced by ka sessions; rewinding a non-empty branch pins a branch summary (at most 3 sentences) onto the kept branch. Keys are documented in the config reference.

Images ride the records: a pasted prompt image or an image read result is stored with its record, so resuming reproduces the visual context. Replay is vision-gated: if the model active at resume takes image input, the stored parts are re-attached to the request; a text-only model drops them (the placeholder text inside the persisted tool result still stands) instead of failing at the wire’s vision gate. Switching a resumed strand from a vision model to a text-only one therefore degrades gracefully, never errors.

Every append is fsynced: a data sync after each record, plus a directory sync when the strand file is created. If the process or the machine dies mid-append, the worst case is one torn final line, and the next open heals it. A strand survives power loss the way it survives a kill: resumable to its last complete record.

Terminal window
ka sessions # list ids, titles, message counts, cost
ka export -o session.md # newest strand for this cwd, as markdown
ka export --html # or as a self-contained offline HTML page
ka export --jsonl # roundtrippable JSONL
ka search "auth middleware" # FTS5 across all strands (index feature)

/diff shows the session’s cumulative file diff: snapshot originals versus current disk. The full diff spills to disk; the transcript carries an excerpt.

Terminal window
ka gc --dry-run # show what would be collected
ka gc --max-age-days 30 # collect old data

edit and write park the target’s current bytes under the data dir before every mutation; if the snapshot fails, the change is refused. /undo (or ka undo) restores the most recent one; undoing a file creation deletes it. Snapshots are journaled per session.