ctx diff
Generate context for changed files with their related dependencies.
Synopsis
ctx diff [REVISION] [OPTIONS]Description
The diff command identifies changed files compared to a git reference and includes context about the symbols and dependencies affected by those changes. This is useful for:
- Code review - Get context for reviewing a PR or commit
- Change impact - Understand what's affected by your changes
- Pre-commit - Verify changes before committing
Options
| Option | Description | Default |
|---|---|---|
REVISION | Git reference to compare against | HEAD~1 |
--max-tokens <N> | Maximum tokens in output | 8000 |
--depth <N> | Depth for finding related symbols | 1 |
--changes-only | Only include changed files, not related context | false |
--staged | Compare staged changes instead of a revision | false |
--summary | Show only summary, not file contents | false |
-f, --format <FORMAT> | Output format (xml, markdown, md, plain, json) | xml |
--show-sizes | Show file sizes in the project tree | false |
--no-tree | Disable the project tree in output | false |
Examples
Changes Since Last Commit
# See what changed since the previous commit (default: HEAD~1)
ctx diffCompare with Branch
# Changes compared to main branch
ctx diff main
# Changes in feature branch
ctx diff origin/mainReview a Specific Commit
# Changes in the last commit
ctx diff HEAD~1Staged Changes
# Only the changes you have staged
ctx diff --stagedToken-Limited Output
# Limit output for smaller context windows
ctx diff --max-tokens 4000Summary Mode
# Just see what changed without file contents
ctx diff --summaryOutput:
Changed files (5):
M src/auth.rs - 3 symbols affected
M src/handlers.rs - 2 symbols affected
A src/cache.rs - new file
D src/legacy.rs - removed
Related symbols:
- authenticate (src/auth.rs:42) - modified
- handleLogin (src/handlers.rs:15) - calls authenticate
- UserSession (src/models.rs:8) - used by authenticateDeep Dependency Analysis
# Find more related context
ctx diff main --depth 4How It Works
- Detect Changes: Uses
git diffto find modified, added, and deleted files - Parse Hunks: Identifies which lines/symbols changed
- Find Related: Follows call graph to find dependent symbols
- Generate Context: Outputs changed files plus relevant context
Output
The output includes:
- Changed files with their full contents
- Related files containing symbols affected by the changes (unless
--changes-onlyis set) - Context limited to
--max-tokens
Integration with Code Review
The ctx review command builds on diff to fetch and review a GitHub pull
request. It requires the GitHub CLI (gh) to be installed and authenticated:
# Get context for a GitHub PR
ctx review 123Tips
- Use
--summaryfirst to understand scope of changes - Increase
--depthfor refactoring tasks - Combine with
--format markdownfor PR descriptions - Use in CI to generate change documentation
See Also
- ctx smart - Task-based file selection
- Impact Analysis - Understand what a change affects