Why Command
Show decision trail for a file line
Why Command
The arc 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
This will show the decision trail for line 42 in src/main.py
.
With Maximum Depth
This will traverse the knowledge graph up to a depth of 5 to find related information.
Including Issues and PRs
This will include related issues and pull requests in the results.
JSON Output
This will output the results in JSON format.
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, the why
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