Skip to content

Commit 7e20024

Browse files
authored
feat(qwen): add Qwen usage adapter (#1030)
* feat(qwen): add Qwen usage adapter Add a Qwen adapter for local chat JSONL files under QWEN_DATA_DIR, including path discovery, parsing, LiteLLM pricing candidates, focused commands, all-source detection, docs, schema, and CLI output coverage. Qwen exposes reasoning tokens separately from ordinary candidate output, so table rendering now accepts adapter-provided totalTokens instead of recomputing totals from visible token columns. * fix(qwen): align config schema and chat discovery * test(qwen): cover existing schema namespaces * refactor(config): clarify agent label selection Replace the inline agent label conditional in the schema generator with a small exhaustive switch helper. This keeps future agent-specific labels out of nested ternaries and makes the config schema label rules easier to extend. * chore: restore claude skill links Keep the Qwen Rust adapter PR focused by reverting local pre-commit sync changes to .claude/skills that are unrelated to this adapter port. * chore(schema): format generated config schema Keep the generated config schema formatting in sync with the pre-commit generator after merging origin/main into the Qwen adapter branch. * chore(schema): format generated config schema * fix(qwen): address review edge cases * docs(qwen): include qwen in env debug grep Add QWEN to the environment-variable troubleshooting grep example so the documented debug command finds QWEN_DATA_DIR. Include KIMI as well because latest main now adds that data source to the same table. * test(qwen): restore config schema property expectation Fix the merged Qwen branch test expectation so the generated root config schema is compared against the complete property set from latest main plus qwen. The previous conflict resolution kept only the continuation line, which made the full Rust test suite fail in CI. * chore(schema): format generated config schema * fix(qwen): normalize session date filters Normalize since/until bounds before comparing Qwen session summaries so ISO date inputs compare against the YYYYMMDD row key consistently. Adds a regression test for filtering Qwen session rows with matching ISO date bounds. * fix(output): remove duplicate total token local Remove the unused duplicate total_tokens binding exposed by the latest main merge so clippy passes with -D warnings.
1 parent 2cc4dfe commit 7e20024

27 files changed

Lines changed: 935 additions & 22 deletions

‎apps/ccusage/README.md‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
2525
## Supported Sources
2626

27-
The main CLI tool for analyzing Claude Code, Codex, OpenCode, Amp, Droid, Codebuff, Hermes Agent, pi-agent, Goose, OpenClaw, Kilo, Kimi, GitHub Copilot CLI, and Gemini CLI usage from local data. Track daily, weekly, monthly, and session-based usage with beautiful tables.
27+
The main CLI tool for analyzing Claude Code, Codex, OpenCode, Amp, Droid, Codebuff, Hermes Agent, pi-agent, Goose, OpenClaw, Kilo, Kimi, Qwen, GitHub Copilot CLI, and Gemini CLI usage from local data. Track daily, weekly, monthly, and session-based usage with beautiful tables.
2828

2929
## Installation
3030

@@ -75,6 +75,7 @@ bunx ccusage goose daily
7575
bunx ccusage openclaw daily
7676
bunx ccusage kilo daily
7777
bunx ccusage kimi daily
78+
bunx ccusage qwen daily
7879
bunx ccusage copilot daily
7980
bunx ccusage gemini daily
8081
bunx ccusage pi daily --pi-path /path/to/sessions
@@ -103,7 +104,7 @@ bunx ccusage monthly --compact # Compact monthly report
103104
- 📊 **Daily Report**: View token usage and costs aggregated by date
104105
- 📅 **Monthly Report**: View token usage and costs aggregated by month
105106
- 💬 **Session Report**: View usage grouped by conversation sessions
106-
- 🤖 **Unified CLI Reports**: View Claude Code, Codex, OpenCode, Amp, Droid, Codebuff, Hermes Agent, pi-agent, Goose, OpenClaw, Kilo, Kimi, GitHub Copilot CLI, and Gemini CLI usage from one CLI
107+
- 🤖 **Unified CLI Reports**: View Claude Code, Codex, OpenCode, Amp, Droid, Codebuff, Hermes Agent, pi-agent, Goose, OpenClaw, Kilo, Kimi, Qwen, GitHub Copilot CLI, and Gemini CLI usage from one CLI
107108
- ⏰ **5-Hour Blocks Report**: Track usage within Claude's billing windows with active block monitoring
108109
- 🚀 **Statusline Integration**: Compact usage display for Claude Code status bar hooks (Beta)
109110
- 🤖 **Model Tracking**: See which models are used across supported sources

‎apps/ccusage/config-schema.json‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,33 @@
11731173
},
11741174
"type": "object"
11751175
},
1176+
"QwenCommandsConfig": {
1177+
"additionalProperties": false,
1178+
"properties": {
1179+
"daily": {
1180+
"$ref": "#/definitions/SharedOptions"
1181+
},
1182+
"monthly": {
1183+
"$ref": "#/definitions/SharedOptions"
1184+
},
1185+
"session": {
1186+
"$ref": "#/definitions/SharedOptions"
1187+
}
1188+
},
1189+
"type": "object"
1190+
},
1191+
"QwenConfig": {
1192+
"additionalProperties": false,
1193+
"properties": {
1194+
"commands": {
1195+
"$ref": "#/definitions/QwenCommandsConfig"
1196+
},
1197+
"defaults": {
1198+
"$ref": "#/definitions/SharedOptions"
1199+
}
1200+
},
1201+
"type": "object"
1202+
},
11761203
"RootCommandsConfig": {
11771204
"additionalProperties": false,
11781205
"properties": {
@@ -1655,6 +1682,15 @@
16551682
],
16561683
"description": "pi-agent configuration.",
16571684
"markdownDescription": "pi-agent configuration."
1685+
},
1686+
"qwen": {
1687+
"allOf": [
1688+
{
1689+
"$ref": "#/definitions/QwenConfig"
1690+
}
1691+
],
1692+
"description": "Qwen configuration.",
1693+
"markdownDescription": "Qwen configuration."
16581694
}
16591695
},
16601696
"type": "object"

‎docs/.vitepress/config.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ export default defineConfig({
7878
{ text: 'pi-agent', link: '/guide/pi/' },
7979
{ text: 'Goose', link: '/guide/goose/' },
8080
{ text: 'Kilo', link: '/guide/kilo/' },
81+
{ text: 'Qwen', link: '/guide/qwen/' },
8182
{ text: 'GitHub Copilot CLI', link: '/guide/copilot/' },
8283
{ text: 'Gemini CLI', link: '/guide/gemini/' },
8384
{ text: 'Kimi', link: '/guide/kimi/' },

‎docs/guide/all-reports.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ ccusage daily --all
2525

2626
## How Unified Views Work
2727

28-
ccusage detects local usage files from Claude Code, Codex, OpenCode, Amp, Droid, Codebuff, Hermes Agent, pi-agent, Goose, OpenClaw, Kilo, Kimi, GitHub Copilot CLI, and Gemini CLI. The same daily, weekly, monthly, and session views can run in two modes:
28+
ccusage detects local usage files from Claude Code, Codex, OpenCode, Amp, Droid, Codebuff, Hermes Agent, pi-agent, Goose, OpenClaw, Kilo, Kimi, Qwen, GitHub Copilot CLI, and Gemini CLI. The same daily, weekly, monthly, and session views can run in two modes:
2929

3030
| Mode | Command example | What it shows |
3131
| ------- | ---------------------- | --------------------------------------- |
@@ -51,6 +51,7 @@ Unified tables include an **Agent** column so you can compare sources in one vie
5151
| OpenClaw | `openclaw` | `ccusage openclaw daily` |
5252
| Kilo | `kilo` | `ccusage kilo daily` |
5353
| Kimi | `kimi` | `ccusage kimi daily` |
54+
| Qwen | `qwen` | `ccusage qwen daily` |
5455
| Copilot CLI | `copilot` | `ccusage copilot daily` |
5556
| Gemini CLI | `gemini` | `ccusage gemini daily` |
5657

@@ -68,6 +69,7 @@ ccusage codebuff daily
6869
ccusage pi session --pi-path /path/to/sessions
6970
ccusage openclaw daily --open-claw-path /path/to/openclaw
7071
ccusage kilo session
72+
ccusage qwen daily
7173
ccusage copilot daily --json
7274
ccusage gemini session --json
7375
```

‎docs/guide/claude/index.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Claude Code Data Source
22

3-
ccusage can read Claude Code usage data as one of its supported local data sources. Claude Code is no longer treated as the only ccusage target; it uses the same unified and focused report model as Codex, OpenCode, Amp, Droid, Codebuff, pi-agent, Kilo, Kimi, GitHub Copilot CLI, and Gemini CLI.
3+
ccusage can read Claude Code usage data as one of its supported local data sources. Claude Code is no longer treated as the only ccusage target; it uses the same unified and focused report model as Codex, OpenCode, Amp, Droid, Codebuff, Hermes Agent, pi-agent, Goose, OpenClaw, Kilo, Kimi, Qwen, GitHub Copilot CLI, and Gemini CLI.
44

55
## Focused Views
66

@@ -75,7 +75,7 @@ export CLAUDE_CONFIG_DIR="~/.config/claude,/backup/claude-archive"
7575
ccusage claude monthly
7676
```
7777

78-
For Codex, OpenCode, Amp, Droid, Codebuff, pi-agent, Kilo, Kimi, GitHub Copilot CLI, and Gemini CLI data locations, use the source-specific environment variables listed in [Environment Variables](/guide/environment-variables).
78+
For Codex, OpenCode, Amp, Droid, Codebuff, Hermes Agent, pi-agent, Goose, OpenClaw, Kilo, Kimi, Qwen, GitHub Copilot CLI, and Gemini CLI data locations, use the source-specific environment variables listed in [Environment Variables](/guide/environment-variables).
7979

8080
### Directory Detection
8181

‎docs/guide/codex/index.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
> ⚠️ Codex log support is experimental while the Codex CLI log format continues to evolve.
66
7-
ccusage can read OpenAI Codex CLI session logs as one of its supported local data sources. Codex uses the same unified and focused report model as Claude Code, OpenCode, Amp, Droid, Codebuff, pi-agent, Kilo, Kimi, GitHub Copilot CLI, and Gemini CLI.
7+
ccusage can read OpenAI Codex CLI session logs as one of its supported local data sources. Codex uses the same unified and focused report model as Claude Code, OpenCode, Amp, Droid, Codebuff, Hermes Agent, pi-agent, Goose, OpenClaw, Kilo, Kimi, Qwen, GitHub Copilot CLI, and Gemini CLI.
88

99
## Focused Views
1010

‎docs/guide/config-files.md‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ Override shared defaults for specific unified reports and legacy Claude commands
176176

177177
### Source-Specific Configuration
178178

179-
Use data source namespaces to set defaults and report overrides. Supported namespaces are `claude`, `codex`, `opencode`, `amp`, `droid`, `codebuff`, `hermes`, `pi`, `goose`, `openclaw`, `kilo`, `kimi`, `copilot`, and `gemini`.
179+
Use data source namespaces to set defaults and report overrides. Supported namespaces are `claude`, `codex`, `opencode`, `amp`, `droid`, `codebuff`, `hermes`, `pi`, `goose`, `openclaw`, `kilo`, `kimi`, `qwen`, `copilot`, and `gemini`.
180180

181181
```json
182182
{
@@ -236,6 +236,11 @@ Use data source namespaces to set defaults and report overrides. Supported names
236236
"offline": true
237237
}
238238
},
239+
"qwen": {
240+
"defaults": {
241+
"offline": true
242+
}
243+
},
239244
"copilot": {
240245
"defaults": {
241246
"offline": true
@@ -260,6 +265,7 @@ ccusage pi daily
260265
ccusage openclaw daily
261266
ccusage kilo daily
262267
ccusage kimi daily
268+
ccusage qwen daily
263269
ccusage copilot monthly
264270
ccusage gemini daily
265271
```

‎docs/guide/configuration.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ For individual developers working on multiple projects:
109109

110110
### Multiple Sources
111111

112-
Configure Claude Code, Codex, OpenCode, Amp, Droid, Codebuff, Hermes Agent, pi-agent, Goose, OpenClaw, Kilo, Kimi, GitHub Copilot CLI, and Gemini CLI separately with data source namespaces:
112+
Configure Claude Code, Codex, OpenCode, Amp, Droid, Codebuff, Hermes Agent, pi-agent, Goose, OpenClaw, Kilo, Kimi, Qwen, GitHub Copilot CLI, and Gemini CLI separately with data source namespaces:
113113

114114
```json
115115
// ~/.config/claude/ccusage.json

‎docs/guide/daily-reports.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ ccusage codex daily
1818
ccusage opencode daily
1919
ccusage amp daily
2020
ccusage pi daily
21+
ccusage qwen daily
2122
```
2223

2324
The daily command is the default, so you can omit it when running ccusage.

‎docs/guide/environment-variables.md‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ ccusage detects supported data source files from conventional locations by defau
2020
| `OPENCLAW_DIR` | OpenClaw | `~/.openclaw` |
2121
| `KILO_DATA_DIR` | Kilo | `~/.local/share/kilo` |
2222
| `KIMI_DATA_DIR` | Kimi | `~/.kimi` |
23+
| `QWEN_DATA_DIR` | Qwen | `~/.qwen` |
2324
| `COPILOT_OTEL_FILE_EXPORTER_PATH` | Copilot CLI | Explicit `.jsonl` file |
2425
| `GEMINI_DATA_DIR` | Gemini CLI | `~/.gemini/tmp` |
2526

@@ -37,6 +38,7 @@ export GOOSE_PATH_ROOT="/path/to/goose,/archive/goose"
3738
export OPENCLAW_DIR="/path/to/openclaw,/archive/openclaw"
3839
export KILO_DATA_DIR="/path/to/kilo,/archive/kilo"
3940
export KIMI_DATA_DIR="/path/to/kimi,/archive/kimi"
41+
export QWEN_DATA_DIR="/path/to/qwen,/archive/qwen"
4042
export COPILOT_OTEL_FILE_EXPORTER_PATH="/path/to/copilot-otel.jsonl"
4143
export GEMINI_DATA_DIR="/path/to/gemini/tmp,/archive/gemini/tmp"
4244
ccusage daily
@@ -208,7 +210,7 @@ To see which environment variables are being used:
208210

209211
```bash
210212
# Show all environment variables
211-
env | grep -E "CLAUDE|CODEX|OPENCODE|AMP|DROID|CODEBUFF|HERMES|PI_AGENT|GOOSE|OPENCLAW|KILO|KIMI|COPILOT|GEMINI|CCUSAGE|LOG_LEVEL"
213+
env | grep -E "CLAUDE|CODEX|OPENCODE|AMP|DROID|CODEBUFF|HERMES|PI_AGENT|GOOSE|OPENCLAW|KILO|KIMI|QWEN|COPILOT|GEMINI|CCUSAGE|LOG_LEVEL"
212214

213215
# Debug mode shows environment variable usage
214216
LOG_LEVEL=4 ccusage daily --debug

0 commit comments

Comments
 (0)