Why Command
Thearc why
command helps you understand the decision trail behind a specific line of code. It traverses the knowledge graph to find commits, PRs, issues, and other context that led to the current state of the code.
Usage
Subcommands
file
Show the decision trail for a specific line in a file.
Options
Option | Description |
---|---|
--max-depth <depth> | Maximum depth to traverse in the knowledge graph (default: 3) |
--include-issues | Include related issues in the results |
--include-prs | Include related pull requests in the results |
--include-docs | Include related documentation in the results |
--format <format> | Output format: text, json, or markdown (default: text) |
--output <file> | Write output to a file instead of stdout |
--debug | Enable debug logging |
Examples
Basic Usage
src/main.py
.
With Maximum Depth
Including Issues and PRs
JSON Output
Output Format
The default output format is a text-based tree showing the decision trail:Comparison with trace
While the trace
command focuses on the historical changes to a file or line, the why
command focuses on understanding the decision-making process that led to the current state of the code.
Feature | why | trace |
---|---|---|
Focus | Decision trail | Historical changes |
Graph traversal | Bi-directional | Linear history |
Default depth | 3 | 1 |
Includes | Commits, PRs, issues, docs | Commits, file changes |
Troubleshooting
No Results Found
If no results are found, try:- Increasing the maximum depth with
--max-depth
- Checking if the file and line number are correct
- Running
arc build
to ensure the knowledge graph is up to date
Performance Issues
For large repositories, thewhy
command may take some time to execute. To improve performance:
- Use a smaller maximum depth
- Run an incremental build first:
arc build --incremental
- Limit the scope of included data with specific options
See Also
- Trace Command - For tracing the historical changes to a file or line
- Relate Command - For finding related nodes in the knowledge graph
- Tracing History Examples - For more examples of using the
why
command