Track Opencode usage with Wakatime
199
stars
119
commits
TypeScript
primary language
Jul 25, 2026
updated
WakaTime plugin for OpenCode - Track your AI coding activity, lines of code, and time spent.
Inspired by claude-code-wakatime.
[!TIP] Also check out codex-wakatime for OpenAI Codex CLI!
--ai-line-changes for WakaTime AI coding analyticsEnsure you have a WakaTime API key configured in ~/.wakatime.cfg
(or $WAKATIME_HOME/.wakatime.cfg when WAKATIME_HOME is set):
[settings]
api_key = waka_your_api_key_here
You can get your API key from WakaTime Settings.
In case of manual install, the plugin will automatically download wakatime-cli if not found. However, you can also install it yourself:
macOS:
brew install wakatime-cli
Other platforms: Download from WakaTime releases.
opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-wakatime"]
}
npm i -g opencode-wakatime
opencode-wakatime --install
This installs the plugin to ~/.config/opencode/plugin/wakatime.js.
To update, run the same commands again.
git clone https://github.com/angristan/opencode-wakatime
cd opencode-wakatime
npm install && npm run build
node bin/cli.js --install
The plugin will be automatically loaded by OpenCode - no configuration needed.
The plugin hooks into OpenCode's event system:
flowchart TB
subgraph OpenCode["OpenCode"]
A[Tool Execution<br/>read, edit, write, patch, multiedit, batch] --> H1[message.part.updated]
B[Chat Activity] --> H2[chat.message]
C[Session Events<br/>idle, end] --> H3[event]
end
subgraph Plugin["opencode-wakatime Plugin"]
H1 --> P1[Extract File Changes<br/>path, additions, deletions]
P1 --> Q[Heartbeat Queue]
H2 -.->|triggers| P2[Process Queue]
Q --> P2
P2 --> R[Rate Limiter<br/>1 per minute per project]
H3 --> P3[Flush Final<br/>Heartbeat]
P3 --> R
end
subgraph WakaTime["WakaTime"]
R --> CLI[wakatime-cli]
CLI --> API[WakaTime API]
API --> D[Dashboard<br/>AI Coding Metrics]
end
| Hook | Purpose |
|---|---|
event | Tracks tool completions via message.part.updated and session lifecycle |
chat.message | Triggers heartbeat processing on activity |
| Tool | Data Extracted |
|---|---|
read | File path (from title) |
edit | File path, additions, deletions (from filediff) |
write | File path, new file detection |
patch | File paths from output, diff count |
multiedit | File paths and changes from each edit result |
batch | Tracks all child tool operations |
Each heartbeat includes:
additions - deletions)opencode-<client>/<version> opencode-wakatime/<version> (e.g. opencode-desktop/1.1.53 opencode-wakatime/1.1.4)By default, plugin files are stored in ~/.wakatime/.
When WAKATIME_HOME is set, the same files are stored in $WAKATIME_HOME/.
| File | Purpose |
|---|---|
opencode.log | Debug logs (enabled via debug=true in ~/.wakatime.cfg) |
opencode-{hash}.json | Per-project state (last heartbeat timestamp) |
opencode-cli-state.json | CLI version tracking |
opencode-version-cache.json | Cached OpenCode server version |
wakatime-cli-* | Auto-downloaded CLI binary |
# Install dependencies
npm install
# Type check
npm run typecheck
# Build
npm run build
opencode.jsonc)~/.wakatime/opencode.log~/.wakatime.cfgwakatime-cli --version~/.wakatime/opencode.log
(or $WAKATIME_HOME/opencode.log when set)~/.wakatime/
(or $WAKATIME_HOME/ when set)brew install wakatime-cliMIT
TypeScript
94.9%
JavaScript
5.1%
Track Opencode usage with Wakatime
199
stars
119
commits
TypeScript
primary language
Jul 25, 2026
updated
WakaTime plugin for OpenCode - Track your AI coding activity, lines of code, and time spent.
Inspired by claude-code-wakatime.
[!TIP] Also check out codex-wakatime for OpenAI Codex CLI!
--ai-line-changes for WakaTime AI coding analyticsEnsure you have a WakaTime API key configured in ~/.wakatime.cfg
(or $WAKATIME_HOME/.wakatime.cfg when WAKATIME_HOME is set):
[settings]
api_key = waka_your_api_key_here
You can get your API key from WakaTime Settings.
In case of manual install, the plugin will automatically download wakatime-cli if not found. However, you can also install it yourself:
macOS:
brew install wakatime-cli
Other platforms: Download from WakaTime releases.
opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-wakatime"]
}
npm i -g opencode-wakatime
opencode-wakatime --install
This installs the plugin to ~/.config/opencode/plugin/wakatime.js.
To update, run the same commands again.
git clone https://github.com/angristan/opencode-wakatime
cd opencode-wakatime
npm install && npm run build
node bin/cli.js --install
The plugin will be automatically loaded by OpenCode - no configuration needed.
The plugin hooks into OpenCode's event system:
flowchart TB
subgraph OpenCode["OpenCode"]
A[Tool Execution<br/>read, edit, write, patch, multiedit, batch] --> H1[message.part.updated]
B[Chat Activity] --> H2[chat.message]
C[Session Events<br/>idle, end] --> H3[event]
end
subgraph Plugin["opencode-wakatime Plugin"]
H1 --> P1[Extract File Changes<br/>path, additions, deletions]
P1 --> Q[Heartbeat Queue]
H2 -.->|triggers| P2[Process Queue]
Q --> P2
P2 --> R[Rate Limiter<br/>1 per minute per project]
H3 --> P3[Flush Final<br/>Heartbeat]
P3 --> R
end
subgraph WakaTime["WakaTime"]
R --> CLI[wakatime-cli]
CLI --> API[WakaTime API]
API --> D[Dashboard<br/>AI Coding Metrics]
end
| Hook | Purpose |
|---|---|
event | Tracks tool completions via message.part.updated and session lifecycle |
chat.message | Triggers heartbeat processing on activity |
| Tool | Data Extracted |
|---|---|
read | File path (from title) |
edit | File path, additions, deletions (from filediff) |
write | File path, new file detection |
patch | File paths from output, diff count |
multiedit | File paths and changes from each edit result |
batch | Tracks all child tool operations |
Each heartbeat includes:
additions - deletions)opencode-<client>/<version> opencode-wakatime/<version> (e.g. opencode-desktop/1.1.53 opencode-wakatime/1.1.4)By default, plugin files are stored in ~/.wakatime/.
When WAKATIME_HOME is set, the same files are stored in $WAKATIME_HOME/.
| File | Purpose |
|---|---|
opencode.log | Debug logs (enabled via debug=true in ~/.wakatime.cfg) |
opencode-{hash}.json | Per-project state (last heartbeat timestamp) |
opencode-cli-state.json | CLI version tracking |
opencode-version-cache.json | Cached OpenCode server version |
wakatime-cli-* | Auto-downloaded CLI binary |
# Install dependencies
npm install
# Type check
npm run typecheck
# Build
npm run build
opencode.jsonc)~/.wakatime/opencode.log~/.wakatime.cfgwakatime-cli --version~/.wakatime/opencode.log
(or $WAKATIME_HOME/opencode.log when set)~/.wakatime/
(or $WAKATIME_HOME/ when set)brew install wakatime-cliMIT
TypeScript
94.9%
JavaScript
5.1%