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
5 changes: 3 additions & 2 deletions AGENTS.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Launch, watch, search and resume your coding CLI sessions: [Claude Code](https:/
- Preview conversation context with search term highlighting
- See context size (tokens as of the last reply), message counts, hit counts, and file size per conversation
- Resume conversations directly from the search interface
- Background tasks and subagents: a session open in `claude` shows `⧗N` for its running background commands and monitors and a pink `◆N` for its running subagents, and the preview lists both with how long each has run
- Background tasks and subagents: a session open in `claude` shows `⧗N` for its running background commands and monitors and a pink `◆N` for its running subagents, and the preview lists both with how long each has run. Its subagents and teammates (Agent tool) also get rows of their own, nested `└` under it with a pink `◆` and `subagent` on the grey row, while they run and for 30 minutes after one finishes (marked `closed`), then they leave the list; only a running session's are shown. Selecting one previews its transcript; it has no message box, Enter opens its session, and delete, rename, prune, fork, pin and snooze are refused
- Every count in the list has its own glyph, explained at the bottom of `?` help: `⌕N` search hits, and each session's PRs as `✓` ready, `✗` needs you, `◷` waiting (checks running, review required, blocked), `○` draft, `+` merged
- Auto-refreshes every minute; a green `●` marks conversations open in a running `claude`, and ones started by another session's `claude -p` sit `└` under it
- Artifacts: the claude.ai pages a session (or its subagents) published, opened or read with Claude Code's Artifact tool show on the preview's `Artifacts:` line (the latest, and how many more), and `Ctrl+O` lists them all by title, after its PRs, to open with Enter
Expand Down
72 changes: 72 additions & 0 deletions internal/transcript/subagentrows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package transcript

import (
"os"
"strings"
"sync/atomic"
)

// KindSubagent is a Claude Code subagent (Agent tool, async or a teammate)
// listed as a row of its own under the session running it: its transcript
// is <session>/subagents/agent-<id>.jsonl, which GetConversations never
// reads. Rows are read-only: a subagent has no session file or socket.
const KindSubagent = "subagent"

// SubagentConv is s, one of parent's subagents, as a Conversation: SessionID
// s.ID, Kind KindSubagent, ParentID the parent's session, titled by its
// meta.json. With prev (the last read of it) only the lines appended since
// are parsed (ParseAppended); without, a copy cached at the file's size and
// time is reused, else it's read whole once.
func SubagentConv(prev *Conversation, parent Conversation, s Subagent) (*Conversation, error) {
if prev != nil && prev.FilePath == s.Path {
return ParseAppended(prev)
}
info, err := os.Stat(s.Path)
if err != nil {
return nil, err
}
ParseCacheMu.Lock()
cached, ok := ParseCache[s.Path]
ParseCacheMu.Unlock()
if ok && cached.size == info.Size() && cached.modTime.Equal(info.ModTime()) {
if cached.conv == nil {
return nil, nil
}
c := *cached.conv
return &c, nil
}
return parseSubagentWhole(s.Path, parent.SessionID, s.Name, parent.Cwd)
}

// SubagentReads counts whole reads of subagent transcripts; tests use it to
// see a row isn't read again until its file changes.
var SubagentReads atomic.Int64

// parseSubagentWhole reads a subagent's transcript whole and caches it in
// ParseCache by its size and time, like any transcript.
func parseSubagentWhole(path, parentID, name, cwd string) (*Conversation, error) {
info, err := os.Stat(path)
if err != nil {
return nil, err
}
SubagentReads.Add(1)
conv, err := ParseConversationUncached(path, info)
if err != nil {
return nil, err
}
if conv != nil {
conv.Kind, conv.ParentID, conv.Spawned = KindSubagent, parentID, true
if name != "" {
conv.Title = name // meta.json's, cleaned as it was read
}
if conv.Cwd == "unknown" && cwd != "" {
conv.Cwd = cwd
}
conv.SearchText = SearchTextOf(*conv) // with its kind and title
conv.SearchLower = strings.ToLower(conv.SearchText)
}
ParseCacheMu.Lock()
ParseCache[path] = parsedFile{info.Size(), info.ModTime(), conv}
ParseCacheMu.Unlock()
return conv, nil
}
13 changes: 12 additions & 1 deletion internal/transcript/transcript.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,6 +443,9 @@ func ParseAppended(prev *Conversation) (*Conversation, error) {
return &c, nil
}
if info.Size() < prev.Size || prev.TailApplied || prev.ParsedBytes > info.Size() {
if prev.Kind == KindSubagent { // ParseConversationFile skips agent-*.jsonl
return parseSubagentWhole(prev.FilePath, prev.ParentID, prev.Title, prev.Cwd)
}
return ParseConversationFile(prev.FilePath, time.Time{}, 0)
}
file, err := os.Open(prev.FilePath)
Expand Down Expand Up @@ -1103,6 +1106,9 @@ func (c Conversation) Questions() []askQuestion {
// --all (showHeadless). Apps you type in start sessions as cli,
// claude-desktop or sdk-ts, never sdk-cli.
func (c Conversation) Headless() bool {
if c.Kind == KindSubagent { // listed only while its session runs it (SubagentConv)
return false
}
if c.Kind == KindCodex {
return c.CodexExec && !c.IsCustomTitle
}
Expand Down Expand Up @@ -1654,6 +1660,9 @@ func AgentGlyph(conv Conversation) (glyph, colour string) {
if conv.Kind == KindCodex {
return "⬡", "37"
}
if conv.Kind == KindSubagent { // the ◆ its session's count uses
return "◆", SubagentColour
}
return "✻", "38;5;173"
}

Expand Down Expand Up @@ -2111,6 +2120,8 @@ const MaxTaskLines = 5
// included), from the meta.json Claude Code writes beside its transcript in
// <session>/subagents/.
type Subagent struct {
ID string // its transcript's name without .jsonl (agent-<id>): its row's SessionID (SubagentConv)
Path string // its transcript
Name string
Started time.Time
LastWrite time.Time // its transcript's: a working subagent writes every few seconds
Expand Down Expand Up @@ -2197,8 +2208,8 @@ func SubagentsOf(conv Conversation) []Subagent {
c.name = CleanText(meta.Description)
}
}
s := Subagent{Name: c.name, Finished: c.finished}
transcript := strings.TrimSuffix(path, ".meta.json") + ".jsonl"
s := Subagent{ID: strings.TrimSuffix(filepath.Base(transcript), ".jsonl"), Path: transcript, Name: c.name, Finished: c.finished}
s.Started = c.subagentStarted(transcript)
subagentCache.metas[path] = c
if info, err := os.Stat(transcript); err == nil {
Expand Down
41 changes: 41 additions & 0 deletions internal/tui/live.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@ type liveMsg struct {
hosts map[string]string // live sessions run by an app, not in a terminal: the app's name
bg map[string]sessions.BgSession // background sessions (claude --bg); nil when not asked this tick
gen int
// The live sessions' subagent rows (subagents.go) and their meta, when
// subsKnown: read in time this tick, so a missing row was dropped.
subRows []transcript.Conversation
subStats map[string]transcript.Subagent
subsKnown bool
}

func liveTick() tea.Cmd {
Expand Down Expand Up @@ -111,6 +116,26 @@ func (m model) liveCmd(askAgents bool) tea.Cmd {
}
var mu sync.Mutex
var wg sync.WaitGroup
// The live sessions' subagent rows, beside the transcript reads
// and under the same deadline; one still stuck from an earlier
// tick isn't started again, and its rows stand meanwhile.
if _, busy := sessions.LiveReads.LoadOrStore(subagentRowsKey, true); !busy {
starts := make(map[string]string, len(scanned))
for id, s := range scanned {
starts[id] = s.Start
}
parents, since, prevSubs := subagentParents(byID, live, starts)
wg.Add(1)
go func() {
defer wg.Done()
defer sessions.LiveReads.Delete(subagentRowsKey)
defer transcript.RecoverWorker()
rows, subs := subagentRowsFor(parents, since, prevSubs, time.Now())
mu.Lock()
msg.subRows, msg.subStats, msg.subsKnown = rows, subs, true
mu.Unlock()
}()
}
for id := range check {
conv, ok := byID[id]
if !ok {
Expand Down Expand Up @@ -259,6 +284,14 @@ func (m *model) opening(id string, fork bool) bool {
// exited, or whose file can't be read right now, is reported instead of
// resumed a second time.
func (m *model) focusCmd(conv transcript.Conversation) tea.Cmd {
if conv.Kind == transcript.KindSubagent { // it runs inside its session: that's what opens
p, ok := m.subagentParentOf(conv)
if !ok {
m.note(subagentNote)
return nil
}
conv = p
}
if m.inT3(conv.SessionID) {
return m.openT3Cmd(conv)
}
Expand All @@ -284,6 +317,14 @@ func (m *model) focusCmd(conv transcript.Conversation) tea.Cmd {
// a session resumed elsewhere since the last live tick is focused, not
// resumed a second time. Forks always open a new session.
func (m *model) resumeCmd(conv transcript.Conversation, fork bool) tea.Cmd {
if conv.Kind == transcript.KindSubagent { // Enter opens its session; there's nothing of its own to fork
p, ok := m.subagentParentOf(conv)
if fork || !ok {
m.note(subagentNote)
return nil
}
conv = p
}
if !fork && m.inT3(conv.SessionID) {
return m.openT3Cmd(conv)
}
Expand Down
5 changes: 5 additions & 0 deletions internal/tui/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ func (m *model) applyRefresh(msg refreshMsg) {
selectedID = m.filtered[m.cursor].conv.SessionID
}
prevScroll := m.previewScroll
for _, it := range m.items { // subagent rows come from the live tick, not the scan
if it.conv.Kind == transcript.KindSubagent {
msg.items = append(msg.items, it)
}
}
m.items = msg.items
m.lastFilterQuery = "" // force a full rescan, not incremental narrowing
m.hits = &hitCounter{byID: make(map[string]int)}
Expand Down
8 changes: 4 additions & 4 deletions internal/tui/preview.go
Original file line number Diff line number Diff line change
Expand Up @@ -928,9 +928,9 @@ const (
// (under 40 columns the time goes too), never the glyph.
func (m model) headerSummary(conv transcript.Conversation, query, when string) string {
parts := []string{highlight(transcript.Truncate(filepath.Base(conv.Cwd), 24), query)}
if conv.Kind == transcript.KindCodex {
if conv.Kind != "" { // codex, or a Claude subagent
glyph, colour := transcript.AgentGlyph(conv)
parts = append(parts, "\033["+colour+"m"+glyph+"\033[0m codex")
parts = append(parts, "\033["+colour+"m"+glyph+"\033[0m "+conv.Kind)
}
if conv.LastError != "" {
parts = append(parts, "\033[1;31m! "+conv.LastError+"\033[0m")
Expand Down Expand Up @@ -1049,9 +1049,9 @@ func (m model) renderPreview(item listItem, height int) string {
// sessionStats is the preview header's model, token and error lines.
func sessionStats(conv transcript.Conversation) []string {
var lines []string
if conv.Kind == transcript.KindCodex {
if conv.Kind != "" {
glyph, colour := transcript.AgentGlyph(conv)
lines = append(lines, "\033[1;33mAgent:\033[0m \033["+colour+"m"+glyph+"\033[0m codex")
lines = append(lines, "\033[1;33mAgent:\033[0m \033["+colour+"m"+glyph+"\033[0m "+conv.Kind)
}
if conv.ActiveModel != "" || conv.ContextTokens > 0 {
window := conv.WindowSize()
Expand Down
Loading
Loading