cc-teamwork-token-count
A Claude Code plugin that ties each session to a Teamwork task and reports
token spend per task via ccusage.
What it does
SessionStart hook — On every brand-new Claude Code session (skipping
resume/clear/compact), appends one JSON line to ~/.claude/tw-session-log.jsonl
with:
{"session_id":"…","branch":"tw30050746-flex-card-list-view","tw_id":"30050746","cwd":"/path/to/project"}
The tw_id is parsed from the current git branch — branches like
tw12345678-…, TW12345678…, tw_12345678 all work. If the branch doesn't
match, tw_id is null and the row is still recorded.
/tw-token-count slash command — Joins the session log against ccusage
output to produce a per-task report.
/tw-token-count 30050746 # full report for one task
/tw-token-count tw30050746 # 'tw' prefix accepted, case-insensitive
/tw-token-count --list # last 10 logged task IDs
/tw-token-count # same as --list
Single-task report:
Teamwork task tw30050746
───────────────────────────────────────────
Sessions: 3 logged · 2 found in ccusage
First start: 2026-05-11 16:38:49 EDT
Last end: 2026-05-13 16:29:34 EDT
Elapsed: 1d 23h 50m
Cost: $13.3267
Tokens: 12,723,567 total
├─ input: 1,854
├─ output: 119,344
├─ cache create: 701,336
└─ cache read: 11,901,033
Session IDs:
844390be-b5b3-424b-8866-75e9d54cecf9
857afba0-bfd5-4fa4-8b1c-6419d4cdf777
c67ec10e-6eef-47f7-8431-20a414a0a73c
List output (with Teamwork MCP connected and authenticated):
tw30052884 - Translate Drupal with GTranslate Module Security Update - Transbay Project
tw30050746 - Flex card list view component - Acme Site Redesign
…
Without the Teamwork MCP, the list falls back to bare IDs and prints:
Teamwork MCP unavailable — showing IDs only. Connect it to see task titles.
Requirements
- bash — the plugin's scripts use bash; macOS's system bash 3.2 is fine.
- jq — for JSON parsing in the scripts.
- npx — used to fetch
ccusage on demand via npx -y ccusage@latest.
- git — only needed at session start, to read the current branch.
- Teamwork MCP (optional) — enables task/project name enrichment in
--list mode. The slash command auto-detects whether twprojects-get_task
is available and falls back to bare IDs when it isn't.
Install
Via local marketplace (development)
-
Clone this repo somewhere you'll keep it. The plugin layout is already
self-contained.
-
Add a marketplace entry that points at the parent directory containing a
marketplace.json. If your repo is the marketplace root (a single-plugin
marketplace), add a .claude-plugin/marketplace.json listing this plugin
and point the marketplace at the repo root.
-
In ~/.claude/settings.json:
{
"extraKnownMarketplaces": {
"local-plugins": {
"source": { "source": "directory", "path": "/absolute/path/to/marketplace-root" }
}
},
"enabledPlugins": {
"cc-teamwork-token-count@local-plugins": true
}
}
-
Restart Claude Code. The SessionStart hook fires on the next startup; the
slash command is available immediately after restart.
Via a published marketplace
Same shape, swap the directory source for a github source pointing at the
marketplace repo.
Layout
cc-teamwork-token-count/
├── .claude-plugin/
│ └── plugin.json # plugin manifest (name, version, description)
├── hooks/
│ └── hooks.json # SessionStart → bin/tw-session-log.sh
├── bin/
│ ├── tw-session-log.sh # hook script
│ └── tw-token-count # CLI used by the slash command
├── commands/
│ └── tw-token-count.md # /tw-token-count slash command
└── README.md
bin/ is prepended to PATH inside Claude Code sessions, so the slash command
invokes tw-token-count by bare name. Outside Claude Code, the binary isn't
on PATH. To use it from a regular terminal, symlink it:
ln -s /absolute/path/to/cc-teamwork-token-count/bin/tw-token-count ~/.local/bin/tw-token-count
How it works