# Reads the last 30 days of Claude Code history, and changes nothing. # measure totals, medians and model names: no prompt, path or project name # read N page N of the prompts the user typed, with secrets masked # count RE [RE..] for each expression, the sessions and days whose prompts match it, # and the frequency, status and cost to report import glob, json, os, re, statistics, sys from collections import defaultdict from datetime import date, datetime, time, timedelta, timezone DAYS = 30 now = datetime.now(timezone.utc) # The window is 30 calendar days in the user's time zone, today included. since = datetime.combine(date.today() - timedelta(days=DAYS - 1), time.min).astimezone() day_of = lambda t: t.astimezone().date() root = os.environ.get("CLAUDE_CONFIG_DIR") or os.path.expanduser("~/.claude") # Text the harness writes into the user's turn; not something the user typed. # Work the user keeps out of the survey: LLM_SURVEY_SKIP='name1,name2' skips every session whose # project folder's path holds one of the names (without case, any punctuation alike). norm = lambda s: re.sub(r"[^a-z0-9]+", "-", (s or "").lower()) SKIP = [norm(x).strip("-") for x in os.environ.get("LLM_SURVEY_SKIP", "").split(",") if x.strip()] skipped = lambda where: any(s and s in norm(where) for s in SKIP) NOT_TYPED = ("= 2 and re.search("[A-Za-z]", text) else text def name(m): # a host, or any dotted name; a file name such as stats.js stays return m.group(0) if m.group(1).lower() in FILES else "[name]" MASKS = [ (re.compile(r"https?://\S+"), "[link]"), (re.compile(r"\b[\w.+-]+@[\w-]+\.[\w.-]+\b", re.A), "[email]"), # "the password is X", "changed the token to X", "DB_PASSWORD=X", "password": "X": what follows the cue. (re.compile(r"(?i)(%s[\"']?)((?:\s+[A-Za-z]+){0,3}?(?:\s+(?:to|is|was)\s+|\s*[=:]\s*))%s" % (CUE, VALUE)), r"\1\2[masked]"), # "password hunter2", "API key sk-abc": the next word, when it is not an ordinary word. (re.compile(r"(?i)(%s)\s+(?=\S*[\d_\-!@#$%%^&*+=])\S+" % CUE), r"\1 [masked]"), (re.compile(r"(?i)\b(bearer)\s+\S+", re.A), r"\1 [masked]"), (re.compile(r"\b\d{1,3}(?:\.\d{1,3}){3}\b", re.A), "[address]"), (re.compile(r"(? 1 else "measure" if mode == "tools": # The tools around the assistant, from a fixed list: which are installed, which run now, and on # how many of the 30 days each was used. Evidence: the command word of each shell history line # (nothing else of the line is kept), the dates of the tools' own session files, and the # terminal this runs in. It prints names from this list, numbers and model ids, nothing else. import shutil, subprocess home = os.path.expanduser("~") MAC = ["/Applications", os.path.join(home, "Applications")] # name, kind, app bundles, commands (installed, typed), processes, folders whose files are sessions KNOWN = [ ("Claude Code", "harness", [], ["claude"], ["claude"], []), ("Codex CLI", "harness", [], ["codex"], ["codex"], ["~/.codex/sessions/**/*.jsonl"]), ("Gemini CLI", "harness", [], ["gemini"], ["gemini"], ["~/.gemini/tmp/*/chats/*.json", "~/.gemini/tmp/*/logs.json"]), ("OpenCode", "harness", [], ["opencode"], ["opencode"], ["~/.local/share/opencode/storage/session/**/*.json"]), ("Aider", "harness", [], ["aider"], ["aider"], []), ("Amp", "harness", [], ["amp"], ["amp"], []), ("Cursor", "editor", ["Cursor.app"], ["cursor"], ["Cursor"], ["~/Library/Application Support/Cursor/User/workspaceStorage/*", "~/.config/Cursor/User/workspaceStorage/*"]), ("VS Code", "editor", ["Visual Studio Code.app"], ["code"], ["Code", "code"], ["~/Library/Application Support/Code/User/workspaceStorage/*", "~/.config/Code/User/workspaceStorage/*"]), ("Windsurf", "editor", ["Windsurf.app"], ["windsurf"], ["Windsurf"], ["~/Library/Application Support/Windsurf/User/workspaceStorage/*", "~/.config/Windsurf/User/workspaceStorage/*"]), ("Zed", "editor", ["Zed.app"], ["zed"], ["zed"], []), ("Neovim", "editor", [], ["nvim"], ["nvim"], []), ("Vim", "editor", [], ["vim"], ["vim"], []), ("Emacs", "editor", ["Emacs.app"], ["emacs"], ["emacs", "Emacs"], []), ("Ghostty", "terminal", ["Ghostty.app"], ["ghostty"], ["ghostty"], []), ("iTerm2", "terminal", ["iTerm.app"], [], ["iTerm2"], []), ("Warp", "terminal", ["Warp.app"], [], ["stable", "Warp"], []), ("WezTerm", "terminal", ["WezTerm.app"], ["wezterm"], ["wezterm-gui"], []), ("kitty", "terminal", ["kitty.app"], ["kitty"], ["kitty"], []), ("Alacritty", "terminal", ["Alacritty.app"], ["alacritty"], ["alacritty"], []), ("Terminal.app", "terminal", [], [], ["Terminal"], []), ("tmux", "multiplexer", [], ["tmux"], ["tmux"], []), ("Zellij", "multiplexer", [], ["zellij"], ["zellij"], []), ("ChatGPT", "chat", ["ChatGPT.app"], [], ["ChatGPT"], []), ("Claude", "chat", ["Claude.app"], [], ["Claude"], []), ] # What TERM_PROGRAM and friends call each terminal: it runs on every day the assistant is used. TERMS = {"ghostty": "Ghostty", "iTerm.app": "iTerm2", "WarpTerminal": "Warp", "WezTerm": "WezTerm", "Apple_Terminal": "Terminal.app", "vscode": "VS Code", "zed": "Zed"} window = lambda t: t >= since days_of = defaultdict(set) # Shell history with times: zsh (":