Point it at any codebase β local or GitHub URL β and ask it anything. It maps the architecture, reads the code, and gives you grounded answers.
Repo Explainer is an agentic AI system built on the Claude Agent SDK. It uses multi-step reasoning and file-system tools to deeply understand any codebase and answer natural language questions about it.
It is built around three pillars:
| Pillar | What it does |
|---|---|
| π€ Agent | Multi-step reasoning agent β reads files, searches code, maps dependencies, synthesizes answers |
| π Eval Harness | Systematic test suite with 8 test cases and 4 weighted metrics to measure answer quality |
| β‘ Optimizer | Automated prompt tuning loop that uses eval scores to iteratively improve the agent |
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CLI Entry Point β
β scripts/run_agent.py β
βββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββΌββββββββββββββββββββββββββββββββ
β Agent Core β
β agent/repo_explainer.py β
β β
β βββββββββββββββ ββββββββββββββββββββββββββββ β
β βSystem Promptβ β Agentic Loop β β
β βagent/ ββββββΆβ send β tool_use β β β
β βprompts.py β β execute β send result β β β
β βββββββββββββββ β repeat β final answer β β
β βββββββββββββββββββββββββββ-β β
ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββΌββββββββββββββββββββββββββββββββ
β Tools Layer β
β agent/tools.py β
β β
β read_file β list_directory β search_code β β
β get_file_tree β detect_language_and_framework β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββΌββββββββββββββββββββββββββββββββ
β Claude API β
β (Anthropic direct or any compatible gateway) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Eval + Optimizer β
β β
β evals/harness.py βββΆ evals/metrics.py β
β β β
β βΌ β
β optimizer/optimizer.py β
β (prompt tuning loop β uses eval scores to improve) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββ
- Python 3.10+
- An API key for Claude (see setup options below)
# Clone the repo
git clone https://github.com/AxaySharma/repo-explainer.git
cd repo-explainer
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
# Set up environment
cp .env.example .env
# Edit .env and fill in your credentials (see options below)The agent uses the Anthropic Python SDK. You can point it at any compatible endpoint.
Get a key from console.anthropic.com.
# .env
ANTHROPIC_API_KEY=sk-ant-your-key-hereGet a key from openrouter.ai. Costs fractions of a cent per run.
# .env
ANTHROPIC_API_KEY=sk-or-your-key-here
ANTHROPIC_BASE_URL=https://openrouter.ai/apiThen in agent/repo_explainer.py set:
model = "anthropic/claude-3.5-haiku"If you have a Claude Pro or Max subscription, you can run scripts as bash tasks from within an active Claude Code session. Claude Code injects its auth into subprocesses it spawns directly:
# Start Claude Code in your project directory
claude
# Then ask Claude Code to run it as a task:
# "Please run: python scripts/run_agent.py --repo evals/fixtures/sample_project --question 'What is the architecture?'"Note: This requires running the command from within the Claude Code session itself, not from a separate terminal window.
python scripts/run_agent.py --repo /path/to/any/repo --question "How does authentication work?"python scripts/run_agent.py --repo https://github.com/any/public-repo --question "What is the overall architecture?"π Repo Explainer Agent
ββββββββββββββββββββββββββββββββββββββββ
π Repo: /path/to/repo
β Question: How does authentication work?
π€ Thinking...
β
Answer:
The authentication system uses JWT tokens issued at /auth/login.
Tokens are validated in auth.py via the decode_token() function,
which is called by the require_auth decorator applied to protected routes.
π Stats: 4 iterations | Tools used: get_file_tree, read_file, search_code
python scripts/run_evals.pypython scripts/run_optimizer.py --iterations 3The agent runs a proper agentic loop β not a single-shot API call:
- Receives repo path or GitHub URL + question
- Always starts with
get_file_tree+detect_language_and_framework - Reads relevant files, searches for patterns
- Synthesizes a grounded answer from actual code it has read
- Stops when it has sufficient context (max 10 iterations)
Tools available:
| Tool | Purpose |
|---|---|
read_file |
Read any file with line numbers |
list_directory |
Browse directory contents |
search_code |
Grep patterns across the codebase |
get_file_tree |
Full ASCII repo structure |
detect_language_and_framework |
Identify stack from config files |
8 test cases run against a sample FastAPI project in evals/fixtures/sample_project/.
Metrics (weighted):
| Metric | Weight | What it measures |
|---|---|---|
| Topic Coverage | 40% | Are expected concepts present in the answer? |
| Hallucination Penalty | 30% | Does the answer contain fabricated information? |
| Answer Length | 15% | Is the answer appropriately detailed? |
| Groundedness | 15% | Did the agent actually read the code to answer? |
A test case passes if overall score β₯ 0.6.
The optimizer runs an automated prompt tuning loop:
baseline eval β identify failed cases β ask Claude to improve system prompt
β re-run evals β keep if better β revert if worse β repeat N times
Cost-efficient by design β uses the fastest available Claude model throughout.
| Run | Pass Rate | Avg Score | Topic Coverage | Groundedness |
|---|---|---|---|---|
| Baseline | 87.5% | 0.853 | 0.834 | 0.963 |
| After Optimization (iter 1) | 100% | 0.952 | 0.984 | 1.000 |
| Ξ Improvement | +12.5% | +0.099 | +0.150 | +0.037 |
The optimizer identified a failure in
framework_detection, improved the system prompt in iteration 1, and recovered to 8/8 passing with a +0.099 score improvement. Further variance across runs is due to LLM non-determinism β a known characteristic of probabilistic models that averaging across multiple runs mitigates. Seeoptimizer/results/for full JSON reports.
- Claude Agent SDK over raw API β proper agentic loop with tool use, not a single-shot prompt
- Compatible with any Claude-compatible endpoint β Anthropic direct, OpenRouter, or Claude Code
- Grounded answers only β agent is instructed never to claim something it has not read in actual code
- GitHub URL support β clones to a temp directory transparently so remote repos work out of the box
- Weighted metrics β hallucination penalty weighted heavily (30%) because a wrong answer is worse than an incomplete one
- Optimizer reverts on regression β keeps the best prompt found, never degrades below baseline
repo-explainer/
βββ agent/
β βββ repo_explainer.py # Core agent + agentic loop
β βββ tools.py # File system tools
β βββ prompts.py # System prompt + templates
β βββ prompts_optimized.py # Best prompt found by optimizer
βββ evals/
β βββ harness.py # Eval runner
β βββ metrics.py # Scoring functions
β βββ test_cases.py # 8 test cases
β βββ fixtures/
β βββ sample_project/ # Sample FastAPI project for testing
βββ optimizer/
β βββ optimizer.py # Prompt tuning loop
β βββ results/ # Before/after JSON reports
βββ scripts/
β βββ run_agent.py # CLI: run the agent
β βββ run_evals.py # CLI: run eval suite
β βββ run_optimizer.py # CLI: run optimizer
βββ tests/
β βββ test_metrics.py # 25 unit tests (all passing)
βββ .env.example
βββ requirements.txt
βββ CONTRIBUTING.md
βββ CHANGELOG.md
βββ README.md
Built with the Claude Agent SDK Β· MIT License