Skip to content

Include archived Codex sessions in usage reports #1177

@yashau

Description

@yashau

What do you want to change?

Make ccusage codex include archived Codex sessions by default when CODEX_HOME points to a Codex home.

Today the Rust adapter reads ~/.codex/sessions, but not ~/.codex/archived_sessions. I would like Codex home discovery to include both directories, while preserving the current behavior where a direct JSONL directory can still be used for saved codex exec --json output.

I opened an implementation PR at #1176, but it was auto-closed by the contributor gate.

Why?

Archived Codex sessions are still part of local usage history. Ignoring them makes token and cost reports look much lower than the real local history for users who archive conversations.

On my machine, the difference is large:

  • active sessions/: 18 JSONL files, about 289M total tokens
  • active + archived_sessions/: 51 JSONL files, about 1.66B total tokens

So the current default undercounts my Codex usage by excluding archived sessions.

How? (optional)

The implementation in #1176 does this in the Rust adapter:

  • Treat entries with sessions/ or archived_sessions/ as Codex homes.
  • Read both directories by default for Codex homes.
  • Keep direct JSONL directory behavior unchanged.
  • Deduplicate by relative JSONL path before parsing, with the active sessions/ copy winning over an archived copy.
  • Use the same discovery behavior in both the event loader and aggregate streaming path.

Validation from the PR branch:

  • cargo test --manifest-path rust/Cargo.toml --workspace codex -- --nocapture
  • cargo check --manifest-path rust/Cargo.toml --workspace
  • git diff --check

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions