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

openclaw-face-cost-tracker

v0.1.6

Published

OpenClaw hook for tracking AI costs with delayed aggregation

Readme

OpenClaw Face Cost Tracker

OpenClaw hook for tracking AI costs with delayed aggregation to avoid frequent calculations.

Features

  • Delayed Calculation: Waits 1 minute after the last message before calculating costs
  • Batch Processing: Multiple messages within 1 minute are batched together
  • Session-based: Calculates costs per session from OpenClaw JSONL files
  • R2 Storage: Uploads cost data to Cloudflare R2 for easy access
  • Pre-calculated Costs: Uses OpenClaw's own cost calculations when available
  • Fallback Calculation: Calculates from token usage when pre-calculated costs aren't available

Installation

  1. Install dependencies:
pnpm install
  1. Set up environment variables (create .env file):
R2_ACCESS_KEY_ID=your_access_key
R2_SECRET_ACCESS_KEY=your_secret_key
R2_ENDPOINT=https://your-account-id.r2.cloudflarestorage.com
R2_BUCKET=your-bucket-name
  1. Test the hook:
pnpm test:push

How It Works

  1. Message Received: When a message:received event occurs, the hook schedules a cost calculation for 1 minute later
  2. Timer Reset: If another message is received within that minute, the timer resets
  3. Cost Calculation: After 1 minute of inactivity, the hook:
    • Reads JSONL session files from ~/.openclaw/agents/main/sessions/
    • Parses usage data from the last 30 days
    • Calculates costs using model-specific pricing
    • Uploads results to R2 as cost.json

Cost Data Format

The cost data uploaded to R2 follows this schema:

{
  "timestamp": "2026-02-24T19:23:00.000Z",
  "sessionKey": "agent:main:main",
  "totalCost": 0.0159,
  "models": {
    "claude-sonnet-4-5": {
      "cost": 0.0159,
      "inputTokens": 100,
      "outputTokens": 500,
      "cacheReadTokens": 27000,
      "cacheWriteTokens": 0,
      "messageCount": 1
    }
  },
  "messageCount": 1,
  "lastMessageTime": "2026-02-24T19:22:45.000Z"
}

Model Pricing

The hook uses pricing from pricing.json in the hook directory.

To update pricing:

  1. Edit pricing.json in the hook directory
  2. Restart the hook to reload the pricing

The pricing file format:

{
  "claude-sonnet-4-5-20251101": {
    "input": 3.00,
    "output": 15.00,
    "cacheWrite": 3.75,
    "cacheRead": 0.30
  },
  "claude-opus-4-5-20251101": {
    "input": 15.00,
    "output": 75.00,
    "cacheWrite": 18.75,
    "cacheRead": 1.50
  }
}

Note: If a model is not found in the pricing file, its cost will be calculated as $0.

Integration with OpenClaw

This hook is designed to work with OpenClaw's hook system. Once installed, it will automatically:

  1. Listen for message events
  2. Schedule delayed cost calculations
  3. Upload results to your R2 bucket

You can then build a dashboard (like the one in openclaw-face) to display the cost data from R2.

Development

  • Test: pnpm test - Run unit tests
  • Test Run: pnpm test:run - Run tests once
  • Test Push: pnpm test:push - Test R2 upload functionality

License

MIT