New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

@tekdi/coding-analytics

Package Overview
Dependencies
Maintainers
11
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tekdi/coding-analytics

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

latest
npmnpm
Version
1.0.1
Version published
Maintainers
11
Created
Source

@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 EventTrigger
cursor_chat_startedNew chat opened
cursor_message_sentUser sends a message
cursor_message_receivedAI responds
cursor_code_editedFiles changed via AI
cursor_chat_endedChat session closed
cursor_agent_thinkingAgent reasoning (if available)

Claude Code Events

PostHog EventTrigger
claude_session_startedClaude Code session begins
claude_prompt_submittedUser submits a prompt
claude_tool_usedAny tool call completes (Bash, Edit, Read, etc.)
claude_subagent_startedSubagent spawned
claude_subagent_stoppedSubagent completes
claude_session_stoppedSession 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

Keywords

cursor

FAQs

Package last updated on 26 Mar 2026

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts