gnaw is a powerful code ingestion tool designed to generate prompts for code
analysis, generation, and other tasks. It works by traversing directories,
building a tree structure, and gathering information about each file.
It simplifies the process of combining and formatting code, making it easy to
analyze, document, or refactor code using LLMs.
You can use gnaw the following ways:
Core
Core library, blazingly fast code ingestion
CLI / TUI
Command line and terminal interface specially designed for humans
Python
Python bindings for AI agents and automation scripts
REST
REST interface for browser-extension integration (planned)
Glob Pattern Filtering: Include or exclude specific files and directories using glob patterns.
Customizable Templates: Tailor prompt generation with Handlebars templates.
Token Counting: Analyze token usage and optimize for LLMs with varying context windows.
Secret Scanning: Catch API keys, tokens, and private keys before they leak into a prompt — warn, redact, or block.
Git Integration: Include Git diffs and commit messages in prompts for code reviews.
Respects .gitignore: Automatically ignores files listed in .gitignore to streamline prompt generation.
Shell Completion: Tab-complete flags, values, and template names in bash, zsh, and fish.
Why gnaw?
Save Time: Automates the process of traversing a codebase and formatting files for LLMs, and avoids repetitive copy-pasting of code.
Improve Productivity: Provides a structured and consistent format for code analysis, and helps identify bugs, refactor code, and write documentation faster.
Handle Large Codebases: Designed to work seamlessly with large codebases, respecting context limits of LLMs.
Customizable Workflows: Flexible options for filtering files, using templates, and generating targeted prompts.
Example Use Cases
Code Documentation: Automatically generate documentation for public functions, methods, and classes.
Bug Detection: Find potential bugs and vulnerabilities by analyzing your codebase with LLMs.
Refactoring: Simplify and optimize code by generating prompts for code quality improvements.
Learning and Exploration: Understand new codebases by generating summaries and detailed breakdowns.
Git Commit and PR Descriptions: Generate meaningful commit messages and pull request descriptions from Git diffs.
Safe Sharing: Scrub secrets out of context before pasting it into a chat, so credentials never leave your machine.