https://github.com/vaibhav-mattoo/cxt
Command-line tool written in Rust to extract and aggregate project context to clipboard for AI chatbots like ChatGPT or Perplexity 🚀
https://github.com/vaibhav-mattoo/cxt
ai ai-assistant best chatgpt code-sharing developer-experience developer-productivity developer-tools file-aggregation perplexity productivity rust simple terminal tui
Last synced: 4 days ago
JSON representation
Command-line tool written in Rust to extract and aggregate project context to clipboard for AI chatbots like ChatGPT or Perplexity 🚀
- Host: GitHub
- URL: https://github.com/vaibhav-mattoo/cxt
- Owner: vaibhav-mattoo
- License: mit
- Created: 2025-07-02T22:20:10.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2025-08-12T01:33:17.000Z (8 months ago)
- Last Synced: 2025-09-18T03:25:01.818Z (7 months ago)
- Topics: ai, ai-assistant, best, chatgpt, code-sharing, developer-experience, developer-productivity, developer-tools, file-aggregation, perplexity, productivity, rust, simple, terminal, tui
- Language: Rust
- Homepage: https://github.com/vaibhav-mattoo/cxt
- Size: 16.4 MB
- Stars: 19
- Watchers: 0
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-cli-apps-in-a-csv - Context Extractor - Command line tool that aggregates file and directory contents into the clipboard, for providing project context to AI chatbots in the browser like ChatGPT and Perplexity. (<a name="ai"></a>AI / ChatGPT)
- awesome-cli-apps - Context Extractor - Command line tool that aggregates file and directory contents into the clipboard, for providing project context to AI chatbots in the browser like ChatGPT and Perplexity. (<a name="ai"></a>AI / ChatGPT)
README
# cxt - Context Extractor
[](https://crates.io/crates/cxt)
[](https://opensource.org/licenses/MIT)
[](https://github.com/vaibhav-mattoo/homebrew-cxt)
[](https://aur.archlinux.org/packages/cxt)
[](https://github.com/vaibhav-mattoo/cxt/commits)
A command-line tool that aggregates file and directory contents into your clipboard, perfect for providing project context to AI chatbots in your browser like ChatGPT, Perplexity etc.
## Showcase
https://github.com/user-attachments/assets/18fa3c3c-0d87-442e-bb30-cbfe36e0e116
*Watch the demo to see `cxt` in action - interactive file selection and clipboard aggregation*
## Use Case
When you're working in the terminal and need to quickly share your project's code structure and contents with an AI assistant, `cxt` makes it effortless. Instead of manually copying files one by one, you can select multiple files and directories, and `cxt` will aggregate all their contents with clear path headers, giving the AI full context of your project structure.
## Installation
### Universal Install Script
The easiest way to install `cxt` on any system:
```bash
curl -sSfL https://raw.githubusercontent.com/vaibhav-mattoo/cxt/main/install.sh | sh
```
This script will automatically detect your system and install the appropriate binary.
Remember to add `~/.local/bin` to your `$PATH` if prompted by the install script, by adding `export PATH="$HOME/.local/bin:$PATH"` in the end of your shell config(~/.bashrc, ~/.zshrc etc).
### From Cargo
```bash
cargo install cxt
```
### Using homebrew
You can install `cxt` through brew on Linux or macOS by:
```bash
brew tap vaibhav-mattoo/cxt
brew install cxt
```
### On Arch Linux (AUR)
You can install `cxt` directly from the AUR:
```bash
yay -S cxt
# or
paru -S cxt
```
### From Source
```bash
git clone https://github.com/vaibhav-mattoo/cxt.git
cd cxt
cargo install --path .
```
## Quick Start
### Interactive Mode
Launch the interactive file selector:
```bash
cxt
# or
cxt --tui
```
Navigate with arrow keys or `hjkl`, select files/directories with `Space`, and confirm with `c`.
### Command Line Mode
Wildcard functionality is now supported! You can use patterns like "*.py" or "src/**/*.rs".
Copy specific files to clipboard:
```bash
cxt file1.txt file2.py src/
```
## Usage Examples
### Basic Usage
```bash
# Copy a single file to clipboard
cxt main.rs
# Copy multiple files and directories
cxt src/ tests/ README.md Cargo.toml
# Print to stdout and copy to clipboard
cxt -p src/
# Write to a file and copy to clipboard
cxt -w output.txt src/
```
### Path Formatting Options
```bash
# Use relative paths in headers
cxt -r src/
# Disable path headers entirely
cxt -n src/
# Include hidden files when walking directories
cxt --hidden src/
```
### Combining Options
```bash
# Print to stdout with relative paths and copy to clipboard
cxt -p -r src/ tests/
# Write to file with no path headers
cxt -w output.txt -n src/
# Ignore a directory while copying a project
cxt -i bin src/
```
## Interactive TUI Mode
The Terminal User Interface (TUI) provides an intuitive way to browse and select files:
### Navigation
- **Arrow keys** or **hjkl**: Move cursor
- **Space**: Select/unselect file or directory
- **Enter** or **l** or **→**: Open directory
- **Backspace** or **h** or **←**: Go to parent directory
- **c**: Confirm selection and exit
- **q/Ctrl-c**: Quit without selection
### Search Mode
- **/** (forward slash): Enter search mode to find files across the current directory and subdirectories
- **Esc**: Exit search mode and return to normal navigation
- **Enter/Arrow keys**: Switch between search input and result navigation
- **Real-time filtering**: Results update as you type, showing partial matches
- **Smart sorting**: Directories first, then by shortest match length
- **Preserved state**: Search query and results persist when navigating between directories
### TUI Features
- **Visual selection**: Selected items are highlighted
- **Directory expansion**: Selecting a directory includes all files within it
- **Path toggles**: Press `r` to toggle relative paths, `n` to toggle no path headers
## Command Line Options
### Output Options
- `-p, --print`: Print content to stdout (also copies to clipboard)
- `-w, --write `: Write content to specified file
- `-t, --tui`: Launch interactive TUI file selector
### Path Formatting
- `-r, --relative`: Use relative paths in headers
- `-n, --no-path`: Disable file path headers
- `--hidden`: Include hidden files when walking directories
- `-i, --ignore `: Ignore a file or directory (only one allowed)
### Examples
```bash
# Interactive selection
cxt --tui
# Print with relative paths
cxt -p -r src/
# Write to file, no path headers
cxt -w context.txt -n src/ tests/
# Include hidden files
cxt --hidden src/
```
## Output Format
By default, `cxt` adds path headers to distinguish between files:
```
--- File: /path/to/file1.txt ---
Content of file1.txt
--- File: /path/to/file2.py ---
Content of file2.py
```
With `--relative`, paths are shown relative to current directory:
```
--- File: file1.txt ---
Content of file1.txt
--- File: src/file2.py ---
Content of file2.py
```
With `--no-path`, only raw content is included:
```
Content of file1.txt
Content of file2.py
```
## Use Cases
Perfect for providing project context to AI assistants and sharing code snippets with colleagues:
```bash
# Quick project overview
cxt --tui
# Specific files for debugging
cxt -r main.rs error.log
# Full project structure
cxt -r src/ tests/ README.md
```
## License
MIT License - see LICENSE file for details.
## Uninstall
To uninstall `cxt`, you can run the command:
```bash
curl -sSfL https://raw.githubusercontent.com/vaibhav-mattoo/cxt/main/uninstall.sh | sh
```
If you installed the software using a package manager, remove it using the package manager's uninstall command.