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

ai-lens

v0.8.61

Published

Centralized session analytics for AI coding tools

Downloads

2,759

Readme

AI Lens

Analytics for AI coding sessions. Captures hook events from Claude Code, Cursor, and Codex, normalizes them to a unified format, queues locally, and ships to a centralized server with a web dashboard and MCP integration.

Hook fires → capture.js → normalize → queue.jsonl → sender.js → POST /api/events → server → dashboard

Developer Setup (client)

Run the init command on each developer machine:

npx -y ai-lens init

This will:

  1. Detect installed AI tools (Claude Code, Cursor, Codex)
  2. Copy client files to ~/.ai-lens/client/
  3. Configure hooks in ~/.claude/settings.json and/or ~/.cursor/hooks.json
  4. Start the Codex watcher for user-level and project-local Codex sessions
  5. Register the MCP server for in-editor analytics (optional)

Re-running is safe — it updates outdated hooks and skips current ones.

Deploying hooks in a specific project (project-level hooks)

To write hooks into the project directory (.cursor/hooks.json and .claude/settings.json) instead of global ~/.cursor/ and ~/.claude/, run from the project root:

npx -y ai-lens init --server https://ai-lens.rantsports.com --no-mcp --project-hooks

Add --use-repo-path to run capture.js directly from the package (repo or npx cache) instead of copying to ~/.ai-lens/client/. Useful when the repo is next to the workspace.

CLI commands

npx ai-lens init       # Setup wizard — detect tools, install hooks, configure MCP
npx ai-lens status     # Run health checks and generate a diagnostic report
npx ai-lens remove     # Remove hooks, client files, and MCP config
npx ai-lens version    # Show installed version

CLI options

| Flag | Description | |------|-------------| | --server URL | Server URL (default: http://localhost:3000) | | --yes, -y | Non-interactive mode, accept all defaults | | --no-mcp | Skip MCP server registration | | --mcp-scope SCOPE | MCP scope: user (default), local, or project | | --projects LIST | Comma-separated project paths to monitor (default: all) | | --project-hooks | Write hooks into project directory instead of global config | | --use-repo-path | Run capture.js from package path instead of copying to ~/.ai-lens/client/ |

Environment variables (client)

# In your shell profile (~/.zshrc, ~/.bashrc)
export AI_LENS_SERVER_URL=https://ai-lens.rantsports.com
export AI_LENS_PROJECTS="~/meta/, ~/meta-cursor/"   # optional, default: all

Claude Code~/.claude/settings.json (hooks section):

{
  "hooks": {
    "SessionStart": [{ "matcher": "", "hooks": [{ "type": "command", "command": "node ~/.ai-lens/client/capture.js" }] }],
    "UserPromptSubmit": [{ "matcher": "", "hooks": [{ "type": "command", "command": "node ~/.ai-lens/client/capture.js" }] }],
    "PreToolUse": [{ "matcher": "", "hooks": [{ "type": "command", "command": "node ~/.ai-lens/client/capture.js" }] }],
    "PostToolUse": [{ "matcher": "", "hooks": [{ "type": "command", "command": "node ~/.ai-lens/client/capture.js" }] }],
    "Stop": [{ "matcher": "", "hooks": [{ "type": "command", "command": "node ~/.ai-lens/client/capture.js" }] }]
  }
}

Cursor~/.cursor/hooks.json:

{
  "version": 1,
  "hooks": {
    "sessionStart": [{ "command": "node ~/.ai-lens/client/capture.js" }],
    "beforeSubmitPrompt": [{ "command": "node ~/.ai-lens/client/capture.js" }],
    "postToolUse": [{ "command": "node ~/.ai-lens/client/capture.js" }],
    "afterFileEdit": [{ "command": "node ~/.ai-lens/client/capture.js" }],
    "afterShellExecution": [{ "command": "node ~/.ai-lens/client/capture.js" }],
    "afterMCPExecution": [{ "command": "node ~/.ai-lens/client/capture.js" }],
    "stop": [{ "command": "node ~/.ai-lens/client/capture.js" }],
    "sessionEnd": [{ "command": "node ~/.ai-lens/client/capture.js" }]
  }
}

Codex — no hook file. Run ai-lens init to start the local watcher, or start it manually:

node ~/.ai-lens/client/codex-watcher.js

The watcher tails the user-level Codex directory (~/.codex) and any project-local .codex directories found under AI_LENS_PROJECTS. It respects AI_LENS_PROJECTS the same way as Claude Code and Cursor: only sessions whose cwd is inside a configured monitored root are sent.

Server Setup

Docker (production)

docker compose up -d

Starts three containers:

| Container | Image | Purpose | |-----------|-------|---------| | app | ai-lens/app | API server + web dashboard (port 3000) | | postgres | postgres:16-alpine | PostgreSQL 16 database | | analyzer | ai-lens/analyzer | Background session analyzer (needs claude login) |

Dashboard: https://ai-lens.rantsports.com

Images are stored in ECR (267996409571.dkr.ecr.eu-north-1.amazonaws.com/ai-lens/) and mirrored to GHCR (ghcr.io/r-ms/ai-lens/) on every push to main.

Environment variables (server)

| Variable | Default | Description | |----------|---------|-------------| | PORT | 3000 | Server port | | DATABASE_URL | (required) | PostgreSQL connection string | | POSTGRES_PASSWORD | ailens | PostgreSQL password (docker compose) | | ANALYSIS_INTERVAL | 60 | Seconds between analysis runs | | AI_LENS_ADMIN_SECRET | (none) | Admin secret for auth token management | | OPENAI_API_KEY | (none) | OpenAI API key for FAISS vector search; text search works without it | | TEAMS_CONFIG | (none) | JSON config for team definitions | | CORS_ALLOWED_ORIGINS | (none) | Allowed CORS origins |

Auth0 SSO

| Variable | Description | |----------|-------------| | AUTH0_DOMAIN | Auth0 tenant domain | | AUTH0_CLIENT_ID | Auth0 SPA client ID | | AUTH0_AUDIENCE | Auth0 API audience identifier | | AUTH0_ALLOWED_DOMAIN | Restrict login to a specific email domain | | AUTH0_CLI_CLIENT_ID | Auth0 Native app client ID for device code flow | | MCP_SERVER_URL | Public server URL for MCP OAuth callbacks |

Without Auth0, the server uses git email headers for identity (personal mode).

Local development

docker compose up postgres -d
npm install
DATABASE_URL=postgresql://ailens:ailens@localhost:5432/ailens npm start

Dashboard

React + TypeScript SPA with:

  • Organization-wide KPIs and adoption trends
  • Team and developer breakdowns
  • Session timelines with tool usage
  • AI-generated session and team analyses
  • Token usage by model
  • MCP server and skill distribution
  • Knowledge base and recurring problems
cd dashboard
npm install
npm run dev          # Vite dev server with HMR (proxies API to localhost:3000)
npm run build        # Production build (served by Express as static files)

Tech: Vite, Tailwind CSS, Nivo charts, TanStack Query, react-router-dom.

MCP Tools

When MCP is enabled during npx ai-lens init, these tools become available inside Claude Code and Cursor:

| Tool | Description | |------|-------------| | who_am_i | Identify yourself by git email — returns your developer profile and team(s) | | get_overview | Organization-wide KPIs: active developers, adoption rate, AI hours, MCP and skill distribution | | list_teams | List all teams with member counts, adoption rate, and AI hours | | get_team | Team detail: KPIs, members, tasks, activity trend, MCP and skill distribution | | get_team_analysis | AI-generated team analysis: achievements, recurring problems, recommendations | | get_developer | Developer profile: sessions, AI hours, tasks, MCP and skill usage, team comparison | | get_mcp_distribution | MCP server usage across the organization | | get_chain | Session chain with compact event timeline, plan mode segments, and timing | | get_events | Full event data for specific event IDs | | get_chain_analysis | AI-generated chain analysis: tasks, problems, tool errors, unanswered questions | | request_analysis | Manually trigger analysis for a specific session chain | | get_token_usage | Token usage statistics grouped by model (input/output/cache tokens) | | knowhow_search | Search the team knowledge base built from session analyses | | knowhow_update | Add or update a knowledge base entry | | export_developer_tips | Export personalized tips as a Markdown document | | search | Natural language search across sessions, tasks, and projects |

API

POST /api/events

Batch insert events. Deduplicates by event_id (ON CONFLICT DO NOTHING) — safe to re-send.

Headers: X-Developer-Git-Email, X-Developer-Name, X-Auth-Token
Body: [{ source, session_id, type, project_path, timestamp, data, raw, event_id }]
Response: { received, skipped, deduplicated }

GET /api/sessions

List sessions. Query params: developer_id, source, days (default 30).

GET /api/sessions/:id

Session detail with all events, plan segments, and metadata.

GET /api/developers

List all developers.

GET /api/dashboard/*

Aggregate endpoints for dashboard charts: overview, teams, developers, tokens, MCP distribution, developer activity, knowledge base, problems, company/team/developer analyses.

Event Types

| Type | Source | Description | |------|--------|-------------| | SessionStart | All | Session opened | | SessionEnd | All | Session closed | | UserPromptSubmit | All | User sent a prompt | | PostToolUse | All | Tool execution completed | | PostToolUseFailure | All | Tool execution failed | | Stop | All | Agent stopped | | PreCompact | All | Context compaction triggered | | PlanModeStart | Claude Code | Entered plan mode | | PlanModeEnd | Claude Code | Exited plan mode (plan content in raw payload) | | SubagentStart | All | Subagent spawned | | SubagentStop | All | Subagent finished | | FileEdit | Cursor | File edited | | ShellExecution | Cursor | Shell command executed | | MCPExecution | Cursor | MCP tool executed | | AgentResponse | Cursor | Agent response (includes token usage in raw payload) | | AgentThought | Cursor | Agent reasoning |

Supported Tools

| Tool | Hook mechanism | |------|---------------| | Claude Code | Hooks via ~/.claude/settings.json | | Cursor | Hooks via ~/.cursor/hooks.json | | Codex | File watcher on ~/.codex and project-local .codex directories |

Client Data

Stored in ~/.ai-lens/:

| File | Purpose | |------|---------| | client/ | Installed client files (capture.js, sender.js, config.js) | | config.json | Server URL, auth token, project list | | queue.jsonl | Pending events | | queue.sending.jsonl | Events being sent (atomic rename as mutex) | | sender.log | Sender activity log | | capture.log | Capture drop log (normalization failures, write errors) | | session-paths.json | Session-to-project path cache |

Development

npm test               # Run all tests (vitest, 683 tests)
npm run test:watch     # Watch mode
npm run dev:dashboard  # Dashboard dev server

Tests require PostgreSQL — set DATABASE_URL or use docker compose up postgres -d (test DB ailens_test is created automatically).

Deployment

GitLab CI (.gitlab-ci.yml) on push to main:

  1. build-app — builds ai-lens/app Docker image, pushes to ECR + GHCR
  2. build-analyzer — builds ai-lens/analyzer Docker image, pushes to ECR + GHCR
  3. deploy — zero-downtime rolling deploy to production (scale up new container, health check, remove old)

Build jobs trigger only when relevant files change (Dockerfile, server/, dashboard/, etc.).

Requirements

  • Node.js 20+
  • Docker + Docker Compose (for production deployment)
  • PostgreSQL 16 (for local development without Docker)