You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Session exit hook (-session-end):
- Shows cost summary when Claude Code session ends (SessionEnd hook)
- Displays session cost, request count, duration, today's total, and models used
- Uses ANSI escape + exit code 2 to render cleanly in Claude Code's hook output
- Silently exits on any error to never break session teardown
Configurable cost thresholds:
- ~/.goccc.json now supports warn_threshold and alert_threshold fields
- Thresholds auto-swap if user accidentally reverses them
- Applied to terminal output, statusline, and session exit hook
MCP detection:
- Now detects top-level mcpServers in ~/.claude.json (6th detection path)
- Replaced programmatic MCP tests with realistic fixture-based tests
- testdata/mcp/ exercises all 7 source types including disabled filtering
Other:
- Merged initConfig + initCurrency to load ~/.goccc.json once
- configPath is now a var func for testability
- Added Timestamp to dedupRecord for session duration calculation
- parseDateStr returns parsed time.Time alongside date string
- Float epsilon for today vs session cost comparison
- Collapsed README "How It Works" to essentials, kept cache write pricing
- Updated CLAUDE.md structure, conventions, and MCP source count
@@ -104,8 +105,9 @@ Independently verified against a Python parser on 272 requests across 11 files (
104
105
-**Shared file parsing** — `parseFile()` in parser.go is used by both `parseLogs` (directory walk) and `parseSession` (statusline single-session)
105
106
-**Local timezone everywhere** — local midnight for cutoffs, `parsed.Local()` for date bucketing. Never use `UTC()` for user-facing date logic
106
107
-**MCP detection is best-effort** — all MCP detection functions return nil/empty on error; statusline never fails due to missing config
107
-
-**MCP sources** — five detection paths: `mcpServers` in settings.json, marketplace `enabledPlugins` with `.mcp.json` walk, project-level `.mcp.json` via `cwd` from transcript, `settings.local.json` in project `.claude/`, and per-project `mcpServers` in `~/.claude.json`
108
-
-**Local currency** — `~/.goccc.json` stores currency code, cached rate, and timestamp; exchange rates auto-fetched and cached for 24h. `-currency-symbol` and `-currency-rate` flags override config (both required together). JSON output cost fields always in USD
108
+
-**MCP sources** — six detection paths: `mcpServers` in settings.json, marketplace `enabledPlugins` with `.mcp.json` walk, project-level `.mcp.json` via `cwd` from transcript, `settings.local.json` in project `.claude/`, top-level `mcpServers` in `~/.claude.json`, and per-project `mcpServers` in `~/.claude.json`
109
+
-**Config file** — `~/.goccc.json` stores currency code, cached rate, timestamp, and cost thresholds (`warn_threshold`/`alert_threshold`). `initConfig()` loads everything once: thresholds first (with swap-correction if misordered), then currency. Exchange rates auto-fetched and cached for 24h. `-currency-symbol` and `-currency-rate` flags override config (both required together). JSON output cost fields always in USD
110
+
-**Session end hook** — `-session-end` reads `SessionEnd` JSON from stdin, parses the session transcript, and outputs a one-line cost summary. Uses `os.Exit(2)` + ANSI escape to overwrite Claude Code's "hook failed" prefix. Silently exits on any error — never breaks session teardown
JSON output always reports costs in USD for backward compatibility, with a `currency` metadata object when a non-USD currency is active.
84
86
87
+
> See also: [Configuration](#configuration) for threshold customization.
88
+
85
89
## Claude Code Statusline
86
90
87
91
goccc can serve as a [Claude Code statusline](https://code.claude.com/docs/en/statusline) provider — a live cost dashboard right in your terminal prompt.
@@ -126,6 +130,52 @@ Add to `~/.claude/settings.json`:
126
130
127
131
To hide the MCP indicator, add `-no-mcp`.
128
132
133
+
## Session Exit Hook
134
+
135
+
goccc can show a cost summary when a Claude Code session ends — the feature users miss most since Anthropic removed it.
|`-statusline`||`false`| Statusline mode for Claude Code (reads session JSON from stdin) |
145
196
|`-no-mcp`||`false`| Hide MCP servers from statusline output |
146
197
|`-currency-symbol`||| Override currency symbol (requires `-currency-rate`) |
@@ -149,15 +200,7 @@ To hide the MCP indicator, add `-no-mcp`.
149
200
150
201
## How It Works
151
202
152
-
Claude Code stores conversation logs as JSONL files under `~/.claude/projects/<project-slug>/`. Each API call produces one or more log entries — streaming responses generate duplicates with the same `requestId`.
153
-
154
-
goccc:
155
-
156
-
1. Walks `.jsonl` files under the projects directory, skipping non-matching project directories and files older than the date range (by mtime)
157
-
2. Pre-filters lines with a byte scan before JSON parsing — only `"type":"assistant"` entries carry billing data (tolerates both compact and spaced JSON formatting)
158
-
3. Deduplicates streaming entries by `requestId` (last entry wins)
159
-
4. Calculates costs using [Anthropic's published pricing](https://platform.claude.com/docs/en/about-claude/pricing), including cache write tiers, long-context premiums (>200K input tokens), and web search costs
160
-
5. Aggregates by model, date (local timezone), project, and month
203
+
goccc parses Claude Code's JSONL conversation logs from `~/.claude/projects/`, deduplicates streaming responses (by `requestId`), and calculates costs using [Anthropic's published pricing](https://platform.claude.com/docs/en/about-claude/pricing) — including cache write tiers, long-context premiums (>200K input), and web search costs.
0 commit comments