A tiny, local-first CLI that finds the files your AI coding agent actually needs — and packs them into a focused context.
| 1 | # CLAUDE.md |
| 2 | |
| 3 | Guidance for Claude Code (and similar agents) working on this repository. |
| 4 | |
| 5 | ## What this project is |
| 6 | |
| 7 | `agent-context` is a **small**, local-first Python CLI that: |
| 8 | |
| 9 | 1. Scans a repository (respecting ignores) |
| 10 | 2. Ranks files for a natural-language task with **deterministic heuristics** |
| 11 | 3. Packs a compact markdown context under a token budget |
| 12 | 4. Optionally exposes the same capabilities over a **stdio MCP** server |
| 13 | |
| 14 | It does **not** call external LLMs, embeddings APIs, or databases. |
| 15 | |
| 16 | ## Architecture |
| 17 | |
| 18 | | Module | Role | |
| 19 | |--------|------| |
| 20 | | `cli.py` | argparse CLI (`analyze`, `pack`, `explain`, `tokens`, `mcp`) | |
| 21 | | `scanner.py` | Walk tree, classify files, estimate tokens | |
| 22 | | `ignore.py` | Built-in ignores + `.gitignore` | |
| 23 | | `scoring.py` | Explainable relevance scores | |
| 24 | | `tokens.py` | Approximate tokens ≈ characters / 4 | |
| 25 | | `security.py` | Sensitive path detection + redaction | |
| 26 | | `packer.py` | Budget selection, truncation, markdown | |
| 27 | | `explain.py` | Heuristic repository map | |
| 28 | | `config.py` | Optional `.agent-context.toml` | |
| 29 | | `mcp.py` | Optional JSON-RPC MCP over stdio | |
| 30 | |
| 31 | Package root: `src/agent_context/`. |
| 32 | |
| 33 | ## Commands |
| 34 | |
| 35 | ```bash |
| 36 | agent-context analyze |
| 37 | agent-context pack "task" --tokens 12000 |
| 38 | agent-context explain |
| 39 | agent-context tokens README.md |
| 40 | agent-context mcp |
| 41 | ``` |
| 42 | |
| 43 | Flags of note: `--json`, `--verbose`, `--stdout`, `-o`, `--version`, `--help`. |
| 44 | |
| 45 | ## Testing |
| 46 | |
| 47 | ```bash |
| 48 | pip install -e ".[dev]" |
| 49 | pytest |
| 50 | pytest --cov=agent_context |
| 51 | ``` |
| 52 | |
| 53 | Security tests must keep failing if secrets leak into packed markdown. |
| 54 | |
| 55 | ## Security constraints |
| 56 | |
| 57 | - Never upload repository contents. |
| 58 | - Never execute project code under analysis. |
| 59 | - Never modify or delete analyzed source files. |
| 60 | - Never print raw secrets to stdout. |
| 61 | - Exclude sensitive filenames from context packs; redact likely secret values. |
| 62 | |
| 63 | ## Dependency policy |
| 64 | |
| 65 | Avoid new dependencies unless they are mature, tiny, and clearly better than stdlib. |
| 66 | |
| 67 | **Do not add:** LangChain, LlamaIndex, OpenAI/Anthropic SDKs, embedding clients, vector DBs, ORMs. |
| 68 | |
| 69 | Prefer extending heuristics in `scoring.py` / `security.py` over new frameworks. |
| 70 | |
| 71 | ## Implementation notes |
| 72 | |
| 73 | - Determinism: no randomness; stable-sort ties by path. |
| 74 | - Token counts are estimates — say so in user-facing text. |
| 75 | - `explain` wording must stay hedged (“Detected”, “Likely”, “Potential”). |
| 76 | - MCP stays isolated in `mcp.py`; CLI users should not need MCP concepts. |