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

@nomadop/session-watcher

v0.6.0

Published

Local Claude Code context-cost monitor, transcript replay, buckets, and handoff

Downloads

329

Readme

Session Watcher

LLM context economics, in your terminal.

Session Watcher treats your prompt cache as inventory — it uses EOQ theory to measure whether the current context is still worth carrying, tracking restart pressure so you can decide when to hand off.


What it does

Session Watcher reads your Claude Code transcript in real time and answers one question: is this session still worth carrying?

Most context tools optimize how you consume tokens — Headroom compresses, /compact shrinks, RTK filters. Session Watcher tracks when the cost curve is drifting, giving you the data to decide. They compose: run any pruning strategy you like, SW measures the cost curve so you can decide when to hand off.

SW reads from the transcript, never writes to it. The dashboard and statusline are pure observers; MCP tools return data for you to act on. Metrics stay on your screen, not in the model's context window.

How it works

Your coding agent (Claude Code)
        │  writes session transcript
        ▼
┌──────────────────────────────────────────┐
│  Session Watcher (in-process MCP server)  │
│  ─────────────────────────────────────── │
│  fold.js     — tail JSONL, fold usage    │
│  measure.js  — B (context belief)        │
│  rate-lamp   — bill premium (br) + gate  │
│  server.js   — Express + SSE dashboard   │
│  statusline  — one-line shell client     │
└──────────────────────────────────────────┘
        │  dashboard  ·  statusline  ·  MCP
        ▼
   Your browser / terminal status bar

Core model: B = cache_read_input_tokens (your context inventory). g = ΔL − ΔB (growth gap). x = L / B (position on the EOQ cost curve). br = mf × pp (bill premium — the percentage you're overpaying relative to optimal).

Lamp thresholds: green (br < 10%), amber (10–24%), red (≥ 25%). See the paper for the full derivation — EOQ inventory theory mapped to LLM prompt caching.

Quick Start

Requires Node.js ≥ 22.16.

# Try without installing — self-contained demo
npx -y @nomadop/session-watcher demo

# Replay your own transcript
npx -y @nomadop/session-watcher replay ~/.claude/projects/<project>/<session>.jsonl

Opens a browser dashboard. The demo uses a pre-built anonymized session; replay uses your real transcript. Both are read-only — nothing is modified or uploaded.

Install

Plugin (recommended)

# 1. Add the marketplace (one-time)
claude plugin marketplace add nomadop/session-watcher

# 2. Install the plugin
claude plugin install session-watcher@session-watcher

Or from within a Claude Code session:

/plugin marketplace add nomadop/session-watcher
/plugin install session-watcher@session-watcher
/reload-plugins

This registers:

  • MCP tools — available in every session
  • SessionStart hook — auto-launches the dashboard server on each session

If you installed or updated in an already-running session, run /reload-plugins to activate.

Statusline

The plugin system does not yet support declaring a statusline. Add to your ~/.claude/settings.json:

{
  "statusLine": {
    "type": "command",
    "command": "<plugin-install-path>/dist/statusline.js"
  }
}

Find your plugin path with:

find ~/.claude/plugins/cache -path '*/session-watcher/*/dist/statusline.js' -print

Or check via claude plugin details session-watcher@session-watcher.

Note: the plugin cache path changes on version update. After updating, re-run the command above and update your statusline path.

One compact line:

Context Buckets

The bucket panel shows exactly which files, skills, and tools are consuming your context budget. Each path carries a token count — check or uncheck to preview how the restart cost changes. The U-curve ghost line updates in real time as you toggle.

Handoff

When it's time to restart, handoff preserves the state you want to keep. Run /sw-handoff to prepare a package — selected paths, working summary, next task. Then /clear, and in the fresh session run /sw-load to restore. Only what you chose is rebuilt — less ramp-up, less waste.

MCP Tools

Server lifecycle

| Tool | Description | |------|-------------| | start_watcher | Start (or reuse) the dashboard server; returns its URL | | stop_watcher | Stop the managed server | | watcher_status | Report whether the server is running and its URL | | rotate_session | Rotate to a new session ID |

Handoff workflow

| Tool | Description | |------|-------------| | get_bucket_summary | Return current context bucket structure (files, skills, tools) with metrics | | prepare_handoff | Persist selected paths + summary as a handoff package; returns a semantic token | | load_handoff | Load a handoff by token, free-text search, or auto-match for the current project |

Tools return data for you to decide on — only handoff injects context back into the model, and only the paths you explicitly selected.

Agent support

Session Watcher is agent-agnostic. The measurement pipeline only needs cache_read_input_tokens from each turn — it doesn't care which agent produced the transcript.

| Agent | Driver | Status | |-------|--------|--------| | Claude Code | JSONL tail (native) | ✅ | | OpenCode | adapter-ready | pending | | OpenClaw | adapter-ready | pending | | Hermes | adapter-ready | pending | | Aider | adapter-ready | pending |

Adding a new agent requires implementing one interface: extract cache_read_input_tokens from the agent's session transcript. See lib/extract.js for the Claude Code reference driver. PRs welcome.

Paper

Context Is Inventory: A Rent-or-Buy Model for Prompt-Cached LLM Sessions Longju Cheng (2026) · DOI: 10.5281/zenodo.21236704

The paper derives the full theoretical specification: EOQ→LLM mapping, the 41.4% movable-cost bound, the ski-rental restart strategy, and measurements on 1,016 real session transcripts. See paper/paper.pdf.

Uninstall

claude plugin uninstall session-watcher@session-watcher
# Remove state directory (optional):
rm -rf ~/.session-watcher

Test

npm test              # unit + integration (node:test)
npx playwright test   # E2E (requires running server)

Citation

@unpublished{cheng2026context,
  author = {Longju Cheng},
  title  = {Context Is Inventory: A Rent-or-Buy Model for Prompt-Cached LLM Sessions},
  year   = 2026,
  doi    = {10.5281/zenodo.21236704},
  url    = {https://doi.org/10.5281/zenodo.21236704},
  note   = {Preprint}
}

Privacy

  • No remote telemetry.
  • Transcripts are read locally and never uploaded.
  • Local aggregate usage and handoff records are stored under ~/.session-watcher.
  • No transcript prose or file contents are stored in telemetry.
  • Removing ~/.session-watcher deletes all local state.

License

MIT