Skip to content
Sessions

Sessions

A session is the persisted form of a single conversation. It captures the full message history, metadata (model, agent, token counts, cost), and a human-readable title.

The data model is in internal/session/session.go and the storage abstraction in internal/session/store.go.

Where sessions are stored

The default location depends on your configured backend.

BackendDefault path
sqlite (default)~/.local/share/ulmi/sessions.db
json~/.local/share/ulmi/sessions/<id>.json

Both can be overridden via sessions.path in your config. See Configuration for the YAML keys.

How saving works

Sessions are saved automatically:

  • Every time the model produces a final response.
  • Every time the agent completes a tool call cycle.
  • After a /compact, /new, or session resume.

The save runs as a background tea.Cmd and never blocks the UI; if it fails, you see a one-line warning in the chat.

The session ID is a generated UUID. The title is derived from the first non-slash user message and is later regenerated on demand by Session.GenerateTitle.

Resuming sessions

ulmi --continue                    # resume most recent
ulmi --session <id>                # resume a specific session
ulmi session list --search "auth"  # find an ID

In the TUI, /sessions (or Ctrl+X L) opens a picker over all saved sessions ordered by UpdatedAt. Selecting one rewrites the chat from the session’s history; if the session was saved with a different model, Ulmi switches to that model when the provider is available.

Forking a session

/fork clones the current conversation into a new session (new UUID, title Fork of <original>) and switches the TUI to the fork. The source session is saved first when a store is configured, so both branches remain available under /sessions. Message history and token/cost counters are copied; file snapshots start fresh for the new session ID. Implemented by session.Fork.

Listing and exporting

ulmi session list                          # tabular output
ulmi session list --json                   # machine-readable
ulmi session list --search "auth refactor"
ulmi session list --limit 10

ulmi session export <id> --format markdown -o transcript.md
ulmi session export <id> --format json

Inside the TUI, /export writes a markdown file ulmi-<timestamp>.md in the working directory. Markdown export is implemented in internal/session/export.go.

On TUI exit, Ulmi always prints a resume hint (ulmi --session <id> or ulmi --continue). When tui.print_history_on_exit is enabled (default), it also dumps the in-TUI chat transcript to the terminal scrollback.

Deleting sessions

ulmi session delete <id>

This is unconditional — there is no built-in trash.

Auto-compaction

Long conversations exceed the model’s context window. Ulmi watches the live context-fill estimate and, once it crosses 80% of the model’s context window (or sessions.auto_compact_tokens when the window is unknown), asks the model to summarise the history once the current turn has fully closed:

  1. Every leading system message is preserved and the stable base system prompt is re-injected after compaction.
  2. The most recent N messages (default 6) are kept verbatim, aligned so a tool result is never split from its tool_use.
  3. The older middle is sent to the LLM (with its tool activity) and replaced by a marker plus the model’s summary.

The implementation is session.Compact with WithKeepRecent; auto-compact runs it asynchronously so the TUI stays responsive. A short notice (ℹ Compacting context …) is added to the chat so you can tell when it happens. After three failed compact attempts in a session, auto-compact stops trying.

Setting auto_compact_tokens: 0 disables the fallback threshold when the window is unknown. A known context window still auto-compacts at 80%.

Manual compaction (/compact)

/compact (slash only — there is no Ctrl+X C binding) runs the same session.Compact summariser, but over the whole conversation (no kept tail): it replaces the dropped prefix with the summary while keeping every leading system message.

Use it when:

  • You want to dramatically shrink a session that has spiralled in size.
  • You want a clean breakpoint before changing topic.

Implementation: internal/session/compact.go.

Sessions and snapshots

File mutations performed during a session are tracked by the snapshot manager. The snapshot history is keyed by session ID, so:

  • ulmi snapshot list --session <id> shows every mutation in a session.
  • Reverting via /undo walks back through the journal.

When a fresh session is started (TUI launch with no --session flag) the snapshot store uses startup as the placeholder session ID. See Snapshots.

Storage backends

SQLite

The default. Uses modernc.org/sqlite (pure Go, no CGO). Single file with sessions and subtasks tables. Schema upgrades use PRAGMA user_version and ordered steps in migrate.go: opening an older file upgrades it in place; a file whose version is newer than this binary is rejected. Suitable for thousands of sessions without performance concerns.

JSON

One file per session inside sessions.path. Easier to inspect by hand or sync with git. Slower for list operations on very large numbers of files but otherwise behaviour-compatible with the SQLite backend.

Switch with:

sessions:
  storage: json
  path: ~/.local/share/ulmi/sessions

Both implementations conform to the Store interface in internal/session/store.go.

Sharing (planned)

The sharing.enabled flag in the config is reserved for a future hosted share feature (publishing a session to a URL). It currently has no effect.