{"id":33185725,"url":"https://github.com/epilande/codegrab","last_synced_at":"2026-01-02T09:25:25.589Z","repository":{"id":285364943,"uuid":"957832864","full_name":"epilande/codegrab","owner":"epilande","description":"✋ Interactive CLI tool for selecting and bundling code into a single, LLM-ready output file","archived":false,"fork":false,"pushed_at":"2025-06-10T05:35:39.000Z","size":250,"stargazers_count":70,"open_issues_count":8,"forks_count":7,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-27T13:51:45.137Z","etag":null,"topics":["ai","artificial-intelligence","bubbletea","bundle","cli","command-line","context","devtools","genai","go","golang","llm","prompt","tui"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/epilande.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-03-31T07:56:24.000Z","updated_at":"2025-06-26T12:19:22.000Z","dependencies_parsed_at":"2025-03-31T10:29:58.757Z","dependency_job_id":"be3f5c99-8d20-4e45-bed3-8a2e3c9c615d","html_url":"https://github.com/epilande/codegrab","commit_stats":null,"previous_names":["epilande/codegrab"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/epilande/codegrab","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epilande%2Fcodegrab","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epilande%2Fcodegrab/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epilande%2Fcodegrab/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epilande%2Fcodegrab/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/epilande","download_url":"https://codeload.github.com/epilande/codegrab/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/epilande%2Fcodegrab/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28071371,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-12-27T02:00:05.897Z","response_time":58,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ai","artificial-intelligence","bubbletea","bundle","cli","command-line","context","devtools","genai","go","golang","llm","prompt","tui"],"created_at":"2025-11-16T05:00:20.100Z","updated_at":"2026-01-02T09:25:25.582Z","avatar_url":"https://github.com/epilande.png","language":"Go","readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003eCodeGrab ✋\u003c/h1\u003e\n\u003c/div\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003cstrong\u003eAn interactive CLI tool for selecting and bundling code into a single, LLM-ready output file.\u003c/strong\u003e\n\u003c/p\u003e\n\n![codegrab-demo](https://github.com/user-attachments/assets/0f7d3e41-d023-4763-aff6-17c6be7c4189)\n\n## ❓ Why?\n\nWhen working with LLMs, sharing code context is essential for getting accurate responses. However,\nmanually copying files or creating code snippets is tedious. CodeGrab streamlines this process by\nproviding a clean TUI (Terminal UI), alongside a versatile CLI (Command-Line Interface). This allows\nyou to easily select files from your project, generate well-formatted output, and copy it directly\nto your clipboard, ready for LLM processing.\n\n## ✨ Features\n\n- 🎮 **Interactive Mode**: Navigate your project structure with vim-like keybindings in a TUI environment\n- 💻 **CLI Mode**: Run non-interactively (`-n` flag) to grab all valid files based on filters, ideal for scripting\n- 🧹 **Filtering Options**: Respect `.gitignore` rules, handle hidden files, apply customizable glob patterns, and skip large files\n- 🔍 **Fuzzy Search**: Quickly find files across your project\n- ✅ **File Selection**: Toggle files or entire directories (with child items) for inclusion or exclusion\n- 📄 **Multiple Output Formats**: Generate Markdown, Plain Text, or XML output\n- ⏳ **Temp File**: Generate the output file in your system's temporary directory\n- 📋 **Clipboard Integration**: Copy content or output file directly to your clipboard\n- 🌲 **Directory Tree View**: Display a tree-style view of your project structure\n- 🌳 **Tree-Only Mode**: Output just the file structure without contents using `-T` flag\n- 🧮 **Token Estimation**: Get estimated token count for LLM context windows\n- 🛡️ **Secret Detection \u0026 Redaction**: Uses [gitleaks](https://github.com/gitleaks/gitleaks) to identify potential secrets and prevent sharing sensitive information\n- 🔗 **Dependency Resolution**: Automatically include dependencies for Go, JS/TS, Python when using the `--deps` flag\n- 🌐 **Remote Git Repo Support**: Analyze remote repositories by passing Git URLs (supports GitHub, GitLab, Bitbucket, SSH, HTTPS)\n\n## 📦 Installation\n\n### Homebrew\n\n```sh\nbrew tap epilande/tap\nbrew install codegrab\n```\n\n### Go Install\n\n```sh\ngo install github.com/epilande/codegrab/cmd/grab@latest\n```\n\n### Binary Download\n\nDownload the [latest release](https://github.com/epilande/codegrab/releases/latest) for your platform.\n\n### Build from Source\n\n```sh\ngit clone https://github.com/epilande/codegrab\ncd codegrab\ngo build ./cmd/grab\n```\n\nThen move the binary to your `PATH`.\n\n## 🚀 Quick Start\n\n1. Go to your project directory and run:\n\n   ```sh\n   grab\n   ```\n\n2. Navigate with arrow keys or \u003ckbd\u003eh\u003c/kbd\u003e/\u003ckbd\u003ej\u003c/kbd\u003e/\u003ckbd\u003ek\u003c/kbd\u003e/\u003ckbd\u003el\u003c/kbd\u003e.\n3. Select files using the \u003ckbd\u003eSpace\u003c/kbd\u003e or \u003ckbd\u003eTab\u003c/kbd\u003e key.\n4. Press \u003ckbd\u003eg\u003c/kbd\u003e to generate output file or \u003ckbd\u003ey\u003c/kbd\u003e to copy contents to clipboard.\n\nCodeGrab will generate `codegrab-output.md` in your current working directory (on macOS this file is automatically copied to your clipboard), which you can immediately send to an AI assistant for better context-aware coding assistance.\n\nhttps://github.com/user-attachments/assets/48f245f4-695d-4cea-8fc0-4b0158bb46a5\n\n## 🎮 Usage\n\n```sh\ngrab [options] [directory]\n```\n\n### Arguments\n\n| Argument    | Description                                                                     |\n| :---------- | :------------------------------------------------------------------------------ |\n| `directory` | Optional path to the project directory (default: \".\")                           |\n| `git-url`   | Git repository URL (GitHub, GitLab, Bitbucket, SSH, HTTPS) to clone and analyze |\n\n### Options\n\n| Option                   | Description                                                                                                                                                                                          |\n| :----------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |\n| `-h, --help`             | Display help information.                                                                                                                                                                            |\n| `-v, --version`          | Display version information.                                                                                                                                                                         |\n| `-n, --non-interactive`  | Run in non-interactive mode (selects all valid files respecting filters).                                                                                                                            |\n| `-o, --output \u003cfile\u003e`    | Output file path (default: `./codegrab-output.\u003cformat\u003e`).                                                                                                                                            |\n| `-t, --temp`             | Use system temporary directory for output file.                                                                                                                                                      |\n| `-g, --glob \u003cpattern\u003e`   | Include/exclude files and directories using glob patterns. Can be used multiple times. Prefix with '!' to exclude (e.g., `--glob=\"*.{ts,tsx}\" --glob=\"\\!*.spec.ts\"`).                                |\n| `-f, --format \u003cformat\u003e`  | Output format. Available: `markdown`, `text`, `xml` (default: `\"markdown\"`).                                                                                                                         |\n| `-S, --skip-redaction`   | Skip automatic secret redaction via gitleaks (Default: false). WARNING: Disabling this may expose sensitive information!                                                                             |\n| `--deps`                 | Automatically include direct dependencies for selected files (Go, JS/TS).                                                                                                                            |\n| `--max-depth \u003cdepth\u003e`    | Maximum depth for dependency resolution (`-1` for unlimited, default: `1`). Only effective with `--deps`.                                                                                            |\n| `--max-file-size \u003csize\u003e` | Maximum file size to include (e.g., `\"100kb\"`, `\"2MB\"`). No limit by default. Files exceeding the specified size will be skipped.                                                                    |\n| `--theme \u003cname\u003e`         | Set the UI theme. Available: catppuccin-latte, catppuccin-frappe, catppuccin-macchiato, catppuccin-mocha, rose-pine, rose-pine-dawn, rose-pine-moon, dracula, nord. (default: `\"catppuccin-mocha\"`). |\n| `--show-tokens`          | Show the number of tokens for each file in file tree.                                                                                                                                                |\n| `--icons`                | Display Nerd Font icons.                                                                                                                                                                             |\n| `-T, --tree-only`        | Output only file structure without contents. Useful for sharing project layout with LLMs.                                                                                                           |\n\n### 📖 Examples\n\n1. Run in interactive mode (default):\n\n   ```bash\n   grab\n   ```\n\n2. Grab all files in current directory (non-interactive), skipping files \u003e 50kb:\n\n   ```bash\n   grab -n --max-file-size 50kb\n   ```\n\n3. Grab a specific directory interactively including dependencies:\n\n   ```bash\n   grab --deps /path/to/project\n   ```\n\n4. Grab a specific directory non-interactively including all dependencies (unlimited depth):\n\n   ```bash\n   grab -n --deps --max-depth -1 /path/to/project\n   ```\n\n5. Specify custom output file:\n\n   ```bash\n   grab -o output.md /path/to/project\n   ```\n\n6. Generate XML output:\n\n   ```bash\n   grab -f xml -o output.xml /path/to/project\n   ```\n\n7. Filter files using glob pattern:\n\n   ```bash\n   grab -g=\"*.go\" /path/to/project\n   ```\n\n8. Use multiple glob patterns for include/exclude:\n\n   ```bash\n   grab -g=\"*.{ts,tsx}\" -g=\"\\!*.spec.{ts,tsx}\"\n   ```\n\n9. Analyze a remote Git repository:\n\n   ```bash\n   grab https://github.com/user/repo.git\n   ```\n\n10. Analyze a remote repository non-interactively with dependencies:\n\n    ```bash\n    grab -n --deps https://github.com/user/repo.git\n    ```\n\n11. Clone and analyze using SSH:\n\n    ```bash\n    grab git@github.com:user/repo.git\n    ```\n\n12. Output only the project structure (no file contents):\n\n    ```bash\n    grab -T -n\n    ```\n\n## ⌨️ Keyboard Controls\n\n### Navigation\n\n| Action                     | Key                             | Description                                             |\n| :------------------------- | :------------------------------ | :------------------------------------------------------ |\n| Move cursor down           | \u003ckbd\u003ej\u003c/kbd\u003e or \u003ckbd\u003e↓\u003c/kbd\u003e    | Move the cursor to the next item in the list            |\n| Move cursor up             | \u003ckbd\u003ek\u003c/kbd\u003e or \u003ckbd\u003e↑\u003c/kbd\u003e    | Move the cursor to the previous item in the list        |\n| Collapse directory         | \u003ckbd\u003eh\u003c/kbd\u003e or \u003ckbd\u003e←\u003c/kbd\u003e    | Collapse the currently selected directory               |\n| Expand directory           | \u003ckbd\u003el\u003c/kbd\u003e or \u003ckbd\u003e→\u003c/kbd\u003e    | Expand the currently selected directory                 |\n| Go to top                  | \u003ckbd\u003eH\u003c/kbd\u003e or \u003ckbd\u003ehome\u003c/kbd\u003e | Jump to the first item in the list                      |\n| Go to bottom               | \u003ckbd\u003eL\u003c/kbd\u003e or \u003ckbd\u003eend\u003c/kbd\u003e  | Jump to the last item in the list                       |\n| Toggle expand/collapse all | \u003ckbd\u003ee\u003c/kbd\u003e                    | Toggle between expanding and collapsing all directories |\n\n### Search\n\n| Action                 | Key                               | Description                                                 |\n| :--------------------- | :-------------------------------- | :---------------------------------------------------------- |\n| Start search           | \u003ckbd\u003e/\u003c/kbd\u003e                      | Begin fuzzy searching for files                             |\n| Next search result     | \u003ckbd\u003ectrl+n\u003c/kbd\u003e or \u003ckbd\u003e↓\u003c/kbd\u003e | Navigate to the next search result                          |\n| Previous search result | \u003ckbd\u003ectrl+p\u003c/kbd\u003e or \u003ckbd\u003e↑\u003c/kbd\u003e | Navigate to the previous search result                      |\n| Select/deselect item   | \u003ckbd\u003etab\u003c/kbd\u003e / \u003ckbd\u003eenter\u003c/kbd\u003e | Toggle selection of the item under cursor in search results |\n| Exit search            | \u003ckbd\u003eesc\u003c/kbd\u003e                    | Exit search mode and return to normal navigation            |\n\n### Selection \u0026 Output\n\n| Action                       | Key                                | Description                                                                  |\n| :--------------------------- | :--------------------------------- | :--------------------------------------------------------------------------- |\n| Select/deselect item         | \u003ckbd\u003etab\u003c/kbd\u003e or \u003ckbd\u003espace\u003c/kbd\u003e | Toggle selection of the current file or directory                            |\n| Copy to clipboard            | \u003ckbd\u003ey\u003c/kbd\u003e                       | Copy the generated output to clipboard                                       |\n| Generate output file         | \u003ckbd\u003eg\u003c/kbd\u003e                       | Generate the output file with selected content                               |\n| Toggle Dependency Resolution | \u003ckbd\u003eD\u003c/kbd\u003e                       | Enable/disable automatic dependency resolution for Go \u0026 JS/TS (Default: Off) |\n| Cycle output formats         | \u003ckbd\u003eF\u003c/kbd\u003e                       | Cycle through available output formats (markdown, text, xml)                 |\n| Toggle Secret Redaction      | \u003ckbd\u003eS\u003c/kbd\u003e                       | Enable/disable automatic secret redaction (Default: On)                      |\n| Toggle Tree-Only Mode        | \u003ckbd\u003eT\u003c/kbd\u003e                       | Output only file structure without contents (Default: Off)                   |\n\n### View Options\n\n| Action                     | Key                              | Description                                  |\n| :------------------------- | :------------------------------- | :------------------------------------------- |\n| Toggle `.gitignore` filter | \u003ckbd\u003ei\u003c/kbd\u003e                     | Toggle whether to respect `.gitignore` rules |\n| Toggle hidden files        | \u003ckbd\u003e.\u003c/kbd\u003e                     | Toggle visibility of hidden files            |\n| Refresh files \u0026 folders    | \u003ckbd\u003er\u003c/kbd\u003e                     | Reload directory tree and reset selections   |\n| Toggle help screen         | \u003ckbd\u003e?\u003c/kbd\u003e                     | Show or hide the help screen                 |\n| Quit                       | \u003ckbd\u003eq\u003c/kbd\u003e / \u003ckbd\u003ectrl+c\u003c/kbd\u003e | Exit the application                         |\n\n## 🔗 Automatic Dependency Resolution\n\nCodeGrab can automatically include dependencies for selected files, making it easier to share complete code snippets with LLMs.\n\n- **How it works**: When enabled, CodeGrab utilizes [tree-sitter](https://tree-sitter.github.io/tree-sitter/) to parse selected source files, identifying language-specific dependency declarations (like `import` or `require`). It then attempts to resolve these dependencies within your project and automatically includes the necessary files (respecting `.gitignore`, hidden, size, and glob filters).\n- **Supported Languages**:\n  - **Go**: Resolves relative imports and project-local module imports (if `go.mod` is present).\n  - **JavaScript/TypeScript**: Resolves relative imports/requires for `.js`, `.jsx`, `.ts`, and `.tsx` files, including directory `index` files.\n  - **Python**: Resolves relative imports for `.py` files within the project structure.\n- **Enabling**:\n  - **Interactive Mode**: Press \u003ckbd\u003eD\u003c/kbd\u003e to toggle dependency resolution on/off. A `🔗 Deps` indicator will appear in the footer when active. Files added as dependencies will be marked with `[dep]`.\n  - **Non-Interactive Mode**: Use the `--deps` flag.\n- **Controlling Depth**: The `--max-depth` flag controls how many levels of dependencies are included:\n  - `1` (Default): Only includes files directly imported by your initially selected files.\n  - `N`: Includes dependencies up to `N` levels deep.\n  - `-1`: Includes all dependencies recursively (unlimited depth).\n\n![codegrab-deps](https://github.com/user-attachments/assets/db04805c-a0b0-4249-ab48-da3d7b92000c)\n\n## 🌐 Git Repository Support\n\nCodeGrab can directly analyze remote Git repositories without requiring manual cloning. Simply pass a Git URL as the directory argument, and CodeGrab will automatically clone the repository to a temporary directory.\n\n- **Supported URL Formats**:\n  - HTTPS: `https://github.com/user/repo.git` or `https://github.com/user/repo`\n  - SSH: `git@github.com:user/repo.git`\n  - SSH with protocol: `ssh://git@github.com/user/repo.git`\n  - Supports GitHub, GitLab, Bitbucket, and other Git hosting platforms\n- **Efficient Cloning**: Uses shallow cloning (`--depth=1`) to only fetch the latest commit, making it fast and lightweight\n- **Automatic Cleanup**: Temporary directories are automatically cleaned up after processing\n- **Full Feature Support**: All CodeGrab features work with remote repositories (filtering, dependency resolution, secret detection, etc.)\n\n## 🛡️ Secret Detection \u0026 Redaction\n\nCodeGrab automatically scans the content of selected files for potential secrets using [gitleaks](https://github.com/gitleaks/gitleaks) with its default rules. This helps prevent accidental exposure of sensitive credentials like API keys, private tokens, and passwords.\n\n- **Enabled by Default**: Secret scanning and redaction are active unless explicitly disabled.\n- **Redaction Format**: Detected secrets are replaced with `[REDACTED_RuleID]`, where `RuleID` indicates the type of secret found (e.g., `[REDACTED_generic-api-key]`).\n- **Skipping Redaction**: You can disable this feature using the `-S` / `--skip-redaction` flag when running the command, or by pressing \u003ckbd\u003eS\u003c/kbd\u003e in the interactive TUI. Use this option with caution, as it may expose sensitive information in the output.\n\n## 🎨 Themes\n\nCodeGrab comes with several built-in themes:\n\n- Catppuccin (Latte, Frappe, Macchiato, Mocha)\n- Dracula\n- Nord\n- Rosé Pine (Main, Moon, Dawn)\n\nSelect a theme using the `--theme` flag:\n\n```sh\ngrab --theme dracula\n```\n\n## 📄 Output Formats\n\n### Markdown (Default)\n\n```sh\ngrab --format markdown\n```\n\n#### Example Output\n\n````md\n# Project Structure\n\n```\n./\n└── internal/\n    ├── filesystem/\n    │   ├── filter.go\n    │   ├── gitignore.go\n    │   └── walker.go\n    └── generator/\n        └── formats/\n            ├── markdown.go\n            └── registry.go\n```\n\n# Project Files\n\n## File: `internal/filesystem/filter.go`\n\n```go\npackage filesystem\n\nimport (\n    \"path/filepath\"\n    \"strings\"\n)\n\n// ... rest of the file content\n```\n````\n\n### Plain Text\n\n```sh\ngrab --format text\n```\n\n#### Example Output\n\n```\n=============================================================\nPROJECT STRUCTURE\n=============================================================\n\n./\n└── internal/\n    ├── filesystem/\n    │   ├── filter.go\n    │   ├── gitignore.go\n    │   └── walker.go\n    └── generator/\n        └── formats/\n            ├── markdown.go\n            └── registry.go\n\n\n=============================================================\nPROJECT FILES\n=============================================================\n=============================================================\nFILE: internal/filesystem/filter.go\n=============================================================\n\npackage filesystem\n\nimport (\n    \"path/filepath\"\n    \"strings\"\n)\n\n// ... rest of the file content\n```\n\n### XML\n\n```sh\ngrab --format xml\n```\n\n#### Example Output\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\u003cproject\u003e\n  \u003cfilesystem\u003e\n    \u003cdirectory name=\".\"\u003e\n      \u003cdirectory name=\"internal\"\u003e\n        \u003cdirectory name=\"filesystem\"\u003e\n          \u003cfile name=\"filter.go\"/\u003e\n          \u003cfile name=\"gitignore.go\"/\u003e\n          \u003cfile name=\"walker.go\"/\u003e\n        \u003c/directory\u003e\n        \u003cdirectory name=\"generator\"\u003e\n          \u003cdirectory name=\"formats\"\u003e\n            \u003cfile name=\"markdown.go\"/\u003e\n            \u003cfile name=\"registry.go\"/\u003e\n          \u003c/directory\u003e\n        \u003c/directory\u003e\n      \u003c/directory\u003e\n    \u003c/directory\u003e\n  \u003c/filesystem\u003e\n  \u003cfiles\u003e\n    \u003cfile path=\"internal/filesystem/filter.go\" language=\"go\"\u003e\u003c![CDATA[\npackage filesystem\n\nimport (\n    \"path/filepath\"\n    \"strings\"\n)\n\n// ... rest of the file content\n]]\u003e\u003c/file\u003e\n    \u003c!-- Additional files --\u003e\n  \u003c/files\u003e\n\u003c/project\u003e\n```\n","funding_links":[],"categories":["\u003ca name=\"programming\"\u003e\u003c/a\u003eProgramming"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fepilande%2Fcodegrab","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fepilande%2Fcodegrab","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fepilande%2Fcodegrab/lists"}