A powerful CLI tool that automatically discovers and bundles related source code into a single markdown file, perfect for sharing with LLMs like ChatGPT, Claude, or Cursor AI.
ScanEx = Scan and Export - because that's exactly what it does! π―
I wrote this project because I wanted to copy and paste source code quickly to ask LLMs for help.
While coding with Cursor, or when I want to ask something about my implementation on ChatGPT or Google AI Studio, I have to copy related source code way too many times. I have to search and copy a lot of files manually.
So I decided to implement something where I can just point to a file, and it will automatically scan related files and write it out for me.
That's it. Simple problem, simple solution. Now instead of spending 10 minutes copying files, I just run one command and get everything I need. π―
- π Smart Dependency Detection - Uses tree-sitter to analyze actual imports/requires
- π Directory Tree Visualization - Shows your project structure at a glance
- π Multi-Language Support - Works with 13+ programming languages
- β‘ Fast & Efficient - Lightning-fast dependency resolution
- π Respects .gitignore - Automatically excludes ignored files
- π§ TypeScript/JavaScript Aliases - Resolves path aliases from tsconfig.json
- π Unix-friendly - Pipes naturally with other command-line tools
- π Copy-Ready - Perfect for pasting into AI chat interfaces
npm install -g scanex# Analyze current directory and copy to clipboard (macOS)
scanex | pbcopy
# Save analysis to a file
scanex > my-project.md
# Analyze specific files
scanex --input src/main.js > analysis.md
# Analyze directory with custom output
scanex --input src/ --output docs/codebase.md# Quick copy for ChatGPT/Claude
scanex --input src/components/UserForm.tsx | pbcopy
# Analyze a bug and share context
scanex --input src/utils/api.js --exclude "test|spec" > bug-report.md# Create comprehensive project documentation
scanex --exclude "node_modules|dist|build" > PROJECT_OVERVIEW.md
# Focus on specific modules
scanex --input src/auth/ > auth-module-docs.md# Include all related files for a bug report
scanex --input src/problematic-file.js > bug-context.mdscanex [options]| Option | Description | Example |
|---|---|---|
-i, --input <paths> |
Comma-separated files or directories to analyze | --input src/main.js,lib/utils.js |
-e, --exclude <pattern> |
Regex pattern of paths to ignore | --exclude "test|spec|dist" |
-o, --output <file> |
Write output to specified file instead of stdout | --output documentation.md |
-V, --version |
Display version number | |
--help |
Show help information |
# Analyze entire project
scanex
# Analyze specific directory
scanex --input src/
# Exclude test files and build artifacts
scanex --exclude "test|spec|dist|build|node_modules"# Analyze single file and its dependencies
scanex --input src/main.js
# Analyze multiple specific files
scanex --input src/api.js,src/utils.js,src/types.ts# Unix-style piping
scanex | grep "function" | head -20
# Combine with other tools
scanex --input src/ | wc -l # Count lines
# Save to custom location
scanex --input backend/ --output docs/backend-analysis.mdScanEx intelligently analyzes dependencies across multiple languages:
| Language | Extensions | Features |
|---|---|---|
| JavaScript | .js, .mjs, .cjs |
ES6 imports, CommonJS requires |
| TypeScript | .ts, .tsx |
Path aliases, type imports |
| React/JSX | .jsx, .tsx |
Component imports, hooks |
| Python | .py |
Import statements, relative imports |
| Ruby | .rb |
Require statements, gem dependencies |
| ERB | .html.erb |
Ruby + HTML template analysis |
| CSS/SCSS | .css, .scss, .sass, .less, .styl |
@import, url() references |
| SQL | .sql, .ddl, .dml, .pgsql, .mysql |
Include statements, file references |
| HTML | .html, .htm |
Script/style/link references |
| YAML | .yml, .yaml |
File references, includes |
| JSON | .json |
Configuration file analysis |
| Markdown | .md |
Link and image references |
| Shell | .sh, .bash, .zsh, .fish |
Source statements, script includes |
| Docker | Dockerfile |
COPY/ADD instructions |
ScanEx generates clean, structured markdown:
<directory_tree>
.
βββ src/
β βββ components/
β β βββ Header.tsx
β β βββ Footer.tsx
β βββ utils/
β β βββ api.ts
β βββ main.ts
βββ package.json
</directory_tree>
<codebase>
#### `src/main.ts`
```typescript
import { Header } from './components/Header';
import { apiCall } from './utils/api';
// ... rest of the code
```
#### `src/components/Header.tsx`
```tsx
import React from 'react';
// ... component code
```
</codebase>ScanEx automatically detects and resolves path aliases from:
tsconfig.jsonjsconfig.json
Example tsconfig.json:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["src/*"],
"@components/*": ["src/components/*"]
}
}
}ScanEx automatically respects .gitignore files at any level in your project, so you don't need to worry about including:
node_modules/- Build artifacts (
dist/,build/) - IDE files (
.vscode/,.idea/) - OS files (
.DS_Store)
ScanEx intelligently detects your project root by looking for:
- Git repository (
.gitdirectory) - Package files (
package.json,pyproject.toml,Cargo.toml, etc.) - Fallback to input directory
- Tree-sitter parsing for accurate import detection
- Path alias resolution for TypeScript/JavaScript projects
- Relative import handling across all languages
- Circular dependency detection and handling
We welcome contributions! Please feel free to submit a Pull Request.
# Clone the repository
git clone https://github.com/darkamenosa/scanex.git
cd scanex
# Install dependencies
npm install
# Run locally
node bin/scanex.js --helpThis project is licensed under the MIT License - see the LICENSE file for details.
- Built with tree-sitter for accurate code parsing
- Inspired by the need for better AI-human collaboration in coding
- Thanks to the open-source community for language grammar definitions
Made with β€οΈ for developers who love AI-assisted coding
ScanEx - Because your AI deserves better context π