Voice
Codestats
OpenClaw plugin: pulse every write/edit tool call to Code::Stats so your AI agent earns you XP.
Install
npm install -g
README
# openclaw-codestats
OpenClaw plugin that turns your AI agent's `write` and `edit` tool calls into [Code::Stats](https://codestats.net) XP pulses. If your agent codes for you, your profile should still light up.
## What it does
- Listens to OpenClaw's `after_tool_call` hook.
- For every `write` and `edit`, calculates "characters changed" and credits XP to the language inferred from the file extension.
- Buffers per-language XP in memory and flushes to `https://codestats.net/api/my/pulses` every 30 seconds (configurable).
- Final flush on `gateway_stop`.
## Requirements
- OpenClaw 2026.5.3 or newer (`api.on("after_tool_call", ...)`).
- A Code::Stats machine API token. Generate one at <https://codestats.net/my/machines>.
- Node.js ≥ 20.
## Install
### From npm (once published)
```bash
npm install -g openclaw-codestats
# or place under any directory listed in plugins.load.paths
```
### Manual
Clone or copy the plugin into a directory OpenClaw scans:
```bash
git clone https://github.com/chchchadzilla/openclaw-codestats.git \
~/.openclaw/plugins/codestats
```
Then point OpenClaw at it (skip if `~/.openclaw/plugins` is already discovered):
```bash
openclaw config set --strict-json plugins.load.paths '["/root/.openclaw/plugins"]'
openclaw config set --strict-json plugins.entries.codestats.enabled true
```
## Configure
Set your Code::Stats token in the gateway environment. With a systemd user service:
```ini
# ~/.config/systemd/user/openclaw-gateway.service.d/env.conf
[Service]
EnvironmentFile=-/root/.openclaw/.env
```
```bash
echo 'CODESTATS_API_TOKEN=YOUR_TOKEN_HERE' >> ~/.openclaw/.env
chmod 600 ~/.openclaw/.env
systemctl --user restart openclaw-gateway
```
Or however you normally feed env vars to your gateway process — the only requirement is that `CODESTATS_API_TOKEN` is visible to it.
### Plugin options
Set under `plugins.entries.codestats.config`:
| Option | Type | Default | Description |
| ----------------- | ------- | ---------------------------------------------- | ------------------------------------------------- |
| `enabled` | boolean | `true` | Master switch. |
| `endpoint` | string | `https://codestats.net/api/my/pulses` | Override for self-hosted Code::Stats instances. |
| `flushIntervalMs` | integer | `30000` | Buffer flush interval. |
| `logXp` | boolean | `false` | Emit per-call buffered/pulsed log lines. |
Example:
```bash
openclaw config set --strict-json plugins.entries.codestats.config.logXp true
openclaw config set --strict-json plugins.entries.codestats.config.flushIntervalMs 15000
```
## Verify
```bash
openclaw plugins inspect codestats --runtime
```
You should see:
```
Status: loaded
Typed hooks: after_tool_call, gateway_stop
```
Then make your agent write a file and (with `logXp=true`) check the gateway log:
```
[codestats] +117 XP JavaScript (buffered)
[codestats] pulsed 117 XP across 1 languages
```
## Caveats
- Only counts tool calls that flow through the **gateway** plugin runtime. If you run the TUI with `--local` (or `openclaw chat`), tool calls happen in the embedded process and won't fire the hook. Use `openclaw tui` (gateway-routed) instead.
- XP estimation is intentionally simple: `write` charges the full content length; `edit` charges `max(oldText.length, newText.length)` per replacement. It's a "reasonable" approximation, not a strict diff.
- Unknown extensions fall back to `Plaintext`. Pull requests welcome to extend the language map.
## License
MIT — see [LICENSE](./LICENSE).
## Credits
Built by [Chad Keith](https://github.com/chchchadzilla) and José (his AI crow 🐦⬛) while wiring Discord into OpenClaw and accidentally inventing this plugin along the way.
voice
Comments
Sign in to leave a comment