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