# saisons

[![CPAN](https://img.shields.io/cpan/v/App-Saisons)](https://metacpan.org/dist/App-Saisons)
[![Kwalitee](https://cpants.cpanauthors.org/dist/App-Saisons.svg)](https://cpants.cpanauthors.org/dist/App-Saisons)
[![CPAN Testers](https://img.shields.io/badge/CPAN%20Testers-matrix-blue)](https://matrix.cpantesters.org/?dist=App-Saisons)

An interactive terminal UI for browsing, resuming, and managing AI coding agent sessions.

Supports [Claude Code](https://claude.ai/code), [Aider](https://aider.chat), [OpenAI Codex CLI](https://github.com/openai/codex), [Gemini CLI](https://github.com/google-gemini/gemini-cli), and [opencode](https://opencode.ai), with an adapter interface for adding more agents.

![saisons](docs/screenshot.png)

## Features

- Browse all sessions across all agents and projects
- Agent tag with brand colors (`✶ Cld`, `a Aid`, `☁ Cdx`, `✦ Gem`, `⎕ Opc`)
- Relative timestamps (`2h ago`, `3d ago`) and session size column
- Running session indicators (`●`)
- Sort by any column (`s` ascending, `S` descending)
- Flat or grouped-by-directory view
- A Claude Code session that ran out of context is dimmed, with its continuation listed under it (`└`); opening it offers the continuation instead
- Incremental metadata filter (`/`) and full-text search (`?`)
- Multi-select and open multiple sessions as new tabs simultaneously
- Peek at conversation history before opening (`v`)
- Move sessions between directories (`m`)
- Fork a session into the same or another folder, optionally a new git worktree (`f`)
- Delete sessions (`d`)
- Export sessions to a file and import them on another machine (`e`, `--export`, `--import`)
- Remembers selection and view mode across restarts
- Auto-detects tmux, screen, Epiton, Tilix, Ptyxis, gnome-terminal, iTerm2, and Terminal.app

## Install

Requires Perl 5.10+.

### Linux / macOS / WSL

```sh
curl -fsSL https://raw.githubusercontent.com/nicomen/saisons/main/install.sh | sh
```

### Windows

```powershell
irm https://raw.githubusercontent.com/nicomen/saisons/main/install.ps1 | iex
```

Installs [Strawberry Perl](https://strawberryperl.com/) via `winget` if needed, then downloads the script and creates a `.cmd` wrapper.

### Other ways

Grab the self-contained fatpacked script directly — a single file, no dependencies:

```sh
curl -fsSL https://raw.githubusercontent.com/nicomen/saisons/main/saisons -o ~/.local/bin/saisons
chmod +x ~/.local/bin/saisons
```

Or with cpanm:

```sh
cpanm https://github.com/nicomen/saisons/archive/main.tar.gz
```

### From source

```sh
git clone https://github.com/nicomen/saisons.git
cd saisons
perl Makefile.PL && make && make test && make install
```

To rebuild the fatpacked `saisons` script after editing sources:

```sh
make fatpack
```

`make fatpack` runs `slimpack -o saisons bin/saisons` (the external
App-SlimPacker bundler, which minifies; needs `slimpack` on `PATH` and
`PPI`). `saisons` is generated output — edit `bin/saisons` and `lib/`, not
`saisons`. You rarely need to run it yourself: after a push to `main`
passes the whole test matrix, GitHub Actions rebuilds `saisons`, checks
that it runs, and commits it.

## Usage

```sh
saisons
```

### Keys

| Key | Action |
|-----|--------|
| `↑` / `k` | Move cursor up |
| `↓` / `j` | Move cursor down |
| `PgUp` / `PgDn` | Page up / page down |
| `Home` / `g` | Jump to top |
| `End` / `G` | Jump to bottom |
| `Space` | Toggle select |
| `a` / `A` | Select all / deselect all |
| `s` | Sort mode: `←`/`→` pick the column, `↑`/`↓` the direction |
| `S` | Flip sort direction |
| `t` | Cycle grouping: flat / by path / by agent |
| `r` | Refresh running session indicators |
| `Enter` | Open selected sessions (cursor session if none marked) |
| `v` | View conversation history |
| `m` | Move session(s) to a different directory |
| `f` | Fork the session under the cursor and open the fork |
| `d` | Delete selected sessions |
| `e` | Export selected sessions (all shown if none marked) to a file |
| `/` | Incremental filter (title, path, date) |
| `?` | Full-text search (scans session files) |
| `q` / `ESC` | Quit (selection is remembered) |

### Where sessions open (the launcher)

`ENTER` resumes each selected session by running its agent's resume command
(e.g. `claude --resume <id>`) in the session's directory. The launcher
decides *in which terminal* that command runs:

- `tmux` / `screen` — one new multiplexer window per session
- `epiton` / `tilix` / `ptyxis` — one new tab per session in the active window
- `epiton-tile` — one new tile per session, laid out as a grid
- `gnome-terminal` — one new window with a tab per session
- `iterm` / `terminal-app` — one new tab or window per session
- `inline` — run in the current terminal, one session after the other

saisons picks one automatically (in tmux → `tmux`, in Epiton, Tilix or
Ptyxis → `epiton` / `tilix` / `ptyxis`, GUI with gnome-terminal →
`gnome-terminal`, macOS → `iterm`/`terminal-app`, otherwise `inline`).
Override it when the guess isn't what you want — for example to take over
the current pane even though you are inside tmux:

```sh
SAISONS_LAUNCHER=inline saisons
# tmux, screen, epiton, epiton-tile, tilix, ptyxis, gnome-terminal, iterm, terminal-app, inline
# (the old name CLAUDE_SESSIONS_LAUNCHER still works)
```

## Moving sessions to another machine

Export your sessions into one file, copy it over, and import it there:

```sh
saisons --export                      # all sessions, to saisons-<host>-<date>.tar.gz
saisons --export sessions.tar.gz      # or name the file
saisons --import sessions.tar.gz      # on the other machine
```

In the list, `e` exports the marked sessions, or every session shown if
none are marked.

Import adds sessions next to the ones already there. Sessions that are
already there are left alone, so running it twice is safe. If your home
directory has a different path on the new machine, paths under it are
changed to match, so resume still works.

Other folders that moved get `--map FROM=TO`, once per folder; `~` in TO
is your home folder on this machine:

```sh
saisons --import sessions.tar.gz --map '/projects=~/projects'
```

Sessions only resume inside their project folder, so import checks each
one first. For every project it says whether the folder is there, and if
not, how to get it:

- a git repo with a remote: the `git clone` command, with the branch
  you were on
- a repo that is there but doesn't have your latest commit yet: a reminder
  to pull
- a folder that isn't in git: a note to copy it by hand

It also warns when the source had uncommitted or unpushed work, since a
clone won't include it.

Import asks whether to clone the missing repos. Use `--clone` or
`--no-clone` to skip the question, and `--dry-run` to see the report
without importing anything. Aider keeps its history inside the project
folder, so Aider sessions are skipped until the folder exists. Run the
import again once it does.

Sessions from opencode 1 can go into opencode 2. opencode converts them
the next time it starts, so restart it after importing:
`opencode service restart`.

Logins and API keys are not exported.

## Supported agents

| Agent | Sessions stored in | Resume command |
|-------|--------------------|----------------|
| Claude Code | `~/.claude/projects/` | `claude --resume <id>` |
| Aider | `.aider.chat.history.md` per project dir | `aider --restore-chat-history` |
| OpenAI Codex | `~/.codex/sessions/YYYY/MM/DD/` | `codex resume <file>` |
| Gemini CLI | `~/.gemini/tmp/<slug>/chats/` | `gemini --resume <uuid>` |
| opencode | `~/.local/share/opencode/opencode.db` (SQLite) | `opencode --session <id>` |

Aider history files are searched one level deep under `~/projects`, `~/dev`, `~/src`, `~/work`, `~/code`, and `/projects`. Override with `SAISONS_SEARCH_DIRS=dir1:dir2` (separate with `;` on Windows).

The opencode adapter reads its SQLite database via the `sqlite3` CLI, which must be installed. `XDG_DATA_HOME` is respected.

## Adding support for other agents

See [`lib/App/Saisons/Adapter/HOWTO.md`](lib/App/Saisons/Adapter/HOWTO.md) for a copy-paste template. In short:

1. Create `lib/App/Saisons/Adapter/MyAgent.pm` implementing six methods: `name`, `find_sessions`, `running`, `launch`, `delete_session`, `load_messages`. Add `export_sessions` and `import_sessions` to support moving sessions between machines.
2. Add it to the `@adapters` list in `saisons`
3. Optionally add a brand color entry to `%ADAPTER_TAGS` in `lib/App/Saisons/UI.pm`

## Session state

`saisons` state (remembered selections, view mode) is stored in `~/.config/saisons/state.json`.
