claude-receipts
CLAUDE.md628 starsChanged 10 months agoMITView on GitHub
claude-receipts is an NPM package that generates beautiful thermal printer-style receipts for Claude Code usage sessions. It integrates with Claude Code's SessionEnd hook to automatically create HTML receipts that open in the browser when a coding session ends. The package operates in two modes: Commands (src/commands/) Core Logic (src/core/) Utils (src/utils/) SessionEnd Hook Integration ccusage Data Format Output Modes Config Philosophy Visual Design
The file
We split this CLAUDE.md into the rules it gives an agent
4 rules. About 0 are common, 0 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈0
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 81
When from hook: uses transcript_path directly, auto-opens browser, no console output
- Very specific: line 89
Only sessions with valid projectPath (not "Unknown Project") are usable
- Very specific: line 118
All types in src/types/:
- Very specific: line 161
Always backs up settings.json before modification.
≈ “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.
Files
CLAUDE.md
This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
Project Overview
claude-receipts is an NPM package that generates beautiful thermal printer-style receipts for Claude Code usage sessions. It integrates with Claude Code's SessionEnd hook to automatically create HTML receipts that open in the browser when a coding session ends.
Development Commands
# Build TypeScript to JavaScript
npm run build
# Watch mode for development
npm run dev
# Test the CLI locally (after building)
node bin/claude-receipts.js generate
node bin/claude-receipts.js generate --output html
node bin/claude-receipts.js config --show
node bin/claude-receipts.js setup
# Install locally for testing as if installed globally
npm link
claude-receipts generate
# Prepare for publishing
npm run prepublishOnly # Runs build automaticallyArchitecture
Data Flow
The package operates in two modes:
- Hook Mode (automatic): SessionEnd hook → stdin JSON → generate HTML → open browser
- Manual Mode: CLI command → fetch recent session → output to console/HTML
SessionEnd Hook
↓ (stdin with session_id, transcript_path)
GenerateCommand
↓
DataFetcher (calls ccusage CLI) + TranscriptParser (reads JSONL)
↓
ReceiptGenerator (creates text) + HtmlRenderer (creates styled HTML)
↓
Save to ~/.claude-receipts/projects/[session-slug].html + open browserKey Components
Commands (src/commands/)
generate.ts- Main command; auto-detects if called from hook via stdinsetup.ts- Modifies~/.claude/settings.jsonto install SessionEnd hookconfig.ts- Manages user configuration at~/.claude-receipts.config.json
Core Logic (src/core/)
data-fetcher.ts- Executesnpx ccusage session --json --breakdownto get usage datatranscript-parser.ts- Parses~/.claude/projects/[path].jsonlfor session metadata (slug, timestamps, message counts)receipt-generator.ts- Creates ASCII text receipt with Claude logo, location, costshtml-renderer.ts- Generates standalone HTML with embedded CSS (thermal printer aesthetic)config-manager.ts- Handles~/.claude-receipts.config.jsonI/O
Utils (src/utils/)
location.ts- Location detection chain: CLI flag → config → IP geolocation (geoip-lite) → fallbackformatting.ts- Currency, number, date/time, duration formattingascii-art.ts- Claude logo and separators for text receipts
Critical Implementation Details
SessionEnd Hook Integration
- Hook receives JSON via stdin:
{session_id, transcript_path, cwd, ...} GenerateCommand.readStdinIfAvailable()checksstdin.isTTY(false = piped from hook)- When from hook: uses
transcript_pathdirectly, auto-opens browser, no console output - Hook cannot output to console (runs after session closes), hence HTML + browser approach
ccusage Data Format
- Actual field names are camelCase:
sessionId,inputTokens,modelBreakdowns, etc. - Session IDs are complex; display names differ from actual IDs
projectPathformat:"project-name/actual-session-id"- split to get session ID- Only sessions with valid
projectPath(not "Unknown Project") are usable
File Naming
- HTML files use session slug (e.g.,
quirky-crafting-floyd.html), not session ID - Session slug comes from first user message in transcript JSONL
- Fallback to session ID if slug unavailable
Output Modes
--output html: Save to~/.claude-receipts/projects/[slug].html--output console: Display ASCII art in terminal (default for manual use)- Hook always uses
--output html(set during setup)
Config Philosophy
- Minimal config: only
version, optionallocation, optionaltimezone - No
outputDirectory,enablePNG,enableConsole,format- simplified after initial design - Output format specified at command level, not config level
Visual Design
- Black & white thermal printer aesthetic (no color backgrounds except dark page background)
- Claude ASCII logo (not "shop" names with emojis)
- "Thank you for building!" (not "shopping")
- Dark page background (#3a3a3a) makes white receipt pop
Type System
All types in src/types/:
ccusage.ts- Matches actual ccusage CLI JSON output (camelCase fields)transcript.ts- JSONL message structure and parsed summaryconfig.ts- Minimal user configurationsession-hook.ts- SessionEnd stdin JSON format
Package Structure
- ESM only (
"type": "module") - Node 22+ required - bin entry:
bin/claude-receipts.jsimports fromdist/cli.js - Exports: Main exports from
src/index.tsfor programmatic use - Files distributed:
dist/,bin/,templates/(though templates currently unused)
Known Constraints
- Cannot output to console from SessionEnd hook (terminal already closed)
- ccusage must be installed (bundled as dependency)
- Requires valid
projectPathfrom ccusage to find transcript - Session data has slight delay; ccusage may not have processed most recent session immediately
- Browser auto-open uses platform-specific commands (
open,start,xdg-open)
Hook Installation
Setup command modifies ~/.claude/settings.json:
{
"hooks": {
"SessionEnd": [
{
"hooks": [
{
"type": "command",
"command": "npx claude-receipts@latest generate --output html"
}
]
}
]
}
}Always backs up settings.json before modification. Uses @latest to ensure users get updates without reinstalling.
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
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.

