npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@tekdi/coding-analytics

v1.0.1

Published

Monitor Cursor & Claude Code usage and send analytics to PostHog. Uses hooks to capture events.

Readme

@tekdi/coding-analytics

Monitor Cursor and Claude Code usage in real-time and send analytics to PostHog for team-wide insights and pattern detection.

🎯 What It Does

Hooks into Cursor and Claude Code on each developer's machine to capture:

  • Cursor: chat sessions, messages, code edits, token usage, agent thinking
  • Claude Code: prompts submitted, tool usage, session start/stop, subagent activity
  • Git context: repository, branch, last commit, dirty status
  • System metadata: OS, Cursor version, Node version
  • User identity: resolved from Claude account UUID → Cursor cached email → git config

Events are written to a local queue and flushed to PostHog every 5 minutes by a cron job, so hooks never block your editor.


🚀 Quick Start

Installation

Mac/Linux:

curl -fsSL https://raw.githubusercontent.com/tekdi/coding-analytics/main/install-scripts/install.sh | bash

Windows (PowerShell as Administrator):

Invoke-WebRequest -Uri https://raw.githubusercontent.com/tekdi/coding-analytics/main/install-scripts/install.ps1 -OutFile install.ps1
.\install.ps1

Manual installation:

npm install -g @tekdi/coding-analytics

# Configure PostHog
coding-analytics config --posthog-key="phc_your_key_here"
coding-analytics config --posthog-host="https://eu.i.posthog.com"

# Install hooks for both providers (also sets up the flush cron)
coding-analytics install-hooks

Verification

coding-analytics status

Expected output:

=== Coding Analytics Status ===

Overall: ✓ healthy

Hooks & Infrastructure:
  Cursor Hooks:    ✓ Installed
  Claude Hooks:    ✓ Installed
  Flush Cron:      ✓ Installed (every 5 min)
  Queue:           0 event(s) pending

Backend:
  PostHog:         ✓ Connected
  Local Storage:   ✓ OK
  Last Event:      2026-03-26T10:30:00Z

Auth IDs:
  Claude:          44c72054-****-****-****-a9743dc0d9bb
  Cursor:          a*****@yourorg.com

📊 Events Captured

Cursor Events

| PostHog Event | Trigger | |---|---| | cursor_chat_started | New chat opened | | cursor_message_sent | User sends a message | | cursor_message_received | AI responds | | cursor_code_edited | Files changed via AI | | cursor_chat_ended | Chat session closed | | cursor_agent_thinking | Agent reasoning (if available) |

Claude Code Events

| PostHog Event | Trigger | |---|---| | claude_session_started | Claude Code session begins | | claude_prompt_submitted | User submits a prompt | | claude_tool_used | Any tool call completes (Bash, Edit, Read, etc.) | | claude_subagent_started | Subagent spawned | | claude_subagent_stopped | Subagent completes | | claude_session_stopped | Session ends |

Enriched Context on Every Event

  • Git: repository, branch, last commit hash, dirty/clean status, modified file count
  • System: OS, Cursor version, Node version, machine ID
  • User: Claude account UUID (preferred) → Cursor cached email → hashed git email
  • Provider: cursor or claude tag on every event

⚙️ Configuration

Location: ~/.coding-analytics/config.json

coding-analytics config --edit    # open in $EDITOR
coding-analytics config --show    # print current config
{
  "posthog": {
    "apiKey": "phc_your_key",
    "host": "https://eu.i.posthog.com",
    "batchSize": 100,
    "flushInterval": 5000
  },

  "capture": {
    "prompts": true,
    "responses": false,
    "fileContent": false,
    "filePaths": true,
    "agentThinking": true
  },

  "privacy": {
    "hashUserIds": true,
    "redactSecrets": true,
    "allowedRepos": [
      "github.com/tekdi/*"
    ]
  },

  "storage": {
    "fallbackToLocal": true,
    "localDbPath": "~/.coding-analytics/events.json",
    "retryFailedEvents": true,
    "maxRetries": 3
  }
}

🔒 Privacy & Security

Captured by default

  • Event types and metadata (timestamps, token counts, line counts)
  • File paths and types
  • Git context (repo name, branch)
  • Hashed or opaque user IDs

Not captured by default

  • AI response content
  • File diffs or file content
  • Raw email addresses
  • Any value matching secret patterns (auto-redacted)

Secret redaction

Automatically strips from prompt content before queuing:

  • API keys
  • Bearer tokens
  • JWT tokens
  • Passwords
  • Database connection strings
  • AWS access keys

Repository filtering

Restrict capture to specific repositories:

{
  "privacy": {
    "allowedRepos": ["github.com/tekdi/*", "github.com/myorg/public-*"]
  }
}

🛠️ CLI Reference

Configuration

coding-analytics config --posthog-key="phc_..."
coding-analytics config --posthog-host="https://eu.i.posthog.com"
coding-analytics config --edit
coding-analytics config --show

Hook Management

# Install hooks for both Cursor and Claude Code + flush cron
coding-analytics install-hooks

# Install for a specific provider only
coding-analytics install-hooks --provider cursor
coding-analytics install-hooks --provider claude

# Uninstall
coding-analytics uninstall-hooks
coding-analytics uninstall-hooks --provider cursor

Monitoring

coding-analytics status                    # full health check
coding-analytics test                      # test PostHog connection

coding-analytics events --recent 20        # view sent events (fallback storage)
coding-analytics events --provider claude  # filter by provider
coding-analytics events --provider cursor

coding-analytics logs --tail               # follow log file
coding-analytics logs --lines 100

Queue & Retry

coding-analytics flush     # manually flush queue to PostHog (normally run by cron)
coding-analytics retry     # retry events that failed to send (from fallback storage)

⚡ Architecture

Events are processed in two stages to avoid any latency impact on your editor:

Hook fires (every tool call / prompt / etc.)
  └─ coding-analytics hook / claude-hook
       → map event type          (~1ms)
       → apply privacy filters   (~1ms)
       → append to queue.jsonl   (~2ms)
       → exit                    total: ~5ms

Every 5 minutes (cron)
  └─ coding-analytics flush
       → drain queue.jsonl atomically
       → enrich batch with git + system context
         (git cached per workspace — 1 call per repo, not per event)
       → send to PostHog
       → on failure: store in events.json for retry

The cron is installed automatically by install-hooks. To verify:

crontab -l | grep coding-analytics

📈 PostHog Query Examples

Tool usage breakdown (Claude Code):

SELECT
  properties.tool_name,
  COUNT(*) as uses,
  countIf(properties.exit_code != 0) as errors
FROM events
WHERE event = 'claude_tool_used'
  AND timestamp > now() - interval '7 days'
GROUP BY tool_name
ORDER BY uses DESC

Most active users across both providers:

SELECT
  distinct_id,
  properties.provider,
  COUNT(*) as event_count
FROM events
WHERE timestamp > now() - interval '7 days'
GROUP BY distinct_id, provider
ORDER BY event_count DESC

High token sessions (Cursor):

SELECT
  properties.chat_id,
  distinct_id,
  SUM(properties.token_count) as total_tokens,
  COUNT(*) as message_count
FROM events
WHERE event = 'cursor_message_sent'
  AND timestamp > now() - interval '7 days'
GROUP BY chat_id, distinct_id
HAVING total_tokens > 5000
ORDER BY total_tokens DESC

🐛 Troubleshooting

Hooks not firing

Cursor: verify ~/.cursor/hooks.json exists and restart Cursor.

Claude Code: verify ~/.claude/settings.json has hook entries and restart Claude Code.

coding-analytics status       # shows which hooks are installed
coding-analytics logs --tail  # watch for errors in real time

Events not appearing in PostHog

coding-analytics test         # check PostHog connectivity
coding-analytics flush        # manually trigger a flush
coding-analytics events       # check fallback storage for unsent events
coding-analytics retry        # resend events that previously failed

Check the PostHog host — use your project's ingestion URL:

coding-analytics config --posthog-host="https://eu.i.posthog.com"  # EU cloud
coding-analytics config --posthog-host="https://us.i.posthog.com"  # US cloud

Cron not running

crontab -l                           # verify cron entry exists
coding-analytics install-hooks       # reinstalls cron if missing
cat ~/.coding-analytics/logs/flush.log  # check flush run history

Auth IDs not detected

coding-analytics status shows (not found) for an auth ID:

  • Claude: ensure you are logged into Claude Code (check ~/.claude.json)
  • Cursor: ensure you are logged into Cursor (check ~/.cursor/ or ~/Library/Application Support/Cursor/)

🔧 Development

Build from Source

git clone https://github.com/tekdi/coding-analytics.git
cd coding-analytics/src
npm install
npm run build
npm link
coding-analytics --version

Project Structure

coding-analytics/
├── src/
│   ├── cli.ts                  # CLI entry point & all commands
│   ├── queue.ts                # Append-only JSONL event queue
│   ├── flusher.ts              # Batch enrichment & PostHog send
│   ├── hooks-listener.ts       # Cursor hook event mapper
│   ├── claude-hooks-receiver.ts # Claude Code hook event mapper
│   ├── enricher.ts             # Git, system & user ID enrichment
│   ├── batcher.ts              # PostHog batch sender
│   ├── local-storage.ts        # JSON fallback for failed sends
│   ├── install-service.ts      # Hook + cron installation
│   ├── health-monitor.ts       # Status checks & auth ID display
│   ├── config.ts               # Configuration management
│   └── logger.ts               # Winston logger
├── install-scripts/
│   ├── install.sh              # Mac/Linux installer
│   └── install               # Windows PowerShell installer
└── package.json

📄 License

MIT — see LICENSE file

Author: Tekdi Technologies Package: @tekdi/coding-analytics Version: 1.0.0