How foyzulkarim/claude-lens works
Purpose and Status
This repository is building Claude Lens, a local analytics/dashboard system for Claude Code transcript data: discover project logs, ingest incrementally, derive sessions/turns/token usage, and expose metrics to a planned interactive client. The previous runnable V1 dashboard is isolated under legacy/; the root codebase is the newer architecture under development.
Entry Points
• Server application assembly: server/app.ts; CLI process entry: server/cli.ts.
• Client is a Vite/React-style shell rooted at client/index.html, with current source at client/src/placeholder.ts.
• Repository build orchestration is in scripts/build.ts.
• Legacy V1 remains independently runnable via legacy/server.js, as stated in the root README.
Ingestion Pipeline
The ingestion subsystem converts filesystem transcript artifacts into normalized store inputs:
• Discovery locates candidate project/transcript files: server/ingest/discovery.ts.
• Transcript parsing reads source log content: server/ingest/parse-transcript.ts.
• Pipeline coordination applies parsing and downstream updates: server/ingest/pipeline.ts.
• Continuous update mechanisms support polling/tailing and initial cache warm-up: server/ingest/poller.ts, server/ingest/tailer.ts, server/ingest/warm-cache.ts.
The primary boundary is local transcript files versus internal typed records; fixture projects under test/fixtures/projects/ represent the expected source shape.
State and Derived Domain Model
The store owns normalized/derived analytical state and change invalidation:
• Central store: server/store/store.ts.
• Session derivation: server/store/derive-session.ts.
• Turn derivation: server/store/derive-turns.ts.
• Dependency/change invalidation: server/store/invalidation.ts.
• Token accounting is separated in server/store/token-usage.ts.
This layer decouples raw ingestion from query-facing metrics, allowing file changes to update only affected derived views.
Metrics Engine
Metrics are computed over stored sessions and turns rather than directly over transcript files:
• Calculation orchestration: server/metrics/engine.ts.
• Dimension definitions/grouping: server/metrics/dimensions.ts.
• Measures and distributions: server/metrics/measures.ts, server/metrics/distributions.ts.
• Grain/time-resolution logic: server/metrics/grain.ts.
• Shared public metric shapes are defined in shared/metrics-contract.ts.
Client, API, and Live Updates
The intended server/client boundary is represented by shared contracts:
• General domain types: shared/types.ts.
• WebSocket protocol: shared/ws-protocol.ts.
• Server integration point: server/app.ts.
• Client shell and visual development setup: client/src/placeholder.ts, client/.storybook/main.ts.
Planning artifacts explicitly identify Fastify assembly, WebSocket invalidation, React shell, URL-synced filtering, and chart/dashboard stages in specs/issues/P3-1-fastify-assembly-ws-invalidation-bus.md through specs/issues/P4-2-dashboard-page.md.
Infrastructure and Legacy Boundary
The active implementation is TypeScript across server/, shared/, and client/, with Vite client configuration in client/vite.config.ts. CI is defined in .github/workflows/ci.yml. The historical Node-based dashboard, its dependencies, and environment example are intentionally contained in legacy/server.js, legacy/package.json, and legacy/.env.example; it should be treated as a separate compatibility/reference implementation rather than the new system’s core runtime.
Main entry points: engine.ts Metrics engine · store.ts Central store · app.ts Server application · discovery.ts Discovery
Components 18
Ingestion
Converts local Claude Code artifacts into typed updates.
- Local transcript files · Claude Code project logs discovered on the local machine.
test/fixtures/projects - Discovery · Locates candidate project and transcript files.
server/ingest/discovery.ts - Transcript parser · Reads transcript content into typed records.
server/ingest/parse-transcript.ts - Ingestion pipeline · Applies parsed records and downstream updates.
server/ingest/pipeline.ts - Polling, tailing and warm-up · Performs initial cache warm-up and continuous file change detection.
server/ingest/poller.ts
Analytical State
Maintains normalized records and invalidates affected derivations.
- Central store · Owns normalized and derived analytical state.
server/store/store.ts - Session derivation
server/store/derive-session.ts - Turn derivation
server/store/derive-turns.ts - Token accounting
server/store/token-usage.ts - Change invalidation · Limits recalculation to affected derived views.
server/store/invalidation.ts
Metrics
Computes query-facing analytics from stored sessions and turns.
- Metrics engine · Calculates metrics over stored sessions and turns.
server/metrics/engine.ts - Dimensions and grain · Defines grouping and time-resolution logic.
server/metrics/dimensions.ts - Measures and distributions
server/metrics/measures.ts - Metrics contract · Public metric shapes shared across the application boundary.
shared/metrics-contract.ts
Server and Client
Planned interactive application boundary.
- Server application · Integrates ingest, state, metrics, API, and live updates.
server/app.ts - Domain and WS contracts · Defines general domain types and WebSocket protocol.
shared/ws-protocol.ts - React/Vite client shell · Current client shell for planned dashboard and filtering UI.
client/src/placeholder.ts
Legacy V1
Separate runnable reference dashboard.
- Legacy V1 dashboard · Independently runnable compatibility/reference implementation.
legacy/server.js
Connections 22
- Local transcript files → Discovery: scan
- Discovery → Ingestion pipeline: candidate files
- Polling, tailing and warm-up → Discovery: initial and changed files
- Discovery → Transcript parser: transcript paths
- Transcript parser → Ingestion pipeline: typed records
- Ingestion pipeline → Central store: normalized updates
- Central store → Session derivation: derive
- Central store → Turn derivation: derive
- Central store → Token accounting: account
- Change invalidation → Central store: invalidate affected views
- Session derivation → Metrics engine: sessions
- Turn derivation → Metrics engine: turns
- Token accounting → Metrics engine: usage
- Dimensions and grain → Metrics engine: grouping and grain
- Measures and distributions → Metrics engine: calculations
- Metrics engine → Metrics contract: metric results
- Server application → Ingestion pipeline: runs ingestion
- Server application → Metrics engine: queries
- Domain and WS contracts → Server application: API and WS types
- Domain and WS contracts → React/Vite client shell: API and WS types
- Metrics contract → React/Vite client shell: metric shapes
- Server application → React/Vite client shell: metrics and live invalidation