Skip to content

Add Cowork usage source#1199

Closed
tsergeytovarov wants to merge 16 commits into
ryoppippi:mainfrom
tsergeytovarov:feat/cowork-usage-source
Closed

Add Cowork usage source#1199
tsergeytovarov wants to merge 16 commits into
ryoppippi:mainfrom
tsergeytovarov:feat/cowork-usage-source

Conversation

@tsergeytovarov
Copy link
Copy Markdown

@tsergeytovarov tsergeytovarov commented Jun 1, 2026

TL;DR

Adds Cowork as a separate usage source for Claude Desktop local agent mode sessions.
Cowork stores Claude-compatible .claude/projects/**/*.jsonl data under local-agent-mode-sessions, so ccusage can parse it with the existing Claude usage model while keeping it distinct from Claude Code.

What changed

  • Added the cowork CLI source with focused reports for daily, monthly, and session.
  • Added Cowork discovery for ~/Library/Application Support/Claude/local-agent-mode-sessions and a guarded COWORK_CONFIG_DIR override.
  • Reused Claude-compatible usage loaders for Cowork JSONL entries, including token usage, cost calculation, and deduplication.
  • Included Cowork rows in unified all-agent reports with explicit source metadata and labels.
  • Updated config schema, source docs, guide navigation, and README coverage for Cowork.
  • Fixed the Nix pre-push hook entry for renovate-config-validator, so the generated hook calls the validator binary directly.

Why

Claude Desktop Cowork local agent mode stores sessions locally, but ccusage previously only picked up Claude Code and other coding CLI sources. This adds support for that local Cowork data without merging it into Claude Code totals, so users can inspect Cowork separately or include it in unified reports.

How tested

  • cargo test --manifest-path rust/Cargo.toml --workspace
  • cargo clippy --manifest-path rust/Cargo.toml --workspace --all-targets -- -D warnings
  • cargo fmt --all --manifest-path rust/Cargo.toml --check
  • TZ=UTC node_modules/.bin/vitest run
  • vitepress build
  • nix develop --command pnpm run lint:oxfmt
  • nix develop --command pnpm run lint:oxlint
  • nix develop --command pnpm typecheck
  • Pre-push hook via nix develop --command git push ...: clippy, oxlint, treefmt, gitleaks, renovate-config-validator, cargo test, and vitest related passed.
  • Runtime checks against local Cowork data for cowork daily, cowork monthly, cowork session, unified daily, and guarded COWORK_CONFIG_DIR failure behavior.

Checklist

  • Tests pass
  • Linter passes
  • Documentation updated
  • Config schema updated

Summary by cubic

Adds Cowork as a separate usage source for Claude Desktop local agent sessions, with focused reports and inclusion in unified views. Users can now analyze Cowork separately from Claude Code.

  • New Features

    • Added cowork CLI namespace with daily, monthly, and session reports (e.g., ccusage cowork daily).
    • Auto-discovers data at ~/Library/Application Support/Claude/local-agent-mode-sessions; supports a comma‑separated COWORK_CONFIG_DIR override with guarded behavior.
    • Reuses Claude-compatible loaders for JSONL parsing, token/cost calc, and dedupe; Cowork stays distinct from Claude Code in all reports.
    • Unified “all” reports include Cowork with proper labels and ordering; updated config schema and docs, including a new Cowork guide.
  • Bug Fixes

    • Nix pre-push hook: invoke renovate-config-validator directly to run the validator reliably.

Written for commit 24e5f3e. Summary will update on new commits.

Review in cubic

Summary by CodeRabbit

  • New Features

    • Added Cowork data source with ccusage cowork daily, monthly, and session report commands
    • Introduced COWORK_CONFIG_DIR environment variable to customize Cowork data discovery paths
  • Documentation

    • Added comprehensive Cowork guide with setup and troubleshooting
    • Updated all existing guides to include Cowork examples and configuration options

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jun 1, 2026

This PR was auto-closed. Only contributors approved with lgtm can open PRs. Open an issue first.

Maintainers review auto-closed issues and reopen worthwhile ones. Issues that do not meet the quality bar in CONTRIBUTING.md may not be reopened or receive a reply.

If a maintainer replies lgtmi, your future issues will stay open. If a maintainer replies lgtm, your future issues and PRs will stay open.

See CONTRIBUTING.md.

@github-actions github-actions Bot closed this Jun 1, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jun 1, 2026

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b82f77cb-d626-4dcc-a21f-e6eba6ccbf5b

📥 Commits

Reviewing files that changed from the base of the PR and between 1f2bcd5 and 24e5f3e.

⛔ Files ignored due to path filters (1)
  • rust/crates/ccusage/src/snapshots/ccusage__config_schema__tests__snapshots_schema_agent_specific_option_edges.snap is excluded by !**/*.snap
📒 Files selected for processing (39)
  • apps/ccusage/README.md
  • apps/ccusage/config-schema.json
  • docs/.vitepress/config.ts
  • docs/guide/all-reports.md
  • docs/guide/claude/index.md
  • docs/guide/codex/index.md
  • docs/guide/config-files.md
  • docs/guide/configuration.md
  • docs/guide/cowork/index.md
  • docs/guide/daily-reports.md
  • docs/guide/environment-variables.md
  • docs/guide/gemini/index.md
  • docs/guide/getting-started.md
  • docs/guide/index.md
  • docs/guide/kimi/index.md
  • docs/guide/monthly-reports.md
  • docs/guide/session-reports.md
  • docs/index.md
  • docs/superpowers/plans/2026-06-01-cowork-usage-source.md
  • docs/superpowers/specs/2026-06-01-cowork-usage-source-design.md
  • nix/git-hooks.nix
  • rust/crates/ccusage-cli/src/parser.rs
  • rust/crates/ccusage-cli/src/tests.rs
  • rust/crates/ccusage-cli/src/types.rs
  • rust/crates/ccusage/src/adapter/all/loader.rs
  • rust/crates/ccusage/src/adapter/all/report.rs
  • rust/crates/ccusage/src/adapter/all/tests.rs
  • rust/crates/ccusage/src/adapter/all/types.rs
  • rust/crates/ccusage/src/adapter/claude/daily.rs
  • rust/crates/ccusage/src/adapter/claude/mod.rs
  • rust/crates/ccusage/src/adapter/claude/paths.rs
  • rust/crates/ccusage/src/adapter/cowork/README.md
  • rust/crates/ccusage/src/adapter/cowork/mod.rs
  • rust/crates/ccusage/src/adapter/cowork/paths.rs
  • rust/crates/ccusage/src/adapter/mod.rs
  • rust/crates/ccusage/src/config.rs
  • rust/crates/ccusage/src/config_schema.rs
  • rust/crates/ccusage/src/main.rs
  • rust/crates/ccusage/src/progress.rs

📝 Walkthrough

Walkthrough

This PR introduces Cowork (Claude Desktop local-agent-mode sessions) as a new data source in ccusage. The changes extend the CLI parser to recognize cowork commands, refactor Claude's path-based loading to be reusable, implement a new Cowork adapter with recursive path discovery and COWORK_CONFIG_DIR override support, integrate Cowork into all-agent aggregation with deterministic ordering, and update documentation and configuration schemas throughout.

Changes

Cowork Agent Support

Layer / File(s) Summary
CLI Parser & Command Types
rust/crates/ccusage-cli/src/parser.rs, rust/crates/ccusage-cli/src/types.rs, rust/crates/ccusage-cli/src/tests.rs, rust/crates/ccusage/src/config.rs
parse_command routes cowork to basic agent parsing; Command enum adds Cowork(AgentCommandArgs) variant; is_agent_command, agent_report_supported, and agent_display_name updated to recognize cowork with daily/monthly/session support; legacy cowork:report syntax parsing tests added.
Claude Adapter Path Extraction
rust/crates/ccusage/src/adapter/claude/paths.rs, rust/crates/ccusage/src/adapter/claude/daily.rs, rust/crates/ccusage/src/adapter/claude/mod.rs, rust/crates/ccusage/src/main.rs
Exposes normalize_claude_config_path and expand_home_path as pub(crate); refactors daily loader to accept explicit paths: &[PathBuf] via load_daily_summaries_from_paths; adds load_entries_from_paths wrapper in mod.rs; test verifies explicit-path loading from multiple config directories.
Cowork Adapter Implementation
rust/crates/ccusage/src/adapter/cowork/paths.rs, rust/crates/ccusage/src/adapter/cowork/mod.rs, rust/crates/ccusage/src/adapter/cowork/README.md, rust/crates/ccusage/src/adapter/mod.rs
New cowork_paths() discovers local-agent-mode sessions from COWORK_CONFIG_DIR (comma-separated) or default ~/Library/Application Support/.../local-agent-mode-sessions, with recursive .claude/projects/ handling and deduplication; cowork/mod.rs implements daily/monthly/session loading and report generation; adapter README documents discovery and commands.
Cowork Module Registration & Progress Tracking
rust/crates/ccusage/src/adapter/mod.rs, rust/crates/ccusage/src/progress.rs, rust/crates/ccusage/src/main.rs
Registers pub(crate) mod cowork in adapter registry; adds UsageLoadAgent::Cowork variant and agent_label mapping; main.rs routes Command::Cowork to adapter::cowork::run().
All-Agent Aggregation & Deterministic Ordering
rust/crates/ccusage/src/adapter/all/types.rs, rust/crates/ccusage/src/adapter/all/loader.rs, rust/crates/ccusage/src/adapter/all/report.rs, rust/crates/ccusage/src/adapter/all/tests.rs
Introduces AGENT_ORDER list and compare_agents() helper for fixed agent ordering (Claude, Cowork, Codex, etc.); load_rows adds cowork loading via load_cowork_rows with session/daily handling; aggregator sorts breakdowns and metadata_agents using custom ordering; report labels detected agents deterministically; tests verify multi-agent aggregation and cowork-specific metadata (projectPath, lastActivity).
Configuration Schema for Cowork
rust/crates/ccusage/src/config_schema.rs, apps/ccusage/config-schema.json
Adds CoworkConfig and CoworkCommandsConfig types to Rust schema with commands (daily/monthly/session) and defaults; schema tests verify cowork options are properly exposed/restricted; generated JSON schema includes 446 lines of cowork command/option definitions.
User Documentation & Examples
apps/ccusage/README.md, docs/guide/*.md, docs/index.md, docs/.vitepress/config.ts, docs/superpowers/*
README adds Cowork to supported-sources table and usage examples; configuration guides include cowork namespace examples; environment-variables docs add COWORK_CONFIG_DIR; daily/monthly/session guides add cowork command examples; new docs/guide/cowork/index.md documents discovery, setup, and commands; getting-started adds Cowork to next steps; superpowers plans/specs provide implementation details.

Estimated Code Review Effort

🎯 4 (Complex) | ⏱️ ~60 minutes

Possibly Related PRs

  • ryoppippi/ccusage#1148: Overlaps in all-agent accumulator ordering logic (all/types.rs) where both PRs modify agent breakdown sorting.
  • ryoppippi/ccusage#1062: Claude adapter refactor depends on usage_files signature and project-filter discovery changed in this PR.
  • ryoppippi/ccusage#1137: Main PR builds on adapter-all refactoring by adding Cowork-specific loading and labeling.

Suggested Reviewers

  • ryoppippi
  • ubugeeei

🐰 A new source hops into the warren,
Cowork sessions bundled in nested fashion,
Paths discovered, sorted with passion,
All-agent views now more in spartan!

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 40 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="rust/crates/ccusage/src/adapter/all/loader.rs">

<violation number="1" location="rust/crates/ccusage/src/adapter/all/loader.rs:407">
P2: New Cowork loader duplicates Claude loader logic, increasing drift risk. Extract a shared helper for daily summary + session capable loading, following the existing `load_summary_agent_rows`/`load_session_capable_summary_agent_rows` pattern in the file.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

})
}

fn load_cowork_rows(kind: AgentReportKind, shared: &SharedArgs) -> Result<AgentRows> {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2: New Cowork loader duplicates Claude loader logic, increasing drift risk. Extract a shared helper for daily summary + session capable loading, following the existing load_summary_agent_rows/load_session_capable_summary_agent_rows pattern in the file.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At rust/crates/ccusage/src/adapter/all/loader.rs, line 407:

<comment>New Cowork loader duplicates Claude loader logic, increasing drift risk. Extract a shared helper for daily summary + session capable loading, following the existing `load_summary_agent_rows`/`load_session_capable_summary_agent_rows` pattern in the file.</comment>

<file context>
@@ -398,6 +404,26 @@ fn load_claude_rows(kind: AgentReportKind, shared: &SharedArgs) -> Result<AgentR
     })
 }
 
+fn load_cowork_rows(kind: AgentReportKind, shared: &SharedArgs) -> Result<AgentRows> {
+    if kind == AgentReportKind::Session {
+        return load_session_capable_summary_agent_rows(
</file context>

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant