This guide provides examples of how to trace the history of code using Arc Memory, showing how to follow the decision trail from a specific line of code to related commits, PRs, issues, and ADRs.Related Documentation:
You can control the depth of the search and the number of results:
Copy
# Get more results (up to 5)arc trace file src/main.py 42 --max-results 5# Search deeper in the graph (up to 3 hops)arc trace file src/main.py 42 --max-hops 3# Combine botharc trace file src/main.py 42 --max-results 5 --max-hops 3
Increasing --max-hops will follow longer paths in the graph, potentially finding more distantly related entities. Increasing --max-results will return more entities.
Arc Memory works with any file type in your repository:
Copy
# Trace history for a Python filearc trace file src/main.py 42# Trace history for a JavaScript filearc trace file src/app.js 100# Trace history for a configuration filearc trace file config.yaml 5# Trace history for documentationarc trace file docs/README.md 10
To understand why a particular feature was implemented:
Copy
# Find the commit that introduced the featuregit blame src/feature.py# Note the line number where the feature was introduced (e.g., line 42)arc trace file src/feature.py 42 --max-hops 3
You can also trace history programmatically in your Python code:
Copy
from pathlib import Pathfrom arc_memory.trace import trace_history_for_file_line# Trace the history of line 42 in a fileresults = trace_history_for_file_line( db_path=Path("~/.arc/graph.db"), file_path="src/main.py", line_number=42, max_results=5, max_hops=3)# Process the resultsfor result in results: print(f"{result['type']}: {result['title']} ({result['timestamp']})") # Access type-specific fields if result['type'] == 'commit': print(f" Author: {result.get('author')}") print(f" SHA: {result.get('sha')}") elif result['type'] == 'pr': print(f" PR #{result.get('number')}") print(f" State: {result.get('state')}") print(f" URL: {result.get('url')}")
# For key files, trace the history of important linesarc trace file src/core_module.py 10arc trace file src/core_module.py 50arc trace file src/core_module.py 100
# Ensure the knowledge graph is builtarc build# Check if the file is tracked by Gitgit ls-files | grep your_file.py# Verify the line number existswc -l your_file.py