Codebase Archaeologist is a CLI-first code intelligence tool that helps you understand an unfamiliar repository without reading every file.
It does deterministic analysis first (scanner, parser, dependency graph, git history), then optionally asks a real LLM to interpret that evidence. Facts never come from the LLM — the LLM only explains what was already measured. Every answer cites file, symbol, and line.
No giant graph to drag around. The graph is internal intelligence translated into answers like direct dependents, potential impact, call path, import chain, related tests, git history.
- You joined a new repo and need to find where authentication, payment, or any feature lives.
- You want to know what breaks if you change
AuthService.authenticate. - You need to trace
POST /loginto the code that handles it. - You want git archaeology: who changed a file, what changed together.
- You want answers that are evidence-grounded, not hallucinated.
# 1. Install (Windows)
.\setup.ps1
.\.venv\Scripts\Activate.ps1
# 2. Try on the included demo (or any repo)
archaeologist scan demo/ecommerce
archaeologist demoLinux / macOS:
./setup.sh
source .venv/bin/activate
archaeologist scan demo/ecommerce
archaeologist demoAll commands have --json for machines and --debug for tracebacks. Without --debug, errors are clean (no stack dump).
You should not need to understand PYTHONPATH, Maturin, PyO3, or Rust bindings.
.\setup.ps1What it does (and never silently ignores errors):
- Checks Python >=3.10 (
python --version) - Checks Git (
git --version) - Detects Rust/Cargo (
cargo --versionor%USERPROFILE%\.cargo\bin\cargo.exe). If missing, it explains: Python fallback can be used — analysis still works, Rust scanner will be skipped. Install Rust from https://rustup.rs/ to enable. - Creates
.venvif not present (python -m venv .venv) - Upgrades pip and runs
pip install -e .(builds Rust extension via Maturin; falls back to Python scanner if Rust missing) - Verifies
python -m archaeologist --helpworks and reports success/failure clearly - Shows next steps
Options:
.\setup.ps1 -NoVenv # install into current interpreter, no .venv
.\setup.ps1 -Dev # also run cargo test + pytestAfter setup:
.\.venv\Scripts\Activate.ps1
archaeologist scan .
# or without activation:
python -m archaeologist scan ../setup.sh
# or
./setup.sh --no-venv --dev
source .venv/bin/activate
archaeologist scan .Manual fallback (if you skip setup scripts):
pip install -e . # builds Rust if cargo available, else fallback
python -m archaeologist --help
cargo test
pytest -qOpen PowerShell in a repository (the demo demo/ecommerce is included, or use your own .):
# 1. Open PowerShell in a repository.
# Example: the demo
Set-Location demo\ecommerce
# or: Set-Location F:\path\to\your\repo
# 2. Run archaeologist scan .
# What it does: walks the repo, counts files/languages/lines, ignores .git/node_modules, detects binaries.
# Expect: REPOSITORY SCAN header, Repository name, Total files, Files by language, Ignored count, file list.
archaeologist scan .
# 3. Run archaeologist search . AuthService
# What it does: deterministic search over filenames, exact symbols, text, imports, git — no LLM.
# Expect: SEARCH "AuthService", Found N results, each line: file:line [reason] symbol score
archaeologist search . AuthService
# 4. Run archaeologist ask . "Where is authentication implemented?"
# What it does: retrieve deterministic evidence -> build constrained prompt -> call LLM (or mock) -> validate citations.
# Expect: [MOCK MODE] banner if no API key, then ANSWER, Evidence (file:line), Confidence, Reasoning.
# With REAL LLM MODE: same but evidence-grounded via OpenAI-compatible API.
archaeologist ask . "Where is authentication implemented?"
# 5. Run archaeologist impact . "services/auth_service.py::AuthService.authenticate"
# What it does: find direct dependents (imports), callers (exact vs possible), tests, git co-change — never claims "will break".
# Expect: CHANGE IMPACT ANALYSIS, Target, HIGH/MEDIUM/LOW, each entry: file + Reason (directly calls / possibly calls / historically changed together)
archaeologist impact . "services/auth_service.py::AuthService.authenticate"AuthService.authenticate is the exact symbol in the demo (check with archaeologist explain . services/auth_service.py).
> archaeologist scan .
============================================================
REPOSITORY SCANgit iinit
============================================================
Repository: ecommerce
Root: F:\Codebase Archaeologist\demo\ecommerce
VCS: git
Total files: 14
Files: 14 (source 12)
Lines: 170
Files (14 shown) ...
services/auth_service.py [Python] 28 lines
> archaeologist search . AuthService
============================================================
SEARCH "AuthService"
============================================================
Found 3 result(s), showing 3:
services/auth_service.py:9 [exact_symbol] score=1.00
AuthService (class)
> archaeologist ask . "Where is authentication implemented?"
[MOCK MODE] deterministic mock - no network call. Set ARCHAEOLOGIST_API_KEY for REAL LLM MODE.
============================================================
ANSWER
============================================================
Based on the retrieved evidence, the question is addressed by services/auth_service.py.
Evidence
--------
services/auth_service.py:1 [text_match]
Confidence: medium
> archaeologist explain . services/auth_service.py
============================================================
EXPLAIN services/auth_service.py
============================================================
File: services/auth_service.py
Kind: file
Location: services/auth_service.py:1-28
Symbols (5)
AuthService [class] services/auth_service.py:9
AuthService.authenticate [method] services/auth_service.py:12
Imports (2)
db.connection (line 3)
Direct Dependents (3)
api/routes.py [imports]
tests/test_auth.py [imports]
> archaeologist impact . "services/auth_service.py::AuthService.authenticate"
============================================================
CHANGE IMPACT ANALYSIS
============================================================
Target: authenticate File: services/auth_service.py
HIGH IMPACT
1. services/auth_service.py Reason: directly calls authenticate
MEDIUM IMPACT
2. api/routes.py Reason: possibly calls authenticate (ambiguous receiver)
3. tests/test_auth.py Reason: directly tests this symbol (authenticate)
> archaeologist trace . "api/routes.py" "services/auth_service.py"
============================================================
TRACE
============================================================
Query: api/routes.py -> services/auth_service.py
Path (1 hops)
1. file:api/routes.py --[imports]--> file:services/auth_service.py
> archaeologist git-log . --file services/auth_service.py
============================================================
GIT HISTORY services/auth_service.py
============================================================
Commits: 2 First: 9a45d036 Authors: Demo Author
9a45d036 Demo Author feat: add authentication and database layerAdd --json to any command for machine output: archaeologist scan . --json | ConvertTo-Json (PowerShell) or archaeologist search . AuthService --json | jq ..
CLI (python -m archaeologist / archaeologist)
|
v
Application / Workflow service (WorkflowService — indexing, search, explain, ask, impact, trace, git)
|
v
Analysis / Retrieval / Impact / Reasoning services (deterministic, no LLM for facts)
|
v
Deterministic repository intelligence (scanner, structure, graph, git, retrieval index)
|
v
LLM interpretation (optional, constrained, evidence-cited)
Pipeline for ask (never reversed):
User question
-> Deterministic retrieval (filename/symbol/text/import/git)
-> Graph/context + snippets + git
-> Evidence collection (capped, scored, deduped)
-> LLM interpretation (system prompt = UNTRUSTED DATA boundaries)
-> Evidence-grounded answer (citations validated against retrieved evidence, confidence from evidence strength)
- CLI (
python/archaeologist/__main__.py) contains no business logic. cli/formatting.pyis stdlib only (norichdependency).structure/graph.pyis internal; users seepotentially calls/directly calls, not raw edge JSON.visualization/is deprecated/isolated, kept for future use.
| Path | Purpose |
|---|---|
src/engine.rs, src/lib.rs |
Rust deterministic scanner + PyO3 bindings |
python/archaeologist/repository/ |
Scanner, file filter, language detector |
python/archaeologist/structure/ |
Parser, IR, symbol/relationship/call extraction, graph |
python/archaeologist/retrieval/ |
Index + search primitives + unified retrieve |
python/archaeologist/reasoning/ |
Provider abstraction, prompt, engine |
python/archaeologist/impact/ |
Analyzer + engine |
python/archaeologist/workflow/ |
IndexManager + WorkflowService |
python/archaeologist/cli/formatting.py |
Terminal formatting (stdlib only) |
python/archaeologist/security/ |
Path traversal, secret redaction, prompt injection hardening |
setup.ps1, setup.sh |
One-command Windows / Linux/macOS setup |
demo/ecommerce/ |
Deterministic demo repo (auth, API, services, DB, tests) |
tests/ |
pytest suite |
The pipeline is deterministic-first. LLM is interpreter, not source of truth.
Environment variables (never hardcode keys, never log them):
| Variable | Required | Default | Purpose |
|---|---|---|---|
ARCHAEOLOGIST_LLM_PROVIDER |
No | mock |
mock (default), echo, openai, anthropic, openrouter |
ARCHAEOLOGIST_API_KEY |
Yes for real | — | API key (also reads OPENAI_API_KEY / ANTHROPIC_API_KEY / OPENROUTER_API_KEY as fallback) |
ARCHAEOLOGIST_MODEL |
No | gpt-4o-mini (openai), claude-3-haiku-20240307 (anthropic), z-ai/glm-5.3-flash (openrouter) |
Model name — not hardcoded per provider, respects ARCHAEOLOGIST_MODEL / .archaeologist_model / ~/.archaeologist/model |
ARCHAEOLOGIST_BASE_URL |
No | https://api.openai.com/v1 (openai), https://api.anthropic.com (anthropic), https://openrouter.ai/api/v1 (openrouter) |
Override endpoint |
MOCK MODE (default, no network):
archaeologist ask . "Where is authentication implemented?"
# Output header: [MOCK MODE] deterministic mock - no network call. Set ARCHAEOLOGIST_API_KEY for REAL LLM MODE.Mock is deterministic, evidence-cited, never pretends to be AI.
REAL LLM MODE — explicit providers:
OpenAI (openai — https://api.openai.com/v1):
$env:ARCHAEOLOGIST_LLM_PROVIDER="openai"
$env:ARCHAEOLOGIST_API_KEY="sk-..." # YOUR_API_KEY
$env:ARCHAEOLOGIST_MODEL="gpt-4o-mini" # default
archaeologist ask . "Where is authentication implemented?"
# Header: [REAL LLM MODE (provider=openai, model=gpt-4o-mini)]Anthropic (anthropic — https://api.anthropic.com, uses x-api-key + anthropic-version):
$env:ARCHAEOLOGIST_LLM_PROVIDER="anthropic"
$env:ARCHAEOLOGIST_API_KEY="sk-ant-..." # YOUR_API_KEY
$env:ARCHAEOLOGIST_MODEL="claude-3-haiku-20240307" # default, or claude-3-5-sonnet-20241022
archaeologist ask . "Where is authentication implemented?"
# Header: [REAL LLM MODE (provider=anthropic, model=claude-3-haiku-20240307)]OpenRouter (openrouter — https://openrouter.ai/api/v1, supports z-ai/glm-5.3-flash):
$env:ARCHAEOLOGIST_LLM_PROVIDER="openrouter"
$env:ARCHAEOLOGIST_API_KEY="sk-or-..." # YOUR_API_KEY, e.g. sk-or-v1-...
$env:ARCHAEOLOGIST_MODEL="z-ai/glm-5.3-flash" # not hardcoded, any OpenRouter ID
archaeologist ask . "Where is authentication implemented?"
# Header: [REAL LLM MODE (provider=openrouter, model=z-ai/glm-5.3-flash)]Or per-command: archaeologist ask . "q" --provider openai --model gpt-4o
Model switching (/model):
archaeologist model # show current (e.g. gpt-4o-mini)
archaeologist model gpt-4o # set for this repo (.archaeologist_model)
archaeologist model openai/gpt-4o-mini # OpenRouter style
archaeologist /model anthropic/claude-3.5-sonnet # slash alias, same
archaeologist model --global openai/gpt-4o # store in ~/.archaeologist/model
archaeologist model --list # known models
archaeologist model --clear # revert to default/env
# Per-call override:
archaeologist ask . "Where is auth?" --model openai/gpt-4o-mini
archaeologist ask . "Explain payment" --model anthropic/claude-3.5-sonnet
# With OpenRouter key (sk-or-v1-...), base URL auto-detects https://openrouter.ai/api/v1:
$env:ARCHAEOLOGIST_API_KEY="sk-or-v1-..."
$env:ARCHAEOLOGIST_LLM_PROVIDER="openai"
archaeologist ask . "Where is auth?" --model openai/gpt-4o-miniIf you set provider to openai without a key:
No real LLM provider is configured.
Set ARCHAEOLOGIST_API_KEY (and optionally ARCHAEOLOGIST_MODEL, ARCHAEOLOGIST_BASE_URL) or use --provider mock.
Current provider=openai but API key is missing. Falling back to MOCK MODE for this run.
The program never silently pretends mock is AI. It explains and falls back with a clear banner.
What is sent to the LLM:
- Only the constrained prompt: system prompt + user question + top N retrieved evidence items (file, symbol, lines, snippet). No full repo dump, no secrets (redacted via
security/secrets.py).
Local / compatible endpoints:
$env:ARCHAEOLOGIST_BASE_URL="http://localhost:11434/v1" # Ollama
$env:ARCHAEOLOGIST_MODEL="llama3"
$env:ARCHAEOLOGIST_API_KEY="ollama" # any non-empty for local
archaeologist ask . "Where is auth?"Provider implementations (python/archaeologist/reasoning/provider.py): OpenAIProvider (Bearer, /chat/completions), AnthropicProvider (x-api-key + anthropic-version, /v1/messages, system as separate field), OpenRouterProvider (OpenAI-compatible + HTTP-Referer/X-Title, supports z-ai/glm-5.3-flash), plus MockProvider/EchoProvider for tests. All use stdlib urllib.request only, timeout 30s, never log API keys, handle missing key / HTTP / network / empty / malformed with clear errors.
Configuration status (new):
archaeologist config show # human: Provider, Model, API Key (Configured/Not set), Base URL, Mode
archaeologist config show --json # machine
# Example:
# Codebase Archaeologist Configuration
# Provider: OpenRouter
# Model: z-ai/glm-5.3-flash
# API Key: Configured
# Base URL: https://openrouter.ai/api/v1Diagnostics (new):
archaeologist doctor # checks Python, git, cargo, scan, LLM config — no network
archaeologist doctor --check-llm # makes a real API request (may spend credits)
# Distinguishes: Configuration detected vs Real API connection successfully verifiedpip install -e . fails with Maturin / Rust error
- Ensure Rust is on PATH:
$env:PATH = "$env:USERPROFILE\.cargo\bin;$env:PATH"thencargo --version. Re-run.\setup.ps1. - If Rust missing, setup explains fallback:
pip install -e . --no-build-isolationstill installs, analysis uses Python fallback scanner. Tests still pass.
python not found / Python <3.10
- Install Python 3.10+ from https://www.python.org/downloads/ and check
python --version. On Linux, trypython3 --versionand usepython3 -m archaeologist.
git: command not found
- Install Git https://git-scm.com/downloads and reopen PowerShell.
archaeologist: command not found after setup
- Activate venv:
.\.venv\Scripts\Activate.ps1(Windows) orsource .venv/bin/activate(Linux). Or usepython -m archaeologist scan .without activation.
No real LLM provider is configured.
- You set
ARCHAEOLOGIST_LLM_PROVIDER=openaibut notARCHAEOLOGIST_API_KEY. Either set the key or run with--provider mock/ unset the provider var.
Repository path does not exist
- Use canonical POSIX relative paths:
services/auth_service.py, not absoluteF:\.... Checkarchaeologist status .and ensure you are in repo root.
Insufficient evidence or AMBIGUOUS TARGET
- Retrieval returned no hits: try broader query (
archaeologist search . AuthService). For ambiguousprocesswith two classes, use exacta.py::Foo.processorservices/auth_service.py::AuthService.authenticate.
Windows path separators \ vs /
- Use POSIX
/in CLI:services/auth_service.py(the tool normalizes\to/internally).
Slow or hangs
- Large repos: graph capped at 400 edges, indexing <5s per 100 files. Check ignored dirs:
archaeologist scan . --json | jq .stats.ignored_files.
Still stuck?
python -m archaeologist scan . --debug # shows full traceback
python -m archaeologist ask . "q" --debug
pytest -q
cargo test| Command | Args | Evidence |
|---|---|---|
scan |
<repo> [--json] [--output FILE] |
Snapshot stats/files |
status |
<repo> [--json] |
ready/stale/error, file/symbol counts |
search |
<repo> <query> [--json] [--limit N] |
filename/symbol/text/import/git |
explain |
<repo> <target> [--json] |
symbols/imports/dependents/git/snippet |
ask |
` [--json] [--provider openai | anthropic |
model / /model |
[MODEL] [--global] [--list] [--clear] [--json] |
view/set LLM model preference |
config |
show [--json] |
Provider, Model, API Key (Configured/Not set), Base URL, Mode |
doctor |
[--check-llm] |
Diagnostics: Python, git, cargo, scan, LLM config; --check-llm verifies real API |
impact |
<repo> <target> [--json] |
HIGH (exact) / MEDIUM (possible/transitive/tests) / LOW |
trace |
<repo> <query> [<to>] [--json] |
graph path imports/calls |
git-log |
<repo> [--file FILE] [--json] [--limit N] |
commits/authors |
demo |
[<repo>] [--json] |
7-step real demo (scan, arch, ask, explain, trace, impact, git) |
Deprecated isolated: visualize (warns), reindex, navigate.
- Facts from deterministic analysis, never LLM.
- LLM never authoritative.
- Every AI explanation cites measured evidence.
- Absence =
UNKNOWN, never guessed. - Evidence language:
Direct dependency detected,Potentially,Historically together, neverwill break.
archaeologist demo # uses demo/ecommerce
archaeologist demo demo/ecommerce # explicit
archaeologist demo . --json # machine-readable
# Legacy:
python demo/demo.py========================================================================================================================================== LINK
==========================================================================================================================================