Claude Code hooks

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

HookAgent
Background processnoneNode daemon (launchd / systemd)
Catches sessions when Claude Code is closedn/areads JSONL on next restart
Offline retry queue❌ (failed POSTs are lost)✅ file-backed FIFO + exponential backoff
Setupone settings.json editnpm install + token + service file
Restart-survival
Network failure resilience
Best fortrusted networks, light usage, quick demoshared/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)

  1. Get an ingest-scope bearer token from the operator (/admin/tokens on the dashboard).

  2. Open ~/.claude/settings.json and 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'"
          }
        ]
      }
    ]
  }
}
  1. Restart your Claude Code session. The next assistant turn pushes.

Heads-up. The hook depends on curl and jq being on $PATH. macOS ships curl; install jq with brew install jq if 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.