rag-debug

rag-debug is a command for Claude Code from kumaran-is/claude-code-onboarding. It costs 15 tokens per session (1,552 once invoked), scanned A, original, MIT.

A diagnostic process for finding where a RAG system loses the information needed to answer a query. RAG, or retrieval-augmented generation, lets an AI answer using retrieved documents.

In plain words
What is it for?
Use it to investigate a specific failing RAG query using its search results, ranking data, final prompt, and expected answer.
Why use it?
It traces a failing answer through parsing, search, ranking, and prompt context to identify the first layer where the correct information disappears.

Command for Claude Code

Written for Claude Code: argument-hint in frontmatter.

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/kumaran-is/claude-code-onboarding/rag-debug
Clone the repo
git clone --depth 1 https://github.com/kumaran-is/claude-code-onboarding

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for rag-debug

README.md
[![agentmods](https://agentmods.dev/badge/commands/kumaran-is/claude-code-onboarding/rag-debug.svg)](https://agentmods.dev/commands/kumaran-is/claude-code-onboarding/rag-debug)
Your own site
<a href="https://agentmods.dev/commands/kumaran-is/claude-code-onboarding/rag-debug"><img src="https://agentmods.dev/badge/commands/kumaran-is/claude-code-onboarding/rag-debug.svg" alt="Measured on agentmods" height="20"></a>
Per session 15 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,552 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00015 $0.01552
Opus 5 $0.00008 $0.00776
Sonnet 5 $0.00003 $0.00310
Haiku 4.5 $0.00002 $0.00155

Measured 2d ago against content hash 109af75badb3, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade A, and why

rag-debug scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.claude/commands/rag-debug.md · 160 lines

How it starts

The opening of the file, as written. The whole thing — 160 lines — stays where its author put it; the contents beside it link to each section on GitHub.

/rag-debug — Diagnose RAG Failure

Diagnose a specific RAG failure by walking the 9-layer diagnostic chain (playbook §40).

Symptom or failing query: $ARGUMENTS

Phase 1: Get the trace

Ask the user for the full trace of the failing query. You need:

  • The exact query as the user typed it
  • Filters applied (tenant, ACL, version, date range)
  • All retriever outputs with scores (dense top-N, sparse top-N)
  • RRF fused result
  • Reranker output (pre and post)
  • Final context packed into the LLM prompt
  • The LLM's response
  • What the correct answer should have been, and which document(s) should have produced it

If the user can't produce this — that's already a finding: they don't have audit logs (§39.2). Recommend that first. Then ask what they CAN reproduce manually.

Phase 2: Walk the chain

Walk these layers IN ORDER. The first layer where the right chunk goes missing is the root cause. Do not skip ahead.

Layer 1: Parsing / Ingestion

Question: Does the answer text exist in ANY chunk in the index?

Action: search the index directly (BM25 or substring) for distinctive phrases from the expected answer. If you can't find it, the problem is parsing or ingestion.

  • ❌ Not in any chunk → stop here. Root cause is Layer 1. Recommend parser audit (§6.1), OCR check, chunk quality scoring (§9.11).
  • ✅ Found in a chunk → continue to Layer 2.

Layer 2: Chunking

Question: Is the full answer in a SINGLE chunk, or split across chunks?

  • ❌ Split across chunks (e.g., the condition is in one chunk, the rule in another) → stop here. Root cause is chunking. Recommend document-aware + parent-child (§9.4), overlap, or recursive retrieval (§9.12).
  • ✅ Single chunk → continue to Layer 3.

Layer 3: Filtering

Question: Did filters wrongly exclude the right chunk?

Action: replay the query WITHOUT filters. Does the right chunk appear?

  • ❌ Right chunk only appears without filters → stop here. Root cause is filtering. Check tenant filter (should not exclude), version filter (effective_to), access_level mismatch.
  • Special case: post-filter on top-k → critical fix (§20.2)
  • ✅ Right chunk found with filters → continue to Layer 4.

Read the full file on GitHub · 160 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 160 lines · 15 tokens per session scan A 109af75badb3

Subscribe to this mod's changes

rag-debug is a command published in the GitHub repository kumaran-is/claude-code-onboarding (35 stars, last pushed 2mo ago), licensed MIT. It adds 15 tokens to every session and 1,552 once invoked, about $0.0001 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-09-03.