code2prompt
$ code2prompt Community Low Riskcode2prompt traverses repositories respecting .gitignore and turns source trees, code files, and git diffs into structured Markdown, XML, or JSON prompts using Handlebars templates. Supports -t/--template, -f/--filter (include globs), -e/--exclude, --tokens, -d/--diff, and -o/--output.
brew install code2prompt code2prompt is fastest as a local Rust CLI for deterministic codebase packing and token counting; an optional code2prompt MCP server package also exists.
Agent-Readiness Checklist
Static evaluation (not yet probed on this host). Run npm run data:probe locally to capture live verification.
FCRS-1.0 6-Dimension Breakdown
Fast Rust CLI with -F json output, -O - stdout mode, --no-clipboard, glob filtering (-f/-e), and --tokens accounting.
- Supports
-F json,-f/--filter,-e/--exclude,--tokens,-d/--diff, and-O -
Offline read-only traversal respecting .gitignore; only writes to disk when -o/--output is specified, though it lacks built-in secret scanning.
- Offline execution respecting
.gitignorewith explicit-ooutput path
Native Rust binary installable via brew install code2prompt, cargo install code2prompt, and prebuilt releases across macOS, Linux, and Windows.
- Available on Homebrew and crates.io (
code2prompt)
Handlebars templates, git diff/branch inclusion (-d), and built-in tiktoken counting make prompt assembly predictable.
- Built-in Handlebars templating, git diff mode, and token estimation
Well-established MIT-licensed project (mufeedvh/code2prompt) with active community releases.
- Active
mufeedvh/code2promptrepo under MIT
Dedicated documentation site (code2prompt.dev) covering CLI flags, templates, and SDK.
- Official docs at
code2prompt.dev
Security, Auth & Guardrails
Fully offline local CLI; stores no credentials.
100% free and MIT open-source.
# code2prompt Agent Rules - Always pass `--no-clipboard` and `-O -` (or `-o <file>`) in headless environments. - Filter large repos with `-f` / `-e` and check `--tokens` before stuffing output into context.
Agent-Ready Command Recipes
Safe Read-Only Queries
code2prompt . -f "*.rs,*.ts" --tokens format --no-clipboard -O -
Prints a structured prompt for matching files to stdout with formatted token counts without touching the clipboard.
code2prompt . -d -F json --no-clipboard -O -
Outputs prompt metadata, token count, and git diff in JSON format to stdout.
Controlled Writes & Previews
code2prompt . -t prompt-template.hbs -e "dist/*,node_modules/*" -o prompt.md --no-clipboard
Renders a filtered codebase prompt using a custom Handlebars template to prompt.md.
Strengths for Agents
- + Fast Rust execution with
-f/-eglob filtering and--tokenscounting. - + Handlebars
-t/--templateand-d/--diffsupport tailored review prompts. - +
-F jsonand-O -integrate cleanly into agent scripts.
Caveats & Pitfalls
- ! Does not run Secretlint automatically like Repomix; exclude
.envor secret files explicitly. - ! Copies to system clipboard by default unless
--no-clipboardor-ois used.