slopmeter

repository·main·Indexed 41 days ago

https://github.com/jeanmeijer/slopmeter

A CLI tool that generates contribution-style usage heatmaps for AI coding assistants, including Claude Code, Cursor, Gemini CLI, Codex, Open Code, and Pi Coding Agent. It scans local usage data to produce visual representations of activity over the rolling past year in PNG, SVG, or JSON formats.

Tokens
10.7K
Snippets
43
Records
57
Agent score
51%

What's inside slopmeter

  1. Understand slopmeter exit behavior

    main

    The CLI exits with an error in the following scenarios:

    • If provider flags are passed but the requested provider has no data.
    • If no provider has any data available.
    • If a JSONL record or OpenCode payload exceeds SLOPMETER_MAX_JSONL_RECORD_BYTES (this results in a clear error naming the file/line/byte cap).
  2. Customize slopmeter output files and formats

    main

    The output format and filename behavior depend on your flags:

    • Format Inference: If --format is omitted, the format is inferred from the --output extension. If neither --format nor a recognized extension is provided, PNG is used.
    • Default Filenames: If --output is omitted, the filename is generated as follows:
      • Default: heatmap-last-year.<ext>
      • With explicit provider flags: heatmap-last-year_<providers>.<ext>
      • With --all: heatmap-last-year_all.<ext>
    • Supported Extensions: .png, .svg, and .json.
    # Write an SVG
    slopmeter --format svg --output ./out/heatmap.svg
    
    # Write JSON for custom rendering
    slopmeter --format json --output ./out/heatmap.json
    
    # Render a dark-theme SVG
    slopmeter --dark --format svg --output ./out/heatmap-dark.svg
  3. Run the slopmeter CLI

    main

    Depending on your environment, you can run the CLI in several ways:

    1. From built output: After running bun run build, execute the compiled JS file with Node.
    2. In dev mode: Use bun run with the --cwd flag pointing to the CLI package.
    3. As a binary: If installed as a package binary, simply call slopmeter.
    # Build once
    bun run build
    
    # Run from built output
    node packages/cli/dist/cli.js
    
    # Run the CLI package directly in dev mode
    bun run --cwd packages/cli dev
    
    # Or if installed as a package binary
    slopmeter
  4. Use the slopmeter CLI

    main

    The slopmeter CLI scans local usage data from various AI coding agents (Claude Code, Codex, Cursor, Gemini CLI, Open Code, and Pi Coding Agent) and generates a contribution-style heatmap for the rolling past year.

    By default, it scans all supported providers and writes a PNG file named ./heatmap-last-year.png.

    slopmeter [--all] [--claude] [--codex] [--cursor] [--gemini] [--opencode] [--pi] [--dark] [--format png|svg|json] [--output ./heatmap-last-year.png]
  5. Gemini token calculation logic

    main

    When processing Gemini messages, tokens are categorized as follows:

    • Input Tokens: Calculated as input + cached.
    • Output Tokens: Calculated as output + thoughts + tool.
    • Cache: Specifically tracks the cached value as input cache.

    This ensures that 'thoughts' and 'tool' usage are correctly attributed to the total output consumption.

  6. Configure slopmeter via environment variables

    main

    You can tune performance and memory limits using these environment variables:

    VariableDescription
    SLOPMETER_FILE_PROCESS_CONCURRENCYPositive integer for file-processing limit (Claude Code and Codex JSONL). Default: 16
    SLOPMETER_MAX_JSONL_RECORD_BYTESByte cap for JSONL records and OpenCode payloads. Default: 67108864 (64 MB)
  7. Configure slopmeter environment variables

    main

    You can tune the performance and limits of the CLI using the following environment variables:

    • SLOPMETER_FILE_PROCESS_CONCURRENCY: A positive integer setting the file-processing limit for Claude Code and Codex JSONL files. Default: 16.
    • SLOPMETER_MAX_JSONL_RECORD_BYTES: The byte cap for records in Claude Code/Codex JSONL, OpenCode JSON, and OpenCode SQLite message.data payloads. Default: 67108864 (64 MB).
  8. Configure heatmap color variants

    main

    The AgentUsageHeatmap uses CSS variables to drive its color scales based on the variant prop. When using a specific variant, the component applies a set of CSS variables (--heatmap-0 through --heatmap-4) to the container. These variables map to provider-specific color scales defined in your global CSS.

    Supported variants and their corresponding CSS variable mappings:

    • claude: --heatmap-claude-0 to --heatmap-claude-4
    • codex: --heatmap-codex-0 to --heatmap-codex-4
    • cursor: --heatmap-cursor-0 to --heatmap-cursor-4
    • opencode: --heatmap-opencode-0 to --heatmap-opencode-4
    • pi: --heatmap-pi-0 to --heatmap-pi-4
  9. Understand the Model Usage and Insights structures

    main

    Slopmeter provides granular breakdowns of token usage and high-level insights into usage patterns.

    Model Usage

    Each entry in a breakdown or an insights object uses the ModelUsage structure to describe token counts for a specific model:

    • name: The name of the model.
    • tokens: An object containing input, output, cache (with input and output), and total counts.

    Insights

    The Insights object provides summarized intelligence about usage:

    • mostUsedModel?: The model with the highest overall usage.
    • recentMostUsedModel?: The model most frequently used in the recent period.
    • streaks: An object containing longest and current usage streak counts.
  10. Determine output file paths and formats

    main

    Slopmeter generates heatmaps with specific naming conventions based on the selected providers and the requested output format.

    Default Filename Pattern

    The default filename follows the pattern: ./heatmap-last-year[SUFFIX].[FORMAT].

    Suffix Logic

    The [SUFFIX] is determined by the providers selected during execution:

    • All providers: If the --all flag is used, the suffix is _all (e.g., ./heatmap-last-year_all.png).
    • Specific providers: If specific providers are selected, the suffix is an underscore followed by the provider IDs joined by underscores (e.g., if cursor and gemini are selected, the suffix is _cursor_gemini).
    • No providers: If no specific providers are selected, no suffix is added.

    Supported Formats

    The following output formats are supported:

    • png (default)
    • svg
    • json
    Example filenames:
    - Default: ./heatmap-last-year.png
    - All providers: ./heatmap-last-year_all.png
    - Specific providers: ./heatmap-last-year_cursor_gemini.png
    - JSON format: ./heatmap-last-year.json