A tiny, local-first CLI that finds the files your AI coding agent actually needs — and packs them into a focused context.
| 1 | <p align="center"> |
| 2 | <img src="assets/agent-context-cover.png" alt="agent-context — Give your AI agent a map before it touches your code" width="100%"> |
| 3 | </p> |
| 4 | |
| 5 | # agent-context |
| 6 | |
| 7 | > Give your AI agent a map before it touches your code. |
| 8 | |
| 9 | A tiny, local-first CLI that finds the files your AI coding agent actually needs — and packs them into a focused context. |
| 10 | |
| 11 | No API key. |
| 12 | No cloud. |
| 13 | No embeddings. |
| 14 | No database. |
| 15 | Just your repository. |
| 16 | |
| 17 | [](https://github.com/gitrabbit/agent-context/actions/workflows/test.yml) |
| 18 | [](https://www.python.org/) |
| 19 | [](LICENSE) |
| 20 | |
| 21 | --- |
| 22 | |
| 23 | ## Why |
| 24 | |
| 25 | AI coding agents work better with the *right* files — not every file in the repo. |
| 26 | |
| 27 | A typical project mixes source, tests, docs, build output, lockfiles, assets, and caches. Dumping all of that into an agent wastes tokens and buries the signal. |
| 28 | |
| 29 | `agent-context` scans your repository locally, ranks files for a task, and packs a compact context package you can hand to any coding agent. |
| 30 | |
| 31 | ## Before / After |
| 32 | |
| 33 | ```text |
| 34 | Before |
| 35 | |
| 36 | Repository |
| 37 | │ |
| 38 | └── 428 files |
| 39 | │ |
| 40 | ▼ |
| 41 | AI Agent |
| 42 | │ |
| 43 | ▼ |
| 44 | Too much irrelevant context |
| 45 | |
| 46 | |
| 47 | After |
| 48 | |
| 49 | Repository |
| 50 | │ |
| 51 | ▼ |
| 52 | agent-context |
| 53 | │ |
| 54 | ├── scan |
| 55 | ├── rank |
| 56 | ├── filter |
| 57 | └── pack |
| 58 | │ |
| 59 | ▼ |
| 60 | Relevant context |
| 61 | │ |
| 62 | ▼ |
| 63 | AI Agent |
| 64 | ``` |
| 65 | |
| 66 | ## Features |
| 67 | |
| 68 | - **Zero-config** — works from any repo root with no setup |
| 69 | - **Local-first** — no network calls from the core CLI |
| 70 | - **Deterministic ranking** — explainable heuristics, no LLM required |
| 71 | - **Token budgeting** — approximate estimates (characters ÷ 4) |
| 72 | - **Secret-aware** — sensitive files excluded; likely secrets redacted |
| 73 | - **`.gitignore` + builtins** — skip `node_modules`, `dist`, caches, etc. |
| 74 | - **Binary-safe** — extension + content detection |
| 75 | - **JSON output** — machine-readable for scripts and agents |
| 76 | - **Optional MCP server** — read-only tools over stdio |
| 77 | |
| 78 | ## Installation |
| 79 | |
| 80 | ```bash |
| 81 | pip install -e . |
| 82 | |
| 83 | # or with test extras |
| 84 | pip install -e ".[dev]" |
| 85 | ``` |
| 86 | |
| 87 | Requires Python 3.11+. |
| 88 | |
| 89 | ## Quick Start |
| 90 | |
| 91 | ```bash |
| 92 | cd your-project |
| 93 | |
| 94 | agent-context analyze |
| 95 | agent-context pack "implement JWT refresh token" |
| 96 | agent-context explain |
| 97 | ``` |
| 98 | |
| 99 | ## CLI commands |
| 100 | |
| 101 | | Command | Purpose | |
| 102 | |---------|---------| |
| 103 | | `agent-context analyze [path]` | Repository inventory + token estimates | |
| 104 | | `agent-context pack "task"` | Rank files and write a context package | |
| 105 | | `agent-context explain [path]` | Heuristic repository map | |
| 106 | | `agent-context tokens <file>` | Estimate tokens for one file | |
| 107 | | `agent-context mcp` | Optional read-only MCP server (stdio) | |
| 108 | |
| 109 | Common flags: |
| 110 | |
| 111 | ```bash |
| 112 | agent-context pack "fix auth" --tokens 12000 |
| 113 | agent-context pack "fix auth" -o ./context.md |
| 114 | agent-context pack "fix auth" --stdout |
| 115 | agent-context pack "fix auth" --json |
| 116 | agent-context pack "fix auth" --verbose |
| 117 | agent-context analyze --json |
| 118 | agent-context --help |
| 119 | agent-context --version |
| 120 | ``` |
| 121 | |
| 122 | ## Example output |
| 123 | |
| 124 | Illustrative example (numbers vary by repository): |
| 125 | |
| 126 | ```text |
| 127 | $ agent-context pack "fix authentication middleware" --tokens 12000 |
| 128 | |
| 129 | agent-context |
| 130 | |
| 131 | Task |
| 132 | fix authentication middleware |
| 133 | |
| 134 | Repository |
| 135 | 428 files |
| 136 | 184,320 estimated tokens |
| 137 | |
| 138 | Selected |
| 139 | 7 files |
| 140 | 11,842 estimated tokens |
| 141 | |
| 142 | Top matches |
| 143 | 94 src/auth/middleware.ts |
| 144 | 88 src/auth/session.ts |
| 145 | 81 src/api/auth.ts |
| 146 | 79 tests/auth.test.ts |
| 147 | |
| 148 | Context reduction |
| 149 | ~93.6% |
| 150 | |
| 151 | Written to |
| 152 | .agent-context/context.md |
| 153 | ``` |
| 154 | |
| 155 | Default output path: `.agent-context/context.md` |
| 156 | |
| 157 | ## How ranking works |
| 158 | |
| 159 | No embeddings. No cloud model. Each file gets an explainable score from signals such as: |
| 160 | |
| 161 | | Signal | Typical contribution | |
| 162 | |--------|----------------------| |
| 163 | | Filename match | +30 | |
| 164 | | Path / directory match | +25–33 | |
| 165 | | Content match | up to +20 | |
| 166 | | Symbol match | +15 | |
| 167 | | Related test | +10 | |
| 168 | | Source file | +5 | |
| 169 | | Documentation | +3 | |
| 170 | | Large file | −10 | |
| 171 | | Generated-looking path | −30 | |
| 172 | |
| 173 | With `--verbose`, every selected candidate shows its signal breakdown. |
| 174 | |
| 175 | Ties break by path for deterministic output. |
| 176 | |
| 177 | ## Security |
| 178 | |
| 179 | `agent-context` is local-first. |
| 180 | |
| 181 | - Repository contents are never uploaded to a remote service by the core CLI. |
| 182 | - Sensitive filenames (`.env`, `*.pem`, `credentials.json`, …) are excluded from packed context. |
| 183 | - Likely secret *values* in included files are replaced with `[REDACTED]`. |
| 184 | - The tool does not execute repository code. |
| 185 | - The tool does not modify or delete your source files. |
| 186 | |
| 187 | **Limitations:** redaction is heuristic. It can miss unusual secret formats and may over-redact. Review generated context before sharing it outside your machine. The optional MCP server is also local stdio — treat whichever agent *consumes* the context according to that agent's own privacy model. |
| 188 | |
| 189 | ## MCP / Claude Code |
| 190 | |
| 191 | Optional read-only MCP tools: |
| 192 | |
| 193 | - `analyze_repository` |
| 194 | - `find_relevant_files` |
| 195 | - `build_context` |
| 196 | - `repository_map` |
| 197 | |
| 198 | ```bash |
| 199 | # Claude Code (stdio) |
| 200 | claude mcp add agent-context -- agent-context mcp |
| 201 | ``` |
| 202 | |
| 203 | See [examples/claude-code.md](examples/claude-code.md). |
| 204 | |
| 205 | ## Configuration |
| 206 | |
| 207 | Optional `.agent-context.toml` in the repo root: |
| 208 | |
| 209 | ```toml |
| 210 | [context] |
| 211 | max_tokens = 12000 |
| 212 | |
| 213 | [security] |
| 214 | redact_secrets = true |
| 215 | |
| 216 | [files] |
| 217 | include = ["src/**", "tests/**"] |
| 218 | exclude = ["generated/**"] |
| 219 | ``` |
| 220 | |
| 221 | Configuration is optional. The CLI works with zero config. |
| 222 | |
| 223 | ## Supported repositories / languages |
| 224 | |
| 225 | Language-agnostic by design. Heuristics understand common layouts and extensions for: |
| 226 | |
| 227 | TypeScript / JavaScript, Python, Go, Rust, Java/Kotlin, C/C#, Ruby, PHP, and typical web app trees (`src/`, `app/`, `tests/`, …). |
| 228 | |
| 229 | Stack detection for `explain` is filename/manifest-based (e.g. `package.json`, `pyproject.toml`, `go.mod`) and intentionally cautious. |
| 230 | |
| 231 | ## Architecture |
| 232 | |
| 233 | ```text |
| 234 | src/agent_context/ |
| 235 | cli.py argparse entrypoint |
| 236 | scanner.py discovery + classification |
| 237 | ignore.py builtins + .gitignore |
| 238 | scoring.py deterministic relevance |
| 239 | tokens.py approximate token estimates |
| 240 | security.py secret detection / redaction |
| 241 | packer.py budget selection + markdown |
| 242 | explain.py heuristic repo map |
| 243 | config.py optional TOML |
| 244 | mcp.py optional stdio MCP server |
| 245 | ``` |
| 246 | |
| 247 | Small modules. Standard library first. No AI framework. |
| 248 | |
| 249 | ## Performance philosophy |
| 250 | |
| 251 | - Skip ignored directories early |
| 252 | - Sample huge files instead of loading them wholesale when estimating |
| 253 | - Cache scan metadata for the duration of one command |
| 254 | - No network, no database, no embedding index |
| 255 | |
| 256 | Optimize only when something is measurably slow. |
| 257 | |
| 258 | ## Development |
| 259 | |
| 260 | ```bash |
| 261 | python -m venv .venv |
| 262 | source .venv/bin/activate # Windows: .venv\Scripts\activate |
| 263 | pip install -e ".[dev]" |
| 264 | pytest |
| 265 | ``` |
| 266 | |
| 267 | ## Testing |
| 268 | |
| 269 | ```bash |
| 270 | pytest |
| 271 | pytest --cov=agent_context --cov-report=term-missing |
| 272 | ``` |
| 273 | |
| 274 | Tests cover scanning, ignore rules, scoring, packing, security redaction, CLI commands, and MCP tool wiring. |
| 275 | |
| 276 | ## Roadmap |
| 277 | |
| 278 | - [x] Repository scanner |
| 279 | - [x] `.gitignore` support |
| 280 | - [x] Relevance ranking |
| 281 | - [x] Token budgeting |
| 282 | - [x] Secret redaction |
| 283 | - [x] Context packing |
| 284 | - [x] Repository explanation |
| 285 | - [x] JSON output |
| 286 | - [x] MCP server |
| 287 | - [ ] Tree-sitter symbol extraction |
| 288 | - [ ] Optional semantic ranking |
| 289 | - [ ] Git history signals |
| 290 | - [ ] More agent integrations |
| 291 | |
| 292 | ## Contributing |
| 293 | |
| 294 | Keep the project small. |
| 295 | |
| 296 | 1. Prefer the standard library. |
| 297 | 2. Do not add embedding / LLM / database dependencies for core features. |
| 298 | 3. Never execute project code or phone home. |
| 299 | 4. Add tests for security-sensitive behavior. |
| 300 | 5. Keep CLI output stable and deterministic. |
| 301 | |
| 302 | ## License |
| 303 | |
| 304 | [MIT](LICENSE) |