Claude Code hooks
Lightweight alternative to the standalone @wigtoken-temp/agent. One block in ~/.claude/settings.json and every Claude Code session you run on that machine streams its messages into your wigtoken server.
Hook vs agent
| Hook | Agent | |
|---|---|---|
| Background process | none | Node daemon (launchd / systemd) |
| Catches sessions when Claude Code is closed | n/a | reads JSONL on next restart |
| Offline retry queue | ❌ (failed POSTs are lost) | ✅ file-backed FIFO + exponential backoff |
| Setup | one settings.json edit | npm install + token + service file |
| Restart-survival | ✅ | ✅ |
| Network failure resilience | ❌ | ✅ |
| Best for | trusted networks, light usage, quick demo | shared/public networks, heavy usage |
If you’re sometimes on a flaky network and don’t want to lose data, use the agent. If you just want to see numbers flow in 30 seconds, use the hook.
Setup (~30 seconds)
-
Get an
ingest-scope bearer token from the operator (/admin/tokenson the dashboard). -
Open
~/.claude/settings.jsonand merge in:
{
"hooks": {
"PostToolUse": [
{
"matcher": "*",
"hooks": [
{
"type": "command",
"command": "WIGTOKEN_SERVER='https://your-wigtoken' WIGTOKEN_TOKEN='wti_…' WIGTOKEN_MACHINE=\"$(hostname)\" /usr/bin/env bash -c 'curl -sS -X POST \"$WIGTOKEN_SERVER/api/ingest/messages\" -H \"Authorization: Bearer $WIGTOKEN_TOKEN\" -H \"Content-Type: application/json\" -d \"$(jq -nc --arg m \"$WIGTOKEN_MACHINE\" --rawfile s /dev/stdin \\'{machine:$m, messages: ($s | split(\"\\n\") | map(select(length>0) | fromjson) | map(select(.type==\"assistant\") | .message) | map({message_id:.id, model:.model, input_tokens:.usage.input_tokens, cache_creation_input_tokens:.usage.cache_creation_input_tokens, cache_read_input_tokens:.usage.cache_read_input_tokens, output_tokens:.usage.output_tokens, ts:now}))}\\')\" > /dev/null'"
}
]
}
]
}
}- Restart your Claude Code session. The next assistant turn pushes.
Heads-up. The hook depends on
curlandjqbeing on$PATH. macOS ships curl; install jq withbrew install jqif needed.
Verify
curl https://your-wigtoken/api/usage/recent?limit=1 \
-H "Authorization: Bearer $WIGTOKEN_TOKEN" | jq .You should see your last assistant turn with the right machine label.
Limitations
- One request per turn (no batching).
- No retry — if the server is briefly down, you lose those messages.
- Hook runs synchronously inside Claude Code; a slow server adds latency to every turn. Keep network paths fast.