get_cross_file_dependenciesΒΆ
Analyze all dependencies a function or class needs from other files, recursively resolving imports and extracting the complete dependency chain.
Quick ReferenceΒΆ
get_cross_file_dependencies(
target_file: str, # File containing symbol
target_symbol: str, # Symbol to analyze
project_root: str = None, # Project directory
max_depth: int = 3, # Resolution depth
include_code: bool = True, # Include source code
include_diagram: bool = True, # Include Mermaid diagram
confidence_decay_factor: float = 0.9 # Confidence decay per level
) -> CrossFileDependencies
User StoriesΒΆ
| Persona | Story | Tool Value |
|---|---|---|
| π₯ David (Team Lead) | "Understand dependencies before approving changes" | Better code reviews |
| π§ Chris (OSS Contributor) | "Understand module relationships with confidence scoring" | Dependency analysis |
| π’ Jennifer (Enterprise Architect) | "Trace dependencies across enterprise-scale systems" | Comprehensive analysis |
ParametersΒΆ
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
target_file | string | Yes | - | Path to file (relative to project root) |
target_symbol | string | Yes | - | Function or class name |
project_root | string | No | cwd | Project root directory |
max_depth | int | No | 3 | Maximum dependency depth |
include_code | bool | No | true | Include source code |
include_diagram | bool | No | true | Include Mermaid diagram |
confidence_decay_factor | float | No | 0.9 | Confidence decay per level |
Response SchemaΒΆ
{
"data": {
"target_file": "string",
"target_symbol": "string",
"dependencies": [
{
"symbol": "string",
"file": "string",
"type": "string",
"depth": "integer",
"confidence": "float",
"code": "string | null",
"line_start": "integer",
"line_end": "integer"
}
],
"dependency_graph": {
"nodes": ["string"],
"edges": [{"from": "string", "to": "string"}]
},
"combined_code": "string",
"circular_dependencies": ["string"],
"low_confidence_count": "integer",
"low_confidence_warning": "string | null",
"mermaid_diagram": "string"
},
"tier_applied": "string",
"duration_ms": "integer"
}
ExamplesΒΆ
Analyze Function DependenciesΒΆ
{
"data": {
"target_file": "services/order_service.py",
"target_symbol": "process_order",
"dependencies": [
{
"symbol": "Order",
"file": "models/order.py",
"type": "class",
"depth": 1,
"confidence": 0.9,
"code": "class Order:\n def __init__(self, items, customer_id):\n ...",
"line_start": 10,
"line_end": 45
},
{
"symbol": "validate_order",
"file": "validators/order_validator.py",
"type": "function",
"depth": 1,
"confidence": 0.9,
"code": "def validate_order(data: dict) -> bool:\n ...",
"line_start": 15,
"line_end": 35
},
{
"symbol": "calculate_total",
"file": "utils/pricing.py",
"type": "function",
"depth": 1,
"confidence": 0.9,
"code": "def calculate_total(items: list) -> float:\n ..."
},
{
"symbol": "PricingRule",
"file": "models/pricing.py",
"type": "class",
"depth": 2,
"confidence": 0.81,
"code": "class PricingRule:\n ..."
}
],
"dependency_graph": {
"nodes": ["process_order", "Order", "validate_order", "calculate_total", "PricingRule"],
"edges": [
{"from": "process_order", "to": "Order"},
{"from": "process_order", "to": "validate_order"},
{"from": "process_order", "to": "calculate_total"},
{"from": "calculate_total", "to": "PricingRule"}
]
},
"combined_code": "# From models/order.py\nclass Order:\n ...\n\n# From validators/order_validator.py\ndef validate_order(data: dict) -> bool:\n ...\n\n# From utils/pricing.py\ndef calculate_total(items: list) -> float:\n ...\n\n# From models/pricing.py\nclass PricingRule:\n ...\n\n# From services/order_service.py\ndef process_order(data: dict) -> Order:\n ...",
"circular_dependencies": [],
"low_confidence_count": 0,
"mermaid_diagram": "graph TD\n process_order --> Order\n process_order --> validate_order\n process_order --> calculate_total\n calculate_total --> PricingRule"
},
"tier_applied": "pro",
"duration_ms": 245
}
Deep Dependency AnalysisΒΆ
{
"data": {
"target_symbol": "UserService",
"dependencies": [
{"symbol": "User", "file": "models/user.py", "depth": 1, "confidence": 0.9},
{"symbol": "Database", "file": "db/database.py", "depth": 1, "confidence": 0.9},
{"symbol": "validate_email", "file": "validators.py", "depth": 1, "confidence": 0.9},
{"symbol": "BaseModel", "file": "models/base.py", "depth": 2, "confidence": 0.81},
{"symbol": "Connection", "file": "db/connection.py", "depth": 2, "confidence": 0.81},
{"symbol": "EmailValidator", "file": "validators/email.py", "depth": 2, "confidence": 0.81},
{"symbol": "Config", "file": "config.py", "depth": 3, "confidence": 0.729},
{"symbol": "Pool", "file": "db/pool.py", "depth": 3, "confidence": 0.729}
],
"low_confidence_count": 2,
"low_confidence_warning": "2 symbols at depth 3+ have confidence < 0.75. Results may be less reliable."
}
}
Detect Circular DependenciesΒΆ
Confidence DecayΒΆ
Confidence decreases with depth:
| Depth | Confidence (factor=0.9) |
|---|---|
| 0 | 1.000 (target symbol) |
| 1 | 0.900 |
| 2 | 0.810 |
| 3 | 0.729 |
| 4 | 0.656 |
| 5 | 0.590 |
Symbols with confidence < 0.5 are flagged as "low confidence".
Mermaid DiagramΒΆ
The tool generates dependency visualizations:
graph TD
subgraph "services/order_service.py"
process_order
end
subgraph "models/order.py"
Order
end
subgraph "validators/order_validator.py"
validate_order
end
subgraph "utils/pricing.py"
calculate_total
end
process_order --> Order
process_order --> validate_order
process_order --> calculate_total Tier DifferencesΒΆ
This tool is available at all tiers. What differs are the limits and capabilities:
| Feature | Community | Pro | Enterprise |
|---|---|---|---|
| Availability | β Available | β Available | β Available |
| Basic dependency analysis | β | β Advanced | β Advanced |
| Max depth | 2 | 5 | Unlimited |
| Include code | β | β | β |
| Confidence decay factor | 0.9 | 0.9 | 0.9 (configurable) |
| Combined code output | Not available | β | β |
| Mermaid diagrams | Not available | β | β |
| Circular detection | Not available | β | β |
| Confidence scoring | Not available | β | β |
| Custom resolution | Not available | Not available | β |
Community Tier
Cross-file dependency analysis is available in Community tier with basic analysis (2 depth max, code extraction). For deeper analysis, diagrams, and circular dependency detection, consider upgrading to Pro or Enterprise.
Use CasesΒΆ
1. Extract with Full ContextΒΆ
# Get all code needed to understand a function
result = get_cross_file_dependencies(
target_file="services/order_service.py",
target_symbol="process_order",
include_code=True
)
# combined_code contains everything needed
print(result.combined_code)
2. Refactoring ImpactΒΆ
# Before refactoring, understand dependencies
result = get_cross_file_dependencies(
target_file="models/user.py",
target_symbol="User",
max_depth=5
)
# Check what depends on User
print(f"User is used by {len(result.dependencies)} symbols")
3. Module ExtractionΒΆ
# Find what's needed to extract a module
result = get_cross_file_dependencies(
target_file="services/payment_service.py",
target_symbol="PaymentService",
max_depth=3
)
# combined_code shows what to include in extracted module
Tier LimitsΒΆ
get_cross_file_dependencies capabilities vary by tier:
| Feature | Community | Pro | Enterprise |
|---|---|---|---|
| Max depth | 1 | 5 | Unlimited |
| Max files analyzed | 50 | 500 | Unlimited |
| Dependency resolution | Basic | β Advanced | β Full |
| Circular import detection | β | β | β |
| Confidence scoring | β | β | β Enhanced |
| Code extraction | β | β | β |
| Mermaid diagrams | β | β | β Advanced |
Community TierΒΆ
- β Analyze cross-file dependencies
- β Detect circular imports
- β Basic confidence scoring
- β Extract dependency code
- β οΈ Max depth of 1 - Direct dependencies only
- β οΈ Limited to 50 files - May miss transitive dependencies
- β No deep dependency chain analysis
Pro TierΒΆ
- β All Community features
- β Max depth of 5 - Trace deeper dependency chains
- β 500 files analyzed - Handle larger projects
- β Advanced resolution - Better import path detection
- β Enhanced confidence scoring - More accurate reliability estimates
- β Timeout protection - Handles large codebases gracefully
Enterprise TierΒΆ
- β All Pro features
- β Unlimited depth - Complete dependency chain
- β Unlimited files - No project size restrictions
- β Full semantic analysis - Understand dependency relationships
- β Low confidence warnings - Flag unreliable deep dependencies
- β Graph query language - Custom dependency queries
Key Difference: Depth and Scale - Community: Depth 1, 50 files - Immediate dependencies only - Pro: Depth 5, 500 files - Multi-level dependency tracking - Enterprise: Unlimited - Complete dependency graph
Best PracticesΒΆ
- Start shallow - Use max_depth=2 first, increase if needed
- Check confidence - Low confidence = verify manually
- Watch for circular deps - Fix before they cause issues
- Use combined_code - For AI context, include all deps
- Review diagrams - Visualize before refactoring
Related ToolsΒΆ
- get_call_graph - Function call relationships
- get_project_map - Project structure overview
- extract_code - Extract with context