codemap_get_dependencies
Get dependency relationships for a file or symbol — what it imports/calls and what imports/calls it. Supports symbol targeting (relativePath$symbolName) for symbol-level call graph data.
Parameters
| Name | Type | Required | Description |
|---|---|---|---|
target | string | ✅ Required | Relative path to the file, or symbol reference (relativePath$symbolName) for symbol-level call tracking |
Usage Examples
MCP Usage (for AI Agents like Claude)
json
{
"name": "codemap_get_dependencies",
"arguments": {
"target": "src/utils/helpers.ts"
}
}Example Output
JSON Response
json
{
"success": true,
"symbol": "src/services/UserService.ts$getUser",
"calls": [
"src/lib/database.ts$query",
"src/utils/validators.ts$validateId"
],
"calledBy": [
"src/api/routes/users.ts$getUserHandler",
"src/middleware/auth.ts$verifyOwnership"
],
"callCount": 2,
"calledByCount": 2
}When to Use This Tool
-
Use
- Impact analysis - Identify what files depend on the one you're changing
- Refactoring planning - Understand the blast radius before modifying shared code
- Deletion safety - Check if a file can be safely removed (no importers)
- Coupling analysis - Find highly coupled files that might need refactoring
- Dead code detection - Identify files that aren't imported by anything
- Component reusability - Measure how widely components are used
- Dependency audits - Review what each file imports to identify unnecessary dependencies
codemap_get_dependencies to understand file relationships and coupling:
Common Patterns
Safe Deletion Check
Coupling Analysis
Refactoring Impact Preview
Find Entry Points
const deps = await codemap.graph.getDependencies('src/old/deprecated.ts');
if (deps.importedByCount === 0) {
console.log('✓ Safe to delete - no files depend on this');
await codemap.delete({ target: 'src/old/deprecated.ts' });
} else {
console.log(✗ Cannot delete - ${deps.importedByCount} files depend on this);
console.log('Update these files first:', deps.importedBy);
}Coupling Analysis
// Find files with high coupling (many imports + importers)
const files = await codemap.search({ query: '*.ts' });
for (const file of files.files) {
const deps = await codemap.graph.getDependencies(file.relativePath);
const coupling = deps.importCount + deps.importedByCount;
if (coupling > 15) {
console.log(⚠️ High coupling: ${file.relativePath} (${coupling} connections));
}
}Refactoring Impact Preview
// Before refactoring a utility file, see what will be affected
const deps = await codemap.graph.getDependencies('src/utils/helpers.ts');
console.log(Refactoring will affect ${deps.importedByCount} files:);
deps.importedBy.forEach(file => console.log( - ${file}));Find Entry Points
// Find files that are imported but import nothing (top-level entries)
const files = await codemap.search({ query: '*.ts' });
for (const file of files.files) {
const deps = await codemap.graph.getDependencies(file.relativePath);
if (deps.importCount === 0 && deps.importedByCount > 0) {
console.log(Entry point: ${file.relativePath});
}
}Pro Tips
Check before refactoring - Always run this tool before major refactoring to understand the impact scope.
Identify code smells - Files with very high
Find dead code - Files with
Monitor component reuse - Track
Use for architectural review - Regularly analyze top files by dependency count to ensure architecture is clean.
Combine with impact analysis - Use
Identify code smells - Files with very high
importedByCount might indicate tight coupling or god objects that need decomposition.Find dead code - Files with
importedByCount === 0 are candidates for removal (unless they're entry points like main.ts).Monitor component reuse - Track
importedByCount for components to ensure they're actually reusable, not single-use.Use for architectural review - Regularly analyze top files by dependency count to ensure architecture is clean.
Combine with impact analysis - Use
codemap_get_dependencies for immediate relationships, codemap_impact_analysis for deep traversal.Best Practices
Document high-coupling files - If a file has >20 dependencies, add a comment explaining why and consider refactoring.
Set coupling thresholds - Establish team standards (e.g., files shouldn't have >10 direct dependencies).
Review before deletion - Always check
Track dependency growth - Monitor how dependencies change over time to prevent architecture degradation.
Validate circular dependencies - If a file both imports and is imported by the same file, investigate circular dependencies.
Use for code reviews - Check if new files have reasonable dependency counts before merging.
Set coupling thresholds - Establish team standards (e.g., files shouldn't have >10 direct dependencies).
Review before deletion - Always check
importedByCount before removing any file to avoid breaking the build.Track dependency growth - Monitor how dependencies change over time to prevent architecture degradation.
Validate circular dependencies - If a file both imports and is imported by the same file, investigate circular dependencies.
Use for code reviews - Check if new files have reasonable dependency counts before merging.
Common Mistakes
❌ Mistake: Deleting files without checking dependencies
✅ Instead: Check dependencies first
---
❌ Mistake: Ignoring high coupling warnings
✅ Instead: Refactor high-coupling files
---
❌ Mistake: Not considering transitive dependencies
✅ Instead: Use impact analysis for full scope
---
❌ Mistake: Treating zero dependencies as always bad
✅ Instead: Understand file purpose
// Dangerous - might break other files
await codemap.delete({ target: 'src/utils/old.ts' });✅ Instead: Check dependencies first
const deps = await codemap.graph.getDependencies('src/utils/old.ts');
if (deps.importedByCount > 0) {
console.error(Cannot delete - used by ${deps.importedByCount} files);
console.log('Update these files first:', deps.importedBy);
} else {
await codemap.delete({ target: 'src/utils/old.ts' });
}---
❌ Mistake: Ignoring high coupling warnings
const deps = await codemap.graph.getDependencies('src/utils/kitchen-sink.ts');
// importCount: 47, importedByCount: 83
// This is a code smell but is ignored✅ Instead: Refactor high-coupling files
const deps = await codemap.graph.getDependencies('src/utils/kitchen-sink.ts');
if (deps.importCount + deps.importedByCount > 50) {
console.warn('⚠️ God object detected - consider splitting into smaller modules');
// Plan refactoring into focused modules
}---
❌ Mistake: Not considering transitive dependencies
// Only checks direct dependencies
const deps = await codemap.graph.getDependencies('src/core/engine.ts');
console.log(${deps.importedByCount} files depend on this);
// But what about files that depend on those files?✅ Instead: Use impact analysis for full scope
// For shallow check
const deps = await codemap.graph.getDependencies('src/core/engine.ts');
console.log(Direct dependents: ${deps.importedByCount});
// For full impact including transitive
const impact = await codemap.graph.impactAnalysis({
startFile: 'src/core/engine.ts',
maxDepth: 3
});
console.log(Total impacted files: ${impact.affectedFiles.length});---
❌ Mistake: Treating zero dependencies as always bad
const deps = await codemap.graph.getDependencies('src/main.ts');
if (deps.importCount === 0) {
console.error('Error: File has no imports!');
}
// But entry points like main.ts might legitimately have few imports✅ Instead: Understand file purpose
const deps = await codemap.graph.getDependencies('src/main.ts');
if (deps.importCount === 0 && !file.path.includes('main')) {
console.warn('Potential isolated file - verify this is intentional');
}