ai-auditor
v0.1.12
Published
Local auditor for Claude Code: see where your tokens and money go prompt by prompt, grade prompt quality, flag risky agent actions, and guard sessions live.
Maintainers
Readme
ai-auditor
Audit your Claude Code sessions locally: see where tokens and money go, prompt by prompt, how clear your prompts are, and what the agent did that deserves a second look (secrets touched, data sent out, risky commands, over-analysis). Each prompt also gets a quality grade with reasons.
Everything runs on your machine. It reads the transcripts Claude Code already writes to
~/.claude/projects/ and keeps a small index in ~/.cache/ai-auditor/audit.db.

Prompts: every prompt graded A to D, the most common issues, and what vague prompts cost.

Agent behavior: secrets touched, risky commands and insecure network calls, each linked to the exact tool call.

Dark mode

Screenshots use made-up demo sessions, not real usage.
Quick start
One command, on whatever Node.js you have (18 or newer):
npx -y ai-auditor serveIt indexes your Claude Code sessions and opens the dashboard. Nothing to configure, and your Node.js version is never changed.
Requirements
Node.js 18 or newer. ai-auditor stores its index with Node's built-in
node:sqlite, and its launcher picks the right way to run for your version:| Your Node.js | What the launcher does | |---|---| | 22.13 or newer | Runs directly | | 22.5 – 22.12 | Re-runs itself with
--experimental-sqlite| | 18 – 22.4 | Runs under a Node 22 thatnpxdownloads into its cache (about 30 MB, first run only). Your installed Node, nvm setup and PATH stay as they are |
Install
To keep the ai-auditor command around instead of using npx each time:
npm install -g ai-auditorGetting started
ai-auditor serve # index sessions and open the dashboard
ai-auditor scan # overview, projects and costliest prompts in the terminalserve keeps running while the dashboard is open, and the dashboard updates live as Claude Code writes
transcripts (watch for Live in the top bar). Stop it with Ctrl+C. Each launch prints a new link with a fresh
access token, so open the link it prints rather than an old bookmark.
To update: npm install -g ai-auditor@latest. To remove: run ai-auditor guard uninstall first if you installed
the guard, then npm uninstall -g ai-auditor.
Commands
Run ai-auditor <command>:
| Command | What it does |
|---|---|
| serve [--port 4517] [--no-open] [--no-ai] [--since 30d] | Starts the dashboard on 127.0.0.1, opens it, keeps it updated live, and reviews prompt grades with Claude in the background. --no-ai turns the AI review off for that run |
| scan [--since 7d] [--project KEY] [--model M] [--limit N] [--json] | Totals, per-project breakdown, costliest prompts |
| behavior [--since 7d] [--project KEY] [--severity warn] [--category C] [--json] | Behavior findings, grouped by rule |
| prompts [--since 7d] [--project KEY] [--flag ID] [--limit N] [--json] | Prompt grades, common issues, at-risk spend, lowest-scoring prompts |
| enhance "<prompt>" / enhance --prompt <session>:<index> [--ai] | Rewrite a prompt into goal, scope, constraints and done-when |
| judge [--since 30d] [--limit 50] [--yes] | Ask Claude whether similar prompts were re-asks (shows count and cost, and asks first) |
| guard install\|uninstall\|status [--scope user\|project] [--coach] [--claude-md] [--yes] | Live guard hooks for Claude Code |
| settings [--json] | Audit Claude Code settings files |
| session <id-or-prefix> [--json] | Per-prompt breakdown for one session |
| cost-check [--json] | Our estimate vs. the cost Claude Code logged, per session |
| self-cost [--since 30d] [--json] | What ai-auditor itself spent: its AI calls (recorded per call) and the guard guidance your sessions re-read (estimated). Also on the dashboard's Settings page |
Global options: --root DIR (projects directory), --db FILE (index location), --config FILE (rule overrides),
--reindex (re-parse everything), --fail-on SEV (exit code 2 if any finding is at or above SEV, for CI).
Behavior rules
Findings are grouped into secrets, data sharing, insecure network, destructive commands, prompt injection and over-analysis, each with a severity (info → critical), the exact tool call, and a suggested fix. Highlights:
- Critical: a secret appeared in tool output (it reached the model), credentials fetched from a secret store,
injected instructions followed by a sensitive action,
rm -rfon/or home, disk-level commands. - High: reading credential files, dumping the environment, uploads/remote copies to non-local hosts, gists,
curl | sh, force-push, destructive database commands.
Tune rules in ~/.config/ai-auditor/config.json:
{
"rules": { "disable": ["destructive.rm-rf"], "severity": { "network.insecure-http": "info" } },
"trustedHosts": ["intranet.example.com"]
}Prompt quality
Typed prompts are classified (task, question, approval, casual). Tasks and questions get a 0–100 score and a grade, losing points only for explained reasons: too short to act on, vague references, unbounded scope ("check all features"), no definition of done, paths that don't exist, unsourced "latest" facts, large pastes. Each issue comes with a tip.
- Avoidable spend: casual turns (thanks, greetings) that re-send the whole conversation.
- At-risk spend: heavy turns set off by vague or unbounded prompts. Part of that work was likely needed, so it is reported separately and never added to avoidable spend.
Improving prompts
Improve (in the prompt inspector, the Prompts page's draft box, or enhance) restructures a prompt into a goal,
scope, constraints and a done-when line. It uses what the session knows, such as files the previous turn touched,
and leaves [placeholders] for what only you know.
Claude judge (AI review)
On by default. It picks how to reach Claude by itself: the Claude API when ANTHROPIC_API_KEY is set, otherwise
your Claude Code subscription through the local claude CLI if it's installed. Through the CLI, each call runs in
print mode (no tools, no hooks, no saved session, so it never shows up as one of your sessions) and counts toward
your plan's usage limits. To choose, or to change the model, set it in ~/.config/ai-auditor/config.json:
{ "llm": { "model": "claude-haiku-5-5", "provider": "claude-code" } }"provider" is "auto" (the default), "api" (also works with an ant auth login profile) or "claude-code".
To turn AI off: ai-auditor serve --no-ai for one run, or { "llm": { "enabled": false } } in the config for good.
Grades then come from the local rules only.
It sends only redacted text and caches every answer, so a prompt is never reviewed twice. Improve with AI
rewrites one prompt per click. judge tells apart prompts that re-ask (the answer missed) from prompts that iterate
(the next item in a list), something text similarity can't do.
ai-auditor serve reviews prompt grades in the background, newest first, for the last 30 days (--since to
change). The rules can't see context: "fix it"
right after the agent showed one error is clear, and a long prompt can still leave out the detail that matters. The
judge sees each prompt with the turn before it, drops rule flags that don't hold there, and adds what the rules
missed as "(AI review)" flags, so every point lost still has a reason. Reviewed grades show an AI tag in the
dashboard and update live as reviews finish; prompts typed while it runs are reviewed as they arrive. It prints the
count and estimated cost on start, and cached reviews are reused on later runs.
Live guard
ai-auditor guard install adds two Claude Code hooks to ~/.claude/settings.json (or --scope project), after
showing the exact change and asking. It keeps your existing hooks and backs the file up first.
- Prompts: secrets are stopped before they reach the model; vague, open-ended or casual prompts get guidance for
the agent (ask one question, plan first, reply briefly). Set
"guard": { "prompts": "block" }to hold vague prompts back instead. - Tool calls: the behavior rules run before each call. High-severity calls (reading
.env,curl | sh, force-push) ask you to confirm; critical ones (rm -rf ~, reading the keychain) are denied. - About 40 ms per prompt. If the guard itself errors, the prompt or call goes through (fail open).
guard statusshows where it's installed, its latency and recent activity;guard uninstallremoves it.- Optional:
--coachinstalls aprompt-coachskill,--claude-mdadds working-style rules to./CLAUDE.md. - Prompt enhancer (off by default; switch it on in the dashboard's Settings page, or set
"guard": { "enhancePrompts": true }): adds a short scope note to each task prompt. It names the files in scope (the ones your prompt mentions, otherwise the ones worked on most recently), tells the agent to change only those unless it can't avoid it, and not to load skills or start sub-agents it doesn't need. Claude Code hooks can't rewrite what you typed, so the note goes alongside your prompt (about 70 tokens). Slash commands, approvals and small talk are skipped.
Turning the guard on (when you're ready)
The guard is not installed by default. To set it up later:
Preview and install:
ai-auditor guard installIt prints the exact change to~/.claude/settings.jsonand asks before writing. It adds two entries underhooks(aUserPromptSubmithook and aPreToolUsehook with"matcher": "*"), each runningnode …/ai-auditor/dist/ai-auditor-hook.jsfrom the installed package. Your existing hooks and settings are kept, and the original file is backed up next to it assettings.json.ai-auditor-backup-<timestamp>.- Only for one project: add
--scope project(writes<project>/.claude/settings.json). - Also install the prompt-coach skill: add
--coach. Add working-style rules to./CLAUDE.md: add--claude-md.
- Only for one project: add
Start a new Claude Code session. Hooks are read when a session starts.
Check it:
ai-auditor guard statusshows where it's installed, the hook's latency, and the last 7 days of activity. The Settings & guard page in the dashboard shows the same, plus recent decisions.Tune it (optional) in
~/.config/ai-auditor/config.json:{ "guard": { "prompts": "annotate", "blockSecretsInPrompts": true, "llmSecretCheck": false, "tools": "on", "askAt": "high", "denyAt": "critical" } }promptscan beannotate(default: guidance for the agent),block(hold vague prompts back so you can reword them) oroff. Settoolstooffto stop checking tool calls.llmSecretCheck: truegives a second opinion on prompts the secret rules can't decide: a credential word followed by a value they didn't flag, like "my password is sunshine". Only those prompts, usually 1–2%, go tollm.modelthroughllm.provider, unredacted, because the value is what gets checked. It costs about $0.0001 per check on Claude Haiku 5.5 and adds about 1 s to those prompts through the API, or about 3 s through"provider": "claude-code". If the check fails or takes longer than 3.5 s, the prompt goes through.After a few days, open Settings & guard → Before and after the guard to see whether prompt scores and at-risk spend improved since you installed it.
To remove it: ai-auditor guard uninstall (shows the diff, asks, backs up). You can also restore the
backup file by hand.
Good to know:
- The hook entries point at the installed package. If you switch Node versions (for example with nvm) or
reinstall ai-auditor somewhere else, run
ai-auditor guard installagain (guard statuswarns when the hook script is missing). - If the guard ever fails, Claude Code carries on as if it weren't there (fail open), and the error is logged
to
~/.cache/ai-auditor/guard.log. That log records decisions, never prompt text. - The guard can block or ask, but never auto-approves: your normal permission prompts always still apply.
Settings audit
ai-auditor settings (or the Settings & guard page) audits your Claude Code settings files: allow rules
that permit arbitrary code (Bash(node -e *)), secrets stored in settings, bypass mode, hooks that send data out,
and missing deny rules for secret files.
How costs are counted
- A prompt is one message that started a model turn, plus every API call made until the next prompt, including the calls of any sub-agents it spawned.
- Cost is computed from logged token counts at Anthropic list prices.
- Claude Code also bills background work it never writes to the transcript (prompt suggestions, summaries, permission checks). Where Claude Code logged its own session cost, the dashboard shows that total, the part traced to prompts, and the remainder as background overhead.
- Some sub-agent calls only log a partial usage snapshot. Their output tokens are estimated from the content they produced and counted as estimated.
- Continued sessions: Claude Code copies earlier history into the new transcript, and its logged cost carries over within one process. Both are counted once, in the session where they happened.
Why token totals differ from Claude Code's /stats
Claude Code's /stats screen can show roughly 2× more tokens than ai-auditor for the same period, with the
same number of sessions. Both read the same transcripts; they count them differently:
- Claude Code writes one API response as several transcript lines, one per content block (thinking, text, each tool call), and every line repeats the full token usage of that response.
/statsadds up every line, so a response with three content blocks is counted three times.- ai-auditor counts each API request once (by
requestId), which is how the API bills.
Example (last 30 days, 2026-09-21 to 2026-10-20):
| | Input | Output | Cache read | Cache write | Total |
|---|---|---|---|---|---|
| Claude Code /stats | 20.8K | 8.9M | 2.7B | 40.8M | 2.8B |
| Every transcript line summed | 20.8K | 8.9M | 2.75B | 40.8M | 2.80B |
| ai-auditor (once per request) | 9.4K | 3.2M | 1.17B | 16.5M | 1.19B |
Summing every line reproduces /stats exactly: 10,776 response lines held only 4,849 API requests (about 2.2
lines each). The per-request count is the one that matches spend: Claude Code's own logged session cost
(totalCostUSD) agrees with it within about 8% (the remainder is background work that never reaches the
transcript), while the /stats token totals would imply about 2.2× that cost. The exact ratio varies with how
many content blocks responses have, so tool-heavy periods differ more.
How far back history goes
Claude Code deletes transcripts older than cleanupPeriodDays (default 30). ai-auditor keeps sessions it has
already indexed after their transcript is deleted, so its history starts from the first time you ran it.
On its first run, if ~/.claude/settings.json doesn't set cleanupPeriodDays, ai-auditor sets it to 365 (backing
the file up first) and says so in the terminal and the dashboard. To undo, remove that line or set your own value;
ai-auditor records that it already ran this step and never changes the setting again. It skips the step when you pass
--root, and leaves any value you already chose alone.
On All time, Spend by model adds the days before ai-auditor's data starts as lighter bars, estimated from
~/.claude/stats-cache.json (hover a model for its monthly breakdown). Because that file counts every transcript line, its
numbers are divided by the ratio between both sources on the days they both cover (per model where there's enough
overlap). They are estimates and are never added to the exact totals.
/stats "All time" reads
~/.claude/stats-cache.json, a running daily total that survives cleanup, so it can reach further back than
ai-auditor. A schema change in an ai-auditor upgrade rebuilds the index from the transcripts still on disk.
Privacy
- The dashboard server listens on
127.0.0.1only, rejects other Host/Origin headers, and requires a per-launch token (included in the linkserveprints). - The AI review is the only thing that sends data out, and it's on by default:
servesends redacted prompt text (with the agent's redacted reply to the turn before) to Claude, through the API or yourclaudeCLI. Never tool output, file contents or secrets in clear.serve --no-aior"llm": { "enabled": false }turns it off, and then nothing leaves your machine. - Help & feedback in the dashboard's bottom-left corner opens the feedback form in a new browser tab. The dashboard sends nothing itself; the form gets only what you type and submit.
- Prompt text, tool inputs and tool-result previews are stored truncated, with secret-shaped strings (API keys, tokens, private keys, connection-string passwords) masked. Findings store masked evidence only.
