Skip to content

feature: agentop observe — group sessions and cost by working directory #1739

Closed
4 of 4 issues completed

Description

@clawgenti

Problem

agentop observe now shows the cost of each session, so it is easy to see which tasks cost the most. Answering "where did my tokens go this month?" still means adding up sessions by hand, because nothing groups them by the project they ran in. The working directory is the natural key for that: one repo or checkout is usually one project.

Today the directory only appears by accident. The Claude Code title harvest (~/.cortex/session-metadata.json) falls back to the working directory as a session's title when the transcript has no model-generated one, so some rows show a path in TITLE and others don't. Codex, Bob, OpenCode and Pi sessions show no directory at all.

Proposal

Record each session's working directory and let the viewer group and total by it:

  • A DIR (or PROJECT) column in the Sessions pane, separate from TITLE.
  • A way to group or scope by directory, like the Agents pane does by agent: one row per directory with SESSIONS, LAST SEEN and COST <window>, and ↵ scopes sessions, usage and the $ band to it.
  • The same breakdown in agentop cost, so a monthly total per directory can be scripted.

Open questions:

  • Where does the directory come from per agent? Claude Code records cwd in its transcripts (the title harvest already reads them). Codex records it in its session files. For other agents it may need the process's cwd, looked up from the pid the proxy already attributes calls to.
  • Group by the exact path, or by repository root (so repo/ and repo/sub/ count together)? Worktrees under .claude/worktrees/ probably belong with their repo.
  • A session whose directory changes partway through (cd in a shell agent): first directory, or last?
  • Is the path sensitive enough to keep out of the session API by default? It is already in session-metadata.json for Claude Code.

Context

Requested in #cortex-community by @vinodmut (2026-11-09), who uses the per-session cost to compare models and agents (Codex vs Claude Code) and to account for monthly token use.

Where it lives

  • cmd/agentop/tui/sessions_pane.go, session_metadata.go, sessions_title.go
  • cmd/agentop/cmd_experimental.go (read-claude-sessions harvest)
  • The Agents pane, as the model for a per-directory breakdown
  • cmd/agentop/README.md: the Sessions pane section and the column table

Assisted-By: Claude (Anthropic AI) [email protected]

Sub-issues

Sub-issues

4 of 4 Issues completed
Loading 4 sub-issues

Activity

  1. added
    enhancement
    ux
    on Nov 9, 2026
  2. mrsabath commented on Nov 9, 2026

    @mrsabath
    Member

    Directory is a good grouping key, and this open question turns out to be the visible edge of
    a second problem worth folding in:

    A session whose directory changes partway through (cd in a shell agent): first
    directory, or last?

    From an offline analysis of a 30-day local archive (66 session directories, 29,606 events):
    a single session id can span weeks of unrelated work. The id default recurs across the
    entire 2026-10-15 -> 2026-11-06 range in one archive directory, carrying 152 events from
    many separate working periods. So "66 sessions" is a directory count, not 66 units of work,
    and any per-session total — cost, tokens, latency — silently averages across unrelated
    tasks.

    That means a DIR column inherits the problem rather than solving it: if one session id
    accumulates work from several directories over three weeks, neither "first" nor "last" is
    right, and the monthly per-directory total this issue wants will be wrong in whichever
    direction the tie-break goes.

    The archive already has enough to fix this. Seq's own documentation notes the
    numbering is unique per incarnation and that whole-session eviction restarts it at 1, and
    segments are written per working period with a lastWrite timestamp. A new segment after a
    long idle gap is a natural incarnation boundary — one of these sessions has 34 segments
    spanning three weeks, each one a distinct sitting. Exposing an incarnation/epoch id in
    session.json would give both this issue and per-session analytics a stable key for "one
    contiguous working period," and would make the first-vs-last question mostly moot: an
    incarnation rarely changes directory.

    Not asking to widen this issue — the directory column is useful on its own and shipping it
    should not wait. Just flagging that the grouping will be more trustworthy with an
    incarnation key than without one, and that the tie-break decision can be deferred if the
    unit being grouped is a sitting rather than a session id.

    (Caveat: one developer's archive, Claude-Code-dominated, so the default-id reuse pattern
    may be specific to how these sessions were started.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementux

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions