CLI Commands¶
Complete reference for all codebrief commands, options, and usage patterns.
📋 Command Overview¶
codebrief provides six main commands for different types of context generation:
Command | Purpose | Output Format |
---|---|---|
tree | Generate directory structure | Text tree or Rich console |
flatten | Concatenate file contents | Markdown with file separators |
deps | Analyze project dependencies | Markdown with dependency tables |
git-info | Extract Git context information | Markdown with Git status and history |
bundle | Create comprehensive context bundles | Structured Markdown with multiple sections |
hello | Example/test command | Console output |
🌳 tree - Directory Tree Generation¶
Generate visual representations of your project structure.
Basic Usage¶
# Generate tree for current directory
codebrief tree
# Generate tree for specific directory
codebrief tree /path/to/project
# Save tree to file
codebrief tree --output project-structure.txt
Options¶
Option | Short | Type | Description |
---|---|---|---|
--output | -o | Path | Output file path |
--to-clipboard | -c | Flag | Copy output to clipboard (cannot be used with --output) |
--ignore | -i | List[str] | Patterns to ignore (repeatable) |
--help | Show command help |
Examples¶
Output:
Integration with .llmignore¶
The tree command automatically respects .llmignore
patterns:
Configuration Integration¶
Use pyproject.toml
for default settings:
[tool.codebrief]
default_output_filename_tree = "docs/structure.txt"
global_exclude_patterns = ["*.log", "tmp/"]
📄 flatten - Code Flattening¶
Concatenate multiple files into a single, LLM-friendly document.
Basic Usage¶
# Flatten all default file types
codebrief flatten
# Flatten specific directory
codebrief flatten src/
# Flatten with custom patterns
codebrief flatten . --include "*.py" --include "*.md"
Options¶
Option | Short | Type | Description |
---|---|---|---|
--output | -o | Path | Output file path |
--to-clipboard | -c | Flag | Copy output to clipboard (cannot be used with --output) |
--include | -inc | List[str] | Include patterns (repeatable) |
--exclude | -exc | List[str] | Exclude patterns (repeatable) |
--help | Show command help |
Examples¶
Output Format¶
The flatten command produces well-structured output:
# --- File: src/main.py ---
"""Main application module."""
def main():
print("Hello, World!")
if __name__ == "__main__":
main()
# --- File: src/utils.py ---
"""Utility functions."""
def helper_function():
return "I'm helping!"
# --- File: tests/test_main.py ---
"""Tests for main module."""
import pytest
from src.main import main
def test_main():
# Test implementation
assert True
Binary File Handling¶
codebrief gracefully handles binary files:
Output includes:
# --- Skipped binary or non-UTF-8 file: image.png ---
# --- File: script.py ---
# Python content here...
📦 deps - Dependency Analysis¶
Analyze and document project dependencies across multiple languages.
Basic Usage¶
# Analyze dependencies in current project
codebrief deps
# Save dependency report
codebrief deps --output dependencies.md
Options¶
Option | Short | Type | Description |
---|---|---|---|
--output | -o | Path | Output file path |
--to-clipboard | -c | Flag | Copy output to clipboard (cannot be used with --output) |
--help | Show command help |
Supported Dependency Files¶
Language | Files Supported |
---|---|
Python | pyproject.toml , requirements.txt , requirements-dev.txt , etc. |
Node.js | package.json |
Future | pom.xml , build.gradle , Gemfile , Cargo.toml , etc. |
Examples¶
Output:
Output:
🔄 git-info - Git Context Extraction¶
Extract comprehensive Git repository information for context generation.
Basic Usage¶
# Generate Git context for current directory
codebrief git-info
# Generate Git context for specific repository
codebrief git-info /path/to/repo
# Save Git context to file
codebrief git-info --output git-context.md
Options¶
Option | Short | Type | Description |
---|---|---|---|
--output | -o | Path | Output file path |
--to-clipboard | -c | Flag | Copy output to clipboard (cannot be used with --output) |
--log-count | -n | int | Number of recent commits to include (default: 10) |
--full-diff | bool | Include full diff of uncommitted changes | |
--diff-options | str | Custom git diff options (e.g., "--stat", "--name-only") | |
--help | Show command help |
Examples¶
Output:
# Git Context
## Repository Information
- **Current Branch:** main
- **Repository Status:** Clean working directory
## Recent Commits (Last 10)
1. **feat: add new feature** (2024-01-15)
- Author: Developer <dev@example.com>
- Hash: abc123f
2. **fix: resolve bug in parser** (2024-01-14)
- Author: Developer <dev@example.com>
- Hash: def456a
Error Handling¶
The git-info command gracefully handles various scenarios:
- Non-Git Repository: Returns informative message
- Git Not Installed: Provides installation guidance
- Permission Issues: Clear error messages
- Network Timeouts: Handles slow Git operations
Configuration Integration¶
📦 bundle - Comprehensive Context Bundling¶
Create structured bundles combining multiple context tools for comprehensive project understanding.
Basic Usage¶
# Create complete project bundle
codebrief bundle
# Create bundle for specific directory
codebrief bundle /path/to/project
# Save bundle to file
codebrief bundle --output project-bundle.md
Options¶
Option | Short | Type | Description |
---|---|---|---|
--output | -o | Path | Output file path |
--to-clipboard | -c | Flag | Copy output to clipboard (cannot be used with --output) |
--exclude-tree | bool | Exclude directory tree section | |
--exclude-git | bool | Exclude Git context section | |
--exclude-deps | bool | Exclude dependencies section | |
--exclude-files | bool | Exclude flattened files section | |
--flatten | List[Path] | Specific paths to flatten (repeatable) | |
--git-log-count | int | Number of Git commits to include | |
--git-full-diff | bool | Include full Git diff | |
--git-diff-options | str | Custom Git diff options | |
--help | Show command help |
Examples¶
Creates a comprehensive bundle with all sections: - Table of Contents - Directory Tree - Git Context - Dependencies - Flattened Files
codebrief bundle \
--exclude-deps \
--flatten src/ tests/ \
--git-log-count 5 \
--output review-bundle.md
Focused bundle for code review with recent Git history.
Documentation-focused bundle without Git information.
Bundle Structure¶
The bundle command creates well-organized output:
# codebrief Bundle
## Table of Contents
- [Directory Tree](#directory-tree)
- [Git Context](#git-context)
- [Dependencies](#dependencies)
- [Files: src/codebrief/tools](#files-srccodebrieftools)
## Directory Tree
📁 my-project/
├── 📄 README.md
├── 📁 src/
└── 📁 tests/
## Git Context
**Current Branch:** main
**Repository Status:** Clean
## Dependencies
### Python Dependencies (pyproject.toml)
- typer: ^0.9.0
- rich: ^13.0.0
## Files: src/codebrief/tools
# --- File: src/codebrief/tools/bundler.py ---
[File contents...]
Advanced Configuration¶
[tool.codebrief]
default_output_filename_bundle = "context-bundle.md"
global_exclude_patterns = ["*.pyc", "__pycache__/"]
Integration with Other Tools¶
The bundle command leverages all other codebrief tools:
- tree: For directory structure
- git-info: For Git context
- deps: For dependency analysis
- flatten: For file content aggregation
👋 hello - Example Command¶
A simple example command for testing and demonstration.
Basic Usage¶
Options¶
Option | Short | Type | Description |
---|---|---|---|
--name | str | Name to greet | |
--help | Show command help |
Examples¶
# Default
codebrief hello
# Output: Hello World from codebrief!
# Custom name
codebrief hello --name "Alice"
# Output: Hello Alice from codebrief!
📋 Clipboard Integration¶
All codebrief commands support clipboard functionality through the --to-clipboard
or -c
flag:
Usage¶
# Copy any command output to clipboard
codebrief tree --to-clipboard
codebrief flatten . -c
codebrief deps --to-clipboard
codebrief git-info -c
codebrief bundle --to-clipboard
Features¶
- Cross-platform: Works on Windows, macOS, and Linux
- Smart behavior: Only available when no output file is specified
- User feedback: Shows success/error messages
- Graceful errors: Handles clipboard access issues gracefully
Examples¶
# ✅ Valid - copy to clipboard
codebrief tree -c
# ❌ Invalid - cannot use both clipboard and file output
codebrief tree -c --output file.txt
# ✅ Valid - save to file (no clipboard)
codebrief tree --output file.txt
Error Handling¶
When clipboard access fails, codebrief provides helpful feedback:
codebrief tree -c
# Success: 📋 Output successfully copied to clipboard!
# If clipboard access fails:
# Warning: Failed to copy to clipboard: [error details]
🔧 Global Options¶
These options work with all commands:
Help and Version¶
# Show general help
codebrief --help
# Show version
codebrief --version
# Command-specific help
codebrief tree --help
codebrief flatten --help
codebrief deps --help
codebrief git-info --help
codebrief bundle --help
Environment Variables¶
Set global behavior via environment variables:
# Debug mode
export codebrief_DEBUG=1
codebrief tree
# Custom output directory
export codebrief_OUTPUT_DIR=~/codebrief-outputs
codebrief flatten . --output code.md # Saves to ~/codebrief-outputs/code.md
🎯 Command Combinations¶
Comprehensive Project Context¶
Generate complete project context:
# Option 1: Use the bundle command (recommended)
codebrief bundle --output complete-project-context.md
# Option 2: Generate individual components
codebrief tree --output docs/structure.txt
codebrief git-info --output docs/git-context.md
codebrief deps --output docs/dependencies.md
codebrief flatten . \
--include "*.py" --include "*.md" --include "*.toml" \
--output docs/codebase.md
Selective Context for Different Audiences¶
🚨 Error Handling¶
codebrief provides helpful error messages:
Common Errors and Solutions¶
Directory Not Found
codebrief tree /nonexistent
# Error: Invalid value for 'ROOT_DIR': Directory '/nonexistent' does not exist.
Solution: Check the path and ensure the directory exists.
Permission Denied
codebrief flatten / --output /etc/output.md
# Error: Permission denied when writing to '/etc/output.md'
Solution: Choose a writable output location or check permissions.
Configuration Error
# With invalid pyproject.toml
codebrief tree
# Warning: Expected list for 'global_exclude_patterns', got str. Using default.
Solution: Fix the configuration type in pyproject.toml
.
Rich Error Output¶
codebrief uses Rich for beautiful error messages:
Shows colorized, well-formatted error with context and suggestions.
🔍 Debugging Commands¶
Verbose Output (Future Feature)¶
# Show detailed processing information
codebrief tree --verbose
codebrief flatten . --verbose --include "*.py"
Dry Run (Future Feature)¶
# See what would be processed without actually doing it
codebrief flatten . --dry-run --include "*.py"
📚 Next Steps¶
Now that you know the commands:
- Practice: Try different combinations on your projects
- Configure: Set up Configuration for your workflow
- Automate: Use commands in scripts and CI/CD
- Advanced: Learn Advanced Workflows