Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changelog

## 1.0.99

- Feat: **`codev session list` and `show` say which sessions are running**, in every account: each session carries `live`, and `pid` and `status` (`busy` / `idle`) when it is. `list --live` lists only the running ones and `list --not-live` the rest; `--live` lists every running session rather than the newest 30. Running means the process in the session's `sessions/<pid>.json` is alive and started when that file says — a leftover file whose pid was reused does not count, and neither does a file with no start time (older Claude Code), which nothing ties to the process now holding its pid. Running sessions that `history.jsonl` does not have — a fresh `/branch` copy before its first prompt — are now listed, shown and resumable too. The `--pretty` list has a `LIVE` column, and its legend always says what `✗` means (the transcript is gone, the session cannot be resumed), which read as "not running" before
- Feat: **`lastActivity`, when a session last did something.** `lastActive` is the last *prompt* — `history.jsonl` records only what the user types — so a session that worked for two hours after one prompt still showed the prompt time. `lastActivity` is the later of that and the last timestamped record in the session's transcript; `lastActive` is unchanged. In `list`, `show` and `self`, and as a `LAST ACTIVITY` column in `list --pretty` (whose `LAST ACTIVE` column is now headed `LAST PROMPT`). On one machine `list --all` over 844 sessions went from 0.95 s to 1.45 s
- Change: **the details panel under a row opens with `⌘→` and closes with `⌘←`** (or `Esc`). `⌘↓` / `⌘↑` still work. `↑` / `↓` move between sessions, so the same arrows with `⌘` doing something else felt wrong; `→` / `←` expand and collapse, as in a Finder list. In the search box `⌘→` is also "caret to the end": while the caret is not at the end of the text it does only that, and the next `⌘→` opens the panel
- Settings → Shortcuts has a **Selected Session** section: `⌘→` / `⌘←`, `⌘I`, `⌘⇧C` and the right-click menu, which were listed nowhere in the app
- Fix: **`codev session self` JSON has `lastActive` and `promptCount`**, which `self --pretty` already printed, plus `lastActivity` and `live: true`. `show --pretty` and `self --pretty` print `Running`, `Last prompt` and `Last activity` lines in place of `Last active`

## 1.0.98

- Fix: **resuming a session of the default account works in a shell that has another account's `CLAUDE_CONFIG_DIR`** ([#172](https://github.com/grimmerk/codev/issues/172)). Claude Code printed `No conversation found with session ID: …` when `codev session resume`, or a pasted "resume command", ran in such a shell — typically inside another account's Claude Code session (its shell tool, a `!` command, an agent), or a terminal started from one. The command left the variable as it found it, so Claude Code looked in the other account. It now clears it for that one command (`env -u CLAUDE_CONFIG_DIR claude --resume …`, as the `claude` launcher already did for the default account). Terminal tabs CodeV opens itself were not affected; commands for other accounts are unchanged
Expand Down
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ The `📌 Pinned (N)` header carries two independent toggles:

Keyboard semantics worth knowing: the shortcuts act on the **selected row** (the one with the blue left border — hovering selects), and require an explicit selection. `⌘D` = pin/unpin toggle; `⇧⌘D` = hide (on a pinned row this unpins *and* folds in one step — pin and hide are mutually exclusive). When the last pin is removed the header disappears entirely (that's normal, not a collapse). A pinned session is never folded away as a "minor session", whatever its message count.

**Copy what identifies a session** — right-click a row for a menu that copies its **title**, **session ID**, **transcript path**, **project path**, **resume command** (`cd … && claude --resume …`, under the session's own account) or a one-line **reference** (title + full id), each item showing the value it will copy. `⌘⇧C` copies the reference of the selected row. `⌘I` opens the same fields as a details overlay, `⌘↓` shows them under the row (`⌘↑` or `Esc` closes); click any line to copy it. The same fields are available from a terminal — see [`codev session`](#multi-account-support-claude-code).
**Copy what identifies a session** — right-click a row for a menu that copies its **title**, **session ID**, **transcript path**, **project path**, **resume command** (`cd … && claude --resume …`, under the session's own account) or a one-line **reference** (title + full id), each item showing the value it will copy. `⌘⇧C` copies the reference of the selected row. `⌘I` opens the same fields as a details overlay, `⌘→` shows them under the row (`⌘←` or `Esc` closes; `⌘↓` / `⌘↑` work too); click any line to copy it. In the search box, `⌘→` first moves the caret to the end of the text, as usual, and opens the details once it is there. Settings → Shortcuts lists these keys. The same fields are available from a terminal — see [`codev session`](#multi-account-support-claude-code).

#### Live view and saved session lists

Expand Down Expand Up @@ -166,15 +166,17 @@ The **default account** can be launched three equivalent ways: bare `claude`, `c

| Command | What it does |
| --- | --- |
| `codev session list [--path <dir>] [--account <name>] [--all \| --limit N]` | Sessions, newest first. Without `--path`: the newest 30, unless `--all` or `--limit N`. With `--path`: **every** session of that directory, unless `--limit N`. `--path .` = sessions whose project is this directory |
| `codev session list [--path <dir>] [--account <name>] [--live \| --not-live] [--all \| --limit N]` | Sessions, newest first. Without `--path` or `--live`: the newest 30, unless `--all` or `--limit N`. With either: **every** matching session, unless `--limit N`. `--path .` = sessions whose project is this directory. `--live` = only the sessions running now; `--not-live` = the rest |
| `codev session show <title \| id>` | Title, full id, account, project path, transcript path and resume command of **every** matching session |
| `codev session view <title \| id> [--last N]` | The last N things the user and the assistant said (default 10; text only — no tool calls, tool results or thinking) |
| `codev session self` | The session this command is being run from — for use inside a Claude Code session |
| `codev session resume <title \| id>` | Resume it in the current terminal, under its own account — whatever your default-terminal setting is |

`<title | id>` is a full session id, the first **four or more hex** characters of one (hyphens allowed — the same rule as the Sessions tab's search), or a session title — its `/rename` name, or the title Claude Code generated for a session that was never renamed (`titleKind` in the output says what a title is: `custom` = a `/rename` name, `ai` = generated, `unknown` = a title captured earlier that could be either, `none` = no title). A title is matched whole, ignoring case; part of a title works when nothing matches outright. **Titles are not unique** — `/branch` copies share theirs — so `show` lists every match, while `view` and `resume` list the candidates and exit non-zero instead of picking one.

**Which sessions it sees.** `list`, `show`, `view` and `resume` read each account's `history.jsonl`, so a session that has never been given a prompt (a fresh `/branch` copy) or that was started from VS Code or Claude Desktop is not there — the Sessions tab shows those, the CLI does not yet. `self` does not depend on history: it identifies the running session from the registration its process keeps (`sessions/<pid>.json`), so it works for those too.
**Which sessions it sees.** `list`, `show`, `view` and `resume` read each account's `history.jsonl`, plus every session **running** now, from the registration its process keeps (`<config dir>/sessions/<pid>.json`) — so a running session that has never been given a prompt (a fresh `/branch` copy) is listed too. One that is neither in history nor running — never prompted, or started from VS Code or Claude Desktop, and since closed — is not; the Sessions tab shows those, the CLI does not yet. `self` identifies the running session from its registration, so it does not depend on history at all.

**Running, and when it last did something.** In the JSON of `list`, `show` and `self`, every session carries `live` (with `pid` and `status` — `busy` or `idle` — when it is running), `lastActive`, `lastActivity` and `promptCount`; `self` is always `live: true`. `view` has none of these. A session counts as running when its registration's process is alive **and** started when the registration says, so a leftover file whose pid now belongs to another process does not count; in `list` and `show`, neither does a registration with no start time (written by an older Claude Code), since nothing ties it to the process holding its pid. `self` is the exception: run from inside the session, it can still prove such a registration when `CLAUDE_CODE_SESSION_ID` in its environment names the same session. `lastActive` is the session's **last prompt** (`history.jsonl` records only what the user types); `lastActivity` is the later of that and the last timestamped record in its transcript, so a session that has worked for two hours on one prompt shows when it last did something. In `--pretty` lists the `LIVE` column shows `busy` / `idle`, and `✗` means the transcript is gone and the session cannot be resumed — it says nothing about whether it is running.

> **Add is just a mapping.** `add <name>` registers *name → config folder* (default `~/.claude-<name>` — that folder **is** the account's `CLAUDE_CONFIG_DIR`). Claude Code itself creates and fills the folder on first login (`claude <name>`). One folder = one account: registering an already-registered folder under a second name is rejected.
>
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "CodeV",
"productName": "CodeV",
"version": "1.0.98",
"version": "1.0.99",
"description": "Quick switcher for VS Code, Cursor, and Claude Code sessions",
"repository": {
"type": "git",
Expand Down
159 changes: 155 additions & 4 deletions src/cli/codev-session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const addSession = (
fs.writeFileSync(path.join(dir, `${sessionId}.jsonl`), lines.join('\n') + '\n');
};

let selfDeps: Pick<CliDeps, 'ancestors' | 'env'> = {};
let selfDeps: Pick<CliDeps, 'ancestors' | 'env' | 'processes'> = {};

const run = (...argv: string[]) => {
const out: string[] = [];
Expand All @@ -71,6 +71,8 @@ const run = (...argv: string[]) => {
cwd: () => app,
ancestors: () => [],
env: () => ({}),
// Never the real `ps`: a fixture pid could be a real process here.
processes: () => new Map(),
...selfDeps,
});
return { code, out, err, stdout: out.join('\n'), stderr: err.join('\n') };
Expand Down Expand Up @@ -310,9 +312,9 @@ describe('codev session show', () => {

it('--pretty prints every field as text, and says when the transcript is gone', () => {
const text = run('show', ID_D.slice(0, 8), '--pretty').stdout;
expect(text).toContain(`Session ID: ${ID_D}`);
expect(text).toContain('Title: (none)');
expect(text).toContain('Transcript: (not found');
expect(text).toContain(`Session ID: ${ID_D}`);
expect(text).toContain('Title: (none)');
expect(text).toContain('Transcript: (not found');
});

it('keeps stdout empty on failure and puts a JSON error on stderr', () => {
Expand Down Expand Up @@ -423,6 +425,12 @@ describe('codev session self', () => {
name: 'api cleanup',
proof: 'process-start',
environmentAgrees: true,
// What `self --pretty` prints as "Last prompt … · N prompts" is in the JSON too.
live: true,
lastActive: new Date(2000).toISOString(),
promptCount: 1,
// No timestamped record in its transcript: the last prompt.
lastActivity: new Date(2000).toISOString(),
});
});

Expand All @@ -440,6 +448,149 @@ describe('codev session self', () => {
});
});

describe('live sessions and last activity', () => {
const ID_E = '44440000-eeee-4eee-8eee-000000000005';
const START = 'Sun Nov 1 10:00:00 2026';
// Key order of a real sessions/<pid>.json (2.1.329); values invented.
const register = (
account: IdentityAccount,
pid: number,
sessionId: string,
over: Record<string, unknown> = {},
): void => {
fs.mkdirSync(path.join(account.dir, 'sessions'), { recursive: true });
fs.writeFileSync(
path.join(account.dir, 'sessions', `${pid}.json`),
JSON.stringify({
pid,
sessionId,
cwd: app,
startedAt: 1793527200000,
procStart: START,
version: '2.1.329',
peerProtocol: 1,
kind: 'interactive',
entrypoint: 'cli',
name: 'billing fix',
updatedAt: 1793527500000,
status: 'busy',
...over,
}),
);
};
const ps = (pid: number, startUtc = 'Sun Nov 1 10:00:00 2026') =>
[pid, { pid, ppid: 1, startUtc, command: 'claude' }] as const;
const live = (...procs: ReturnType<typeof ps>[]) => {
selfDeps = { processes: () => new Map(procs) };
};
// A turn_duration record, then bookkeeping with no timestamp of its own —
// how a real transcript usually ends.
const tail = (at: string, sessionId: string) => [
JSON.stringify({
parentUuid: 'x',
isSidechain: false,
type: 'system',
subtype: 'turn_duration',
durationMs: 1200,
messageCount: 4,
timestamp: at,
uuid: '00000000-0000-4000-8000-00000000beef',
isMeta: false,
cwd: app,
sessionId,
}),
JSON.stringify({
type: 'cost-state',
sessionId,
totalCostUSD: 1.5,
startTime: 1793527200000,
modelUsage: { m: { timestamp: '2030-01-01T00:00:00.000Z' } },
}),
];
const idsOf = (stdout: string): string[] =>
JSON.parse(stdout).sessions.map((s: { sessionId: string }) => s.sessionId);
const listed = (...argv: string[]) =>
JSON.parse(run('list', ...argv).stdout).sessions as Record<string, unknown>[];

it('marks running sessions, and not a leftover file whose pid now belongs to another process', () => {
register(main, 700, ID_A);
// Same pid alive, different start: the pid was reused — not ID_C running.
register(work, 702, ID_C, { cwd: api, status: 'idle' });
live(ps(700), ps(702, 'Mon Nov 2 09:00:00 2026'));
const rows = listed();
const byId = new Map(rows.map((r) => [r.sessionId, r]));
expect(byId.get(ID_A)).toMatchObject({ live: true, pid: 700, status: 'busy' });
expect(byId.get(ID_C)).toMatchObject({ live: false, pid: null, status: null });
expect(byId.get(ID_B)).toMatchObject({ live: false });
// A registration whose process is gone is not running either.
live();
expect(listed().every((r) => r.live === false)).toBe(true);
});

it('--live / --not-live filter on it, and --live lists a running session history has never seen', () => {
register(main, 700, ID_A);
// ID_E: running, never prompted — in no history.jsonl. Its transcript
// already carries the title.
register(work, 703, ID_E, { cwd: api, name: 'fresh branch', updatedAt: 5000, status: 'idle' });
const dir = path.join(work.dir, 'projects', transcriptSlug(api));
fs.mkdirSync(dir, { recursive: true });
fs.writeFileSync(
path.join(dir, `${ID_E}.jsonl`),
JSON.stringify({ type: 'custom-title', customTitle: 'fresh branch', sessionId: ID_E }) + '\n',
);
live(ps(700), ps(703));
expect(idsOf(run('list', '--live').stdout)).toEqual([ID_E, ID_A]);
const e = listed('--live')[0];
expect(e).toMatchObject({
title: 'fresh branch',
account: 'work',
projectPath: api,
live: true,
status: 'idle',
lastActive: null,
promptCount: 0,
});
expect(idsOf(run('list', '--not-live').stdout)).toEqual([ID_B, ID_C, ID_D]);
// …and show finds it by its title.
expect(JSON.parse(run('show', 'fresh branch').stdout).sessions[0].sessionId).toBe(ID_E);
expect(run('list', '--live', '--not-live').code).toBe(2);
});

it('lastActivity is the last timestamped transcript record; lastActive stays the last prompt', () => {
fs.rmSync(path.join(main.dir, 'projects'), { recursive: true });
addSession(main, ID_A, app, {
title: 'billing fix',
at: 4000,
extra: tail('2026-11-01T12:34:56.000Z', ID_A),
});
const a = listed().find((r) => r.sessionId === ID_A);
expect(a).toMatchObject({
lastActive: new Date(4000).toISOString(),
lastActivity: '2026-11-01T12:34:56.000Z',
});
const shown = JSON.parse(run('show', ID_A).stdout).sessions[0];
expect(shown.lastActivity).toBe('2026-11-01T12:34:56.000Z');
expect(shown.live).toBe(false);
// Never earlier than the last prompt: a prompt that never reached the
// transcript, or a transcript that is gone, leaves the prompt time.
addSession(main, ID_A, app, { at: Date.parse('2026-11-02T08:00:00.000Z'), transcript: false });
expect(listed().find((r) => r.sessionId === ID_A)?.lastActivity).toBe('2026-11-02T08:00:00.000Z');
expect(listed().find((r) => r.sessionId === ID_D)?.lastActivity).toBe(new Date(1000).toISOString());
});

it('--pretty has a LIVE column and always explains ✗', () => {
register(main, 700, ID_A);
live(ps(700));
const r = run('list', '--path', '.', '--pretty');
expect(r.out[0]).toContain('LIVE');
expect(r.out.find((l) => l.startsWith(ID_A.slice(0, 8)))).toContain('busy');
// No row here has ✗, and the legend still says what it means.
expect(r.out.some((l) => l.startsWith(ID_D.slice(0, 8)))).toBe(false);
expect(r.stdout).toContain('✗ = transcript gone, cannot be resumed (not about running)');
expect(run('show', ID_A, '--pretty').stdout).toContain('Running: yes — pid 700 · busy');
});
});

describe('options', () => {
it('rejects an option the command does not have instead of ignoring it', () => {
// A typo must not run as if the option had not been given.
Expand Down
Loading
Loading