agentleFS
MicrosoftKnown publishermicrosoft/clarity/CLAUDE.md

clarity

CLAUDE.md2.7k starsChanged 9 months agoMITView on GitHub

Clarity is an open-source TypeScript behavioral analytics library for tracking user interactions and session replays. Monorepo with Lerna/Yarn workspaces: Stack: TypeScript, Rollup, TSLint, Playwright, Lerna, Yarn workspaces Critical: clarity-js has two top priorities that must guide all development decisions: Rollup + TypeScript → multiple formats (CJS, ESM, IIFE minified). Build artifacts auto-cleaned to build/ or extension/ (gitignored). Build outputs per package: - clarity-js: clarity.js (CJS), clarity.module.js (ESM), clarity.min.js (minified), plus variants: clarity.extended.js, clarity.insight.js, clarity.performance.js, clarity.livechat.js, and dynamic module builds (clarity.tidio.js,…

  • Installs packages

Trending

Quiet since August.thin dataabout the whole repository

Dec 2025: 0 mentionsJan 2026: 1 mentionFeb 2026: 0 mentionsMar 2026: 0 mentionsApr 2026: 0 mentionsMay 2026: 0 mentionsJun 2026: 0 mentionsJul 2026: 0 mentionsAug 2026: 1 mentionSep 2026: 0 mentionsOct 2026: 0 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the microsoft/clarity repository that our weekly crawl found: only 7 in all, so this is a hint, not a trend. There is no adoption data for this file yet.

Who's talking about microsoft/clarity

The biggest 5 of 7 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 7

Talked about on GitHub and Hacker News (7 times).

On GitHub · 6

1 more on GitHub

The file

We split this CLAUDE.md into the rules it gives an agent

10 rules. About 0 are common, 3 are distinctive, and 7 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 7

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Avoid blocking the main thread

    line 19
  2. Very specific:

    Test helpers: test/helper.ts (root), packages/clarity-js/test/helper.ts (package-specific)

    line 63
  3. Very specific:

    Build fails: Run yarn install first after clone/pull

    line 121
  4. Very specific:

    Test failures: Ensure build artifacts exist with yarn build before running tests

    line 122
  5. Very specific:

    TSLint errors: Only fix your changes, use yarn tslint:fix for formatting

    line 124
  6. Very specific:

    If changing clarity-js APIs used by other packages, rebuild all from root

    line 130
  7. Very specific:

    Follow TSLint rules: typedefs required, max 140 chars, let/const only, as assertions

    line 131
  8. Distinctive:

    Always prioritize performance and bundle size: - avoid blocking main thread, minimize network requests, keep bundle small

    line 135
  9. Distinctive:

    Check bundle size impact after changes (CI runs size checks with <2% growth threshold)

    line 136
  10. Very specific:

    Use @src/<path> aliases for cross-module imports (e.g., from "@src/data/cookie", from "@src/data/metadata")

    line 139

≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

Clarity Development Guidelines

Repository Overview

Clarity is an open-source TypeScript behavioral analytics library for tracking user interactions and session replays. Monorepo with Lerna/Yarn workspaces:

  • clarity-js (packages/clarity-js): Core instrumentation library
  • clarity-decode (packages/clarity-decode): Data decoder
  • clarity-visualize (packages/clarity-visualize): Session replay visualization
  • clarity-devtools (packages/clarity-devtools): Chrome extension (private)

Stack: TypeScript, Rollup, TSLint, Playwright, Lerna, Yarn workspaces

clarity-js Performance & Bundle Size Priorities

Critical: clarity-js has two top priorities that must guide all development decisions:

  1. Performance - As an analytics library running on diverse websites, clarity-js must not hurt website performance or impact metrics like INP (Interaction to Next Paint) or PLT (Page Load Time). Balance data collection needs with:
    • Avoid blocking the main thread
    • Minimize network requests
    • Reduce payload size
  2. Bundle Size - Small bundle size is crucial for loading clarity-js quickly and starting data collection as soon as possible. Every byte matters.

Build & Development Commands

Installation

ALWAYS run yarn install before building or testing. (~25s, peer dependency warnings are normal)

Building

yarn build              # All packages (~45s, Lerna parallel build)
yarn build:js           # clarity-js only (~20s)
yarn build:decode       # clarity-decode only
yarn build:visualize    # clarity-visualize only
yarn build:devtools     # clarity-devtools only

Rollup + TypeScript → multiple formats (CJS, ESM, IIFE minified). Build artifacts auto-cleaned to build/ or extension/ (gitignored).

Build outputs per package:

  • clarity-js: clarity.js (CJS), clarity.module.js (ESM), clarity.min.js (minified), plus variants: clarity.extended.js, clarity.insight.js, clarity.performance.js, clarity.livechat.js, and dynamic module builds (clarity.tidio.js, clarity.crisp.js)
  • clarity-decode: clarity.decode.js (CJS), clarity.decode.module.js (ESM), clarity.decode.min.js (minified)
  • clarity-visualize: clarity.visualize.js (CJS), clarity.visualize.module.js (ESM), clarity.visualize.min.js (minified)
  • clarity-devtools: Output to extension/ directory for Chrome extension

Testing

yarn test                                      # Root: Runs Playwright tests (all projects)
yarn test:ui                                   # Root: Runs Playwright tests in UI mode
yarn workspace clarity-js test                 # clarity-js only (Playwright with clarity-js project)
yarn workspace clarity-decode test             # clarity-decode only (Playwright with clarity-decode project)

Tests use Playwright test runner configured in playwright.config.ts at the repo root. Each package has its own Playwright project configuration.

Test structure:

  • Per-package tests: packages/*/test/*.test.ts
  • Root e2e tests: test/*.test.ts
  • Playwright auto-discovers test directories that have both test/ folder and package.json
  • Test helpers: test/helper.ts (root), packages/clarity-js/test/helper.ts (package-specific)

Linting

cd packages/<package> && yarn tslint       # Check linting
cd packages/<package> && yarn tslint:fix   # Auto-fix

Important: Existing TSLint errors exist - only fix what you change. Key rules: max 140 chars, typedefs required, no var, use as not <> for assertions.

Project Architecture

Structure

packages/
  clarity-js/src/         # Main package
    core/                 # Config, events, version.ts (source of truth)
    layout/               # DOM tracking, mutations
    interaction/          # User interactions
    performance/          # Metrics
    data/, diagnostic/, insight/, dynamic/
  clarity-decode/         # Decoder (depends on clarity-js)
  clarity-visualize/      # Visualization (depends on clarity-decode)
  clarity-devtools/       # DevTools (depends on all three)
scripts/
  bump-version.ts         # Version bumping (updates version.ts + all package.json)
  check-file-size.sh      # Bundle size validation
playwright.config.ts      # Playwright test configuration

Per-package configs: tsconfig.json (ES5 target), tslint.json, rollup.config.ts, package.json

Common file patterns:

  • encode.ts files: Data encoding logic, found in various modules (use relative imports, not @src alias)
  • rollup.config.ts: Per-package build configuration defining output formats
  • helper.ts: Test utility functions (root test/ and packages/clarity-js/test/)
  • version.ts: Single source of truth for version (packages/clarity-js/src/core/version.ts)

Dependency chain: clarity-js → clarity-decode → clarity-visualize → clarity-devtools. Changes to upstream packages may require rebuilding dependents.

Versioning & Release

yarn bump-version                 # Patch (default)
yarn bump-version --part=minor    # Minor
yarn bump-version --part=major    # Major

Updates version.ts, all package.json, lerna.json, and stages files. Then commit, push, create PR.

Environment

Node.js: 22+ required Package manager: Yarn only (has yarn.lock, uses workspaces) - install globally: npm i -g yarn

Common Issues

  1. Build fails: Run yarn install first after clone/pull
  2. Test failures: Ensure build artifacts exist with yarn build before running tests
  3. Peer dependency warnings: Expected and safe to ignore
  4. TSLint errors: Only fix your changes, use yarn tslint:fix for formatting
  5. clarity-js changes not reflected: Rebuild all with yarn build from root

Making Changes

Workflow: yarn install → make changes → yarn build → yarn test → lint modified files

  • If changing clarity-js APIs used by other packages, rebuild all from root
  • Follow TSLint rules: typedefs required, max 140 chars, let/const only, as assertions
  • Build configs in rollup.config.ts generate multiple formats (CJS, ESM, IIFE)

clarity-js specific considerations:

  • Always prioritize performance and bundle size - avoid blocking main thread, minimize network requests, keep bundle small
  • Check bundle size impact after changes (CI runs size checks with <2% growth threshold)

Import style for clarity-js:

  • Use @src/<path> aliases for cross-module imports (e.g., from "@src/data/cookie", from "@src/data/metadata")
  • Exception: encode.ts files use relative imports (e.g., from "./encode")

Trust these instructions - validated by testing. Only search if you need specifics not covered here or encounter undocumented errors.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.