/reflect:costfrom reflect
Reports token spend and cost estimates for the reflect background drainer, broken down by cached reads, uncached writes, and IO. Helps identify outlier runs, low cache reuse, and expensive model usage.
Ships in reflect. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Shows what the reflect background drainer is spending: token volume split into
cached (cheap reuse), uncached writes (expensive cache_creation), and
io (input+output), plus a ballpark $est, grouped by day, outcome, model,
or transcript. This is the observability the 2026-05-31 incident lacked — one
drain run burned 41.5M tokens / ~$713 for zero net-new learnings and nothing
surfaced it until a manual backfill.
sonnet, not
opus) after a deploy.Parse the window from the user's request and pass it as --since:
| User says | --since |
|---|---|
| "1 day", "today", "last 24h", (default) | 1d |
| "this week", "last 7 days" | 7d |
| "last hour" | 1h |
| "last month", "30 days" | 30d |
Default to 1d when unspecified.
Locate the cost reporter (prefer the running plugin, else the newest cached
version), then render. The script is reflect_cost.py, shipped in the reflect
plugin's scripts/.
WINDOW="1d" # ← substitute from the table above
# Resolve reflect_cost.py robustly across deploy layouts.
COST_PY=""
for cand in \
"${CLAUDE_PLUGIN_ROOT:-}/plugin/scripts/reflect_cost.py" \
$(ls -t "$HOME"/.claude/plugins/cache/*/reflect/*/plugin/scripts/reflect_cost.py "$HOME"/.claude/plugins/cache/*/reflect/*/scripts/reflect_cost.py 2>/dev/null); do
if [ -n "$cand" ] && [ -f "$cand" ]; then COST_PY="$cand"; break; fi
done
if [ -z "$COST_PY" ]; then
echo "reflect_cost.py not found — install/update the reflect plugin (v4+):"
echo " claude plugin update reflect@ainb-reflect-memory"
exit 1
fi
# Headline: by outcome (where the spend goes), then model (cheap vs expensive),
# then the top transcripts (find the outlier).
python3 "$COST_PY" --since "$WINDOW" --by outcome
echo
python3 "$COST_PY" --since "$WINDOW" --by model
echo
python3 "$COST_PY" --since "$WINDOW" --by transcript --top 10
echo
# Writer health (M2): each run's output classification — a healthy drain is
# all `valid`; prose/idle/poisoned/malformed rows mean the writer is drifting
# (3 consecutive invalids poison the transcript as writer_drift).
python3 "$COST_PY" --since "$WINDOW" --by writer
echo
# Recall quality (A4): the followup-rate diagnostic. A "followup" = the same
# session searched again within the window (default 30s) with a DIFFERENT
# query and got a fully DISJOINT result set — i.e. the first recall didn't
# satisfy. High rate = tune rerank weights / graph arm budget / OOD threshold.
python3 "$COST_PY" --since "$WINDOW" --followup
echo
# Subscription quota (M3): per-window rate-limit snapshot the drainer ingested
# from its own claude -p runs, plus whether the writer gate is open or closed.
# A CLOSED gate means drains are deferred (reason=quota_near_limit) — queue
# entries are retained and replay automatically once the quota recovers.
python3 "$COST_PY" --quota
For a machine-readable view, add --json.
recall followup rate — last 7d
searches tracked : 42
followups : 6 (re-search within 30s, disjoint results)
followup rate : 14%
RECALL_FOLLOWUP_WINDOW_SECONDS (default 30).The drainer only began recording the full token envelope in v4. Older cost
events carry only outcome (no tokens/model), so the split shows 0.
Reconstruct the real numbers from the raw session logs with the backfill — it
scans ~/.claude/projects, finds the reflect runs, and sums their usage into a
separate drain-cost-backfill.jsonl (which reflect_cost.py reads alongside
the live log):
BACKFILL_PY="$(dirname "$COST_PY")/archive/backfill_costs.py"
python3 "$BACKFILL_PY" --since "$WINDOW" \
--projects-dir "$HOME/.claude/projects" \
--state-dir "${REFLECT_STATE_DIR:-$HOME/.reflect}"
# then re-run the reflect_cost.py commands above
outcome runs tokens cache_rd cache_wr io $est
ok 48 120M 95M 18M 7.0M 220.40
partial_max_turns 3 40M 30M 8M 2.0M 70.10
cost_usd from claude -p where recorded, else an
order-of-magnitude estimate from token buckets × ballpark list prices. Not a bill.--outlier-tokens (default 5M). One
flagged transcript is usually where a spend spike lives.Then summarize for the user in one or two lines: total tokens, the cached vs uncached split, the model, the $est, and call out any outlier transcript.
claude plugin update reflect@ainb-reflect-memory and restart.? and 0 tokens — pre-v4 events only; run the
backfill above.REFLECT_STATE_DIR points elsewhere (ls "${REFLECT_STATE_DIR:-$HOME/.reflect}").What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
cost-tracking, token-spend, observability, cache-reuse, drain-monitoring
Other plugins' skills for the same job
npx claudepluginhub stevengonsalvez/ainb-reflect-memory --plugin reflect2 plugins in one repository ship this exact skill · first indexed Jul 18, 2026
10 skills in this plugin
/consolidatereflect:consolidateProject-level memory consolidation. Merges orphaned worktree memory
directories into a single .agents/MEMORY.md for the current project.
Deduplicates, sections, and proposes cleanup of orphan dirs.
Does NOT index into the global knowledge base — use reflect:ingest for that.
/corpusreflect:corpusBuild a long-lived, filtered SLICE of the global learnings KB and answer a question-set over it ("ask the auth subsystem", "ask the migration log"). Unlike /reflect:recall (a fresh hybrid query each time), a corpus is a saved filter snapshotted to disk — prime it once, ask many questions, reprime when the KB drifts. Use when the user wants a durable Q&A session against one filtered area of their own code history rather than a one-shot search./errors-ackreflect:errors-ackTriage and acknowledge entries in the reflect errors sink
(~/.reflect/errors.json). Invoked from the statusline ⚠N badge when
pipeline errors accumulate (drain poison, parser crashes, ingest
failures, hook timeouts).
/exportreflect:exportExport or import the reflect knowledge base as a deterministic,
git-friendly tarball — the learnings markdown corpus plus the reflect.db
rows in one snapshot. Use to back up the KB, move it to another machine,
or restore it: `export` writes the tarball, `import` restores it (with an
optional GraphRAG reindex). Answers "snapshot my reflect KB", "move my
learnings to another machine", or "restore my knowledge base from a backup".
/ingestreflect:ingestThe global knowledge indexer. Harvests ALL memory sources across all tools
(Claude, Codex, Copilot, Gemini) and all project types into the unified
GraphRAG + QMD knowledge base. Archives originals, generates entity sidecars,
and dual-indexes for future retrieval. This is THE command that makes the
knowledge base comprehensive.
/recallreflect:recallRetrieve relevant prior learnings from the global knowledge base. Hybrid
vector + graph search over 170+ indexed learnings, reranked by confidence,
recency, and tag overlap. Use when starting work, debugging a recurring
problem, or before implementing a feature that may have prior art.