Context extraction and codebase analysis tool. Generate precise, token-efficient context for any AI agent or workflow.
# Extract - analyze recent changes
dex HEAD~5..HEAD --format markdown
# Distill - compress entire codebase
dex distill .
# Visual API tree of your codebase structure
dex tree src/ --show-types --show-params
# Extract and track changes with snapshots
dex snapshot create "pre-refactor"
dex HEAD~3..HEAD --format xml --clipboard
# Distill entire codebase into token-efficient format
dex distill . --ai-action audit
Result: Precise context extraction with 90% token reduction, AI-powered file selection, and comprehensive codebase analysis.
DEX transforms how you work with AI agents by solving the context engineering problem:
- π― Surgical Precision: Extract exactly what matters, not everything
- π Token Efficiency: 90% reduction in token usage through smart compression
- π³ Visual Understanding: Beautiful API trees and codebase structure visualization
- β‘ Multi-Format: Output optimized for any AI agent or workflow
# Install
npm install -g dex
# Initialize in your project
cd your-project
dex init
dex -c
Git-Based Extraction
dex # Current uncommitted changes
dex -s # Staged changes only
dex HEAD~5..HEAD # Last 5 commits
dex --since "2 hours ago" # Time-based extraction
dex -p "src/api/**" -t ts # Filter by path and type
Interactive Selection
dex --select # Visual file picker
dex --select --format json # Interactive + custom format
API Trees
dex tree src/ # Visual API structure
dex tree src/ --show-types # Include function signatures
dex tree src/ --format outline # Different view format
dex tree . --group-by type --show-types # Organized by type with details
Example Output:
π³ Generating API tree...
π¦ Project API Structure
βββ π src/
β βββ π main.ts
β β βββ π startServer() β Promise<Server>
β βββ π core/
β β βββ π context-engine.ts
β β β βββ π class ContextEngine
β β β βββ βββ π§ constructor(options: EngineOptions)
β β β βββ βββ π€ extract(path: string) β Promise<Context>
β β β βββ βββ π validateInput(input: any) β boolean
β β βββ π git-extractor.ts
β β βββ π class GitExtractor
β β βββ βββ π€ getDiff(range: string) β Promise<GitDiff[]>
β β βββ βββ π€ getCurrentBranch() β Promise<string>
β βββ π routes/
β β βββ π auth.ts
β β β βββ π€ POST /auth/login
β β β βββ π€ POST /auth/logout
β β β βββ π€ GET /auth/profile
β β βββ π api.ts
β β βββ π€ GET /api/health
β β βββ π€ POST /api/extract
β βββ π types/
β βββ π index.ts
β βββ π· interface EngineOptions
β βββ π· interface GitDiff
β βββ π· type OutputFormat = 'xml' | 'json' | 'markdown'
π Summary: 15 files, 23 exports, 8 classes, 12 functions, 5 interfaces
Distillation
dex distill . # Compress entire codebase
dex distill src/ # Distill specific directory
dex distill . --since HEAD~10 # Only recent changes
Example Output:
ποΈ Distilling codebase...
π Processing 89 files...
β‘ Parallel extraction: 4 workers
π― Depth: public APIs only
# Codebase Distillation: MyApp
## Architecture Overview
- **Type**: Node.js/TypeScript web application
- **Structure**: Modular with core engine + plugin system
- **Entry Point**: src/main.ts β Express server on port 3000
- **Key Dependencies**: Express, TypeScript, simple-git
## Core Modules
### Context Engine (src/core/)
```typescript
// Primary extraction engine
class ContextEngine {
extract(path: string): Promise<ExtractedContext>
applyFilters(files: string[]): string[]
}
// Git operations wrapper
class GitExtractor {
getDiff(range: string): Promise<GitDiff[]>
getFileContents(path: string): Promise<string>
}
- Original size: 847 files, ~2.1M characters
- Distilled size: 89 key files, ~180k characters
- Compression ratio: 91.4% reduction
- Estimated tokens: 45k β 4.2k (90% savings)
β Distillation saved to .dex/dex.distill.myapp.md
### π File Combination
**Multi-File Context**
```bash
dex combine src/auth/ src/api/ # Combine directories
dex combine file1.ts file2.ts # Combine specific files
dex combine . -t "*.config.*" # Combine by pattern
dex combine -s # Combine all staged files (full content)
dex combine -s -c # Copy staged files to clipboard
Staged Files Integration
The -s, --staged
flag provides full file content of all staged files (not just diffs like dex -s
), making it perfect for comprehensive code review or sharing complete staged changes with AI agents. Use -c
to copy directly to clipboard.
Work Session Management
dex session start "feature-auth" # Start tracking work
dex session status # Check current session
dex session end # End and summarize
Provider Setup
# Set your preferred AI provider
export ANTHROPIC_API_KEY=your-key # For Claude
export OPENAI_API_KEY=your-key # For GPT models
export GROQ_API_KEY=your-key # For Groq models
# Configure in .dexrc
dex config set ai.provider anthropic
dex config set ai.model claude-3-sonnet
Built-in Templates
dex --prompt-template security # Security-focused analysis
dex --prompt-template performance # Performance optimization
dex --prompt-template refactor # Refactoring guidance
dex --prompt-template testing # Test coverage analysis
Custom Prompts
dex prompts list # View available templates
dex --prompt "Custom analysis text" # Direct prompt text
Format Options
dex --format xml # Structured XML (default)
dex --format markdown # Clean markdown
dex --format json # Structured JSON
dex --format text # Plain text
Output Destinations
dex --clipboard # Copy to clipboard
dex --output custom.md # Save to specific file
dex distill . --stdout # Print to console
Path & Type Filters
dex -p "src/components/**" # Specific paths
dex -t ts,tsx,js # File types
dex --full "*.config.*" # Include full files matching pattern
dex --exclude "*.test.*" "*.spec.*" # Exclude patterns
Smart Filtering
dex --include-untracked # Include untracked files
dex --staged # Only staged files
dex --since HEAD~10 # Only recent changes
Create .dexrc
in your project root:
dex config set ai.provider openai
dex config set ai.model gpt-4
dex config set defaults.format markdown
dex config list # View all settings
DEX automatically saves outputs to .dex/
with descriptive filenames:
.dex/
βββ dex.extract.current.txt # Current changes
βββ dex.extract.staged.txt # Staged changes
βββ dex.distill.src.txt # Distilled codebase
βββ dex.tree.src.txt # API tree visualization
βββ dex.combine.auth-api.txt # Combined files
# 2. Analyze existing code
dex tree src/users/ --show-types
# 3. Extract relevant context for implementation
dex generate "implement user profile editing" --max-files 15
# 4. Track progress with snapshots
dex snapshot create "profiles-implemented"
# 5. Generate final context for review
dex session end
Example Session Flow:
$ dex session start "user-profiles"
π Session started
ID: sess_1704123456
Branch: feature/user-profiles
Starting commit: a1b2c3d
Description: user-profiles
Session now tracking ALL changes (committed and uncommitted)
Use 'dex' to package everything you've worked on
$ dex tree src/users/ --show-types
π³ Generating API tree...
π¦ User System APIs
βββ π src/users/
β βββ π user.model.ts
β β βββ π class User extends BaseModel
β β βββ βββ π§ constructor(data: UserData)
β β βββ βββ π€ updateProfile(data: ProfileData) β Promise<User>
β β βββ βββ π€ uploadAvatar(file: File) β Promise<string>
β β βββ βββ π validateProfile(data: any) β ValidationResult
β βββ π user.service.ts
β βββ π€ getUserById(id: string) β Promise<User>
β βββ π€ updateUserProfile(id: string, data: ProfileData) β Promise<User>
β βββ π€ deleteUser(id: string) β Promise<void>
$ dex session end
βΉοΈ Session ended
Duration: 2h 34m
Description: user-profiles
π Session Summary:
π’ Added: 4 files
π‘ Modified: 7 files
π Total: +156 lines, -23 lines
β
Full session context saved to .dex/dex.session.user-profiles.xml
# 2. Focus on authentication components
dex -p "src/auth/**" --prompt-template security
# 3. Get visual overview of API surface
dex tree src/ --include-private --show-params
# 1. Extract recent changes
dex HEAD~20..HEAD --prompt-template performance
# 2. Focus on hot paths
dex combine src/api/ src/db/ --prompt-template performance
# 3. Generate comprehensive performance review
dex distill . --ai-action analyze
DEX is built for token efficiency:
- Smart Extraction: Only relevant changes and context
- AI Selection: Intelligent file prioritization
- Compression: Advanced distillation algorithms
- Caching: Avoid redundant AI calls
- Snapshots: Track only deltas between states
Typical Results:
- Full codebase: ~150K tokens β ~15K tokens (90% reduction)
- Change extraction: ~50K tokens β ~5K tokens (90% reduction)
- AI file selection: Perfect relevance with minimal tokens
- Node.js: 16.0.0 or higher
- Git: For change tracking and extraction
- AI API Keys: For AI-powered features (optional)
DEX works with any text-based language, with enhanced support for:
- TypeScript/JavaScript
- Python
- Go
- Java
- Rust
- C/C++
- And more via tree-sitter parsing
DEX is open source and contributions are welcome:
- β Star us on GitHub
- π Report bugs
- π‘ Request features
- π§ Submit pull requests
MIT License - see LICENSE for details.
Transform your AI workflow with precision context extraction
npm install -g dex
Context engineering for the AI age