@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 | bashWindows (PowerShell as Administrator):
Invoke-WebRequest -Uri https://raw.githubusercontent.com/tekdi/coding-analytics/main/install-scripts/install.ps1 -OutFile install.ps1
.\install.ps1Manual 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-hooksVerification
coding-analytics statusExpected 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:
cursororclaudetag 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 --showHook 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 cursorMonitoring
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 100Queue & 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 retryThe 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 DESCMost 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 DESCHigh 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 timeEvents 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 failedCheck 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 cloudCron 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 historyAuth 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 --versionProject 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
