gnaw is a powerful context engineering tool designed to ingest codebases and format them for Large Language Models. Whether you are manually copying context for a chat assistant, building AI agents via Python, or wiring up a browser extension over REST, gnaw streamlines the context preparation process.
⚡ Quick Install
Cargo
The crates.io package is gnaw-ctx; the installed binary is gnaw.
To enable optional Wayland support (e.g., for clipboard integration on Wayland-based systems), use the wayland feature flag:
Python bindings 🐍
Built with PyO3/maturin. Not yet published to PyPI — build from source (see Alternative Installation).
🚀 Quick Start
Once installed, generating a prompt from your codebase is as simple as pointing the tool to your directory.
Basic Usage: Generate a prompt from the current directory and copy it to the clipboard.
Save to file:
🌐 Ecosystem
gnaw is more than just a CLI tool. It is a complete ecosystem for codebase context.
| 🧱 Core Library | 💻 CLI / TUI | 🐍 Python | 🌐 REST | 🤖 MCP |
|---|---|---|---|---|
gnaw-core — the internal, high-speed library responsible for secure file traversal, respecting .gitignore rules, and structuring Git metadata. |
Designed for humans, featuring both a minimal CLI and an interactive TUI. Generate formatted prompts, track token usage, and output the result to your clipboard or stdout. | Fast Python bindings to the Rust core. Ideal for AI agents, automation scripts, or deep integration into RAG pipelines. | A planned axum-based REST interface, enabling browser extensions and other clients to request well-structured context over HTTP. | A planned MCP server, letting agentic applications call gnaw as a tool to read your codebase without bloating their context window. |
📚 Documentation
Check our online documentation for detailed instructions.
✨ Features
gnaw transforms your entire codebase into a well-structured prompt for large language models. Key features include:
- Terminal User Interface (TUI): Interactive terminal interface for configuring and generating prompts
- Smart Filtering: Include/exclude files using glob patterns and respect
.gitignorerules - Flexible Templating: Customize prompts with Handlebars templates for different use cases
- Syntax-Aware Compression: Chunk on whole functions and types via tree-sitter, not arbitrary line cuts
- Token Tracking: Track token usage to stay within LLM context limits
- Git Integration: Include diffs, logs, and branch comparisons in your prompts
- Blazing Fast: Built in Rust for high performance and low resource usage
Stop manually copying files and formatting code for LLMs. gnaw handles the tedious work so you can focus on getting insights and solutions from AI models.
Alternative Installation
Refer to the documentation for detailed installation instructions.
Binary releases
Download the latest binary for your OS from Releases.
Source build
⭐ Star Gazing
🍴 Forked from code2prompt
gnaw began as a fork of code2prompt by Mufeed VH and contributors, and owes its foundation to that project. It carries forward the core idea — turning a codebase into a single, well-structured LLM prompt — while taking the tooling in a Rust-native direction and adding new capabilities:
- Syntax-aware compression — chunk on whole functions and types via tree-sitter, rather than arbitrary line cuts
- REST interface (planned) — an axum surface so browser extensions and other clients can request context over HTTP
- MCP server (planned) — expose gnaw as a tool for agentic applications
The original code2prompt is MIT licensed. gnaw is dual-licensed under MIT OR Apache-2.0; portions derived from code2prompt remain under the upstream MIT license, whose copyright notice is preserved. See License for details.
📜 License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Portions of this project are derived from code2prompt and remain under its original MIT license; that copyright notice is retained in LICENSE-MIT.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
Liked the project?
If you liked the project and found it useful, please give it a :star:!
👥 Contribution
Ways to contribute:
- Suggest a feature
- Report a bug
- Fix something and open a pull request
- Help document the code
- Spread the word