ts-morph

TypeScript compiler API wrapper that makes programmatic TypeScript code analysis and manipulation accessible. ts-morph wraps TypeScript's complex compiler API in a simpler, navigable object model — read source files, traverse AST nodes, modify code, add/remove declarations, and generate TypeScript programmatically. Used for codemods, code generators, documentation extractors, and static analysis tools.

Evaluated Mar 07, 2026 (0d ago) v21+
Homepage ↗ Repo ↗ Developer Tools typescript ast code-generation codemods static-analysis refactoring
⚙ Agent Friendliness
67
/ 100
Can an agent use this?
🔒 Security
89
/ 100
Is it safe for agents?
⚡ Reliability
80
/ 100
Does it work consistently?

Score Breakdown

⚙ Agent Friendliness

MCP Quality
--
Documentation
85
Error Messages
78
Auth Simplicity
100
Rate Limits
100

🔒 Security

TLS Enforcement
90
Auth Strength
90
Scope Granularity
90
Dep. Hygiene
85
Secret Handling
90

Local code analysis — no security concerns. Code modification tools can introduce vulnerabilities if used carelessly; review generated/modified code.

⚡ Reliability

Uptime/SLA
82
Version Stability
80
Breaking Changes
78
Error Recovery
78
AF Security Reliability

Best When

You need to programmatically analyze or modify TypeScript code at the AST level — codemods, code generators, or documentation extractors.

Avoid When

You need simple text transformations or runtime type checking — ts-morph's AST approach is overkill for basic string replacement.

Use Cases

  • Build TypeScript codemods that programmatically refactor code across large codebases — rename types, migrate APIs, update patterns
  • Generate TypeScript code programmatically from schemas, databases, or configuration in agent scaffolding tools
  • Extract TypeScript documentation and type information for API documentation generators
  • Build static analysis tools that traverse TypeScript ASTs to find patterns, anti-patterns, or metrics
  • Write type-safe code transformation pipelines in agent systems that modify TypeScript source files

Not For

  • JavaScript-only projects — ts-morph requires TypeScript
  • Simple text/regex-based code changes — ts-morph is powerful but heavyweight for simple string replacements
  • Runtime type checking — ts-morph is a static analysis tool; use Zod or TypeBox for runtime validation

Interface

REST API
No
GraphQL
No
gRPC
No
MCP Server
No
SDK
Yes
Webhooks
No

Authentication

Methods: none
OAuth: No Scopes: No

No authentication — local code analysis library.

Pricing

Model: open_source
Free tier: Yes
Requires CC: No

MIT-licensed open source library.

Agent Metadata

Pagination
none
Idempotent
Full
Retry Guidance
Not documented

Known Gotchas

  • ts-morph creates an in-memory TypeScript project — loading large codebases consumes significant memory and time for initial type checking; disable type checking if not needed with useInMemoryFileSystem or skipLibCheck
  • Node manipulations are order-sensitive — removing a node while iterating its parent's children causes index shift issues; collect nodes first, then modify
  • ts-morph version must be compatible with the TypeScript version — check peerDependencies; mismatches cause compiler API incompatibilities
  • Save order matters when writing generated files — ts-morph's in-memory model must be explicitly saved to disk via project.save() or sourceFile.save()
  • Type resolution requires the full project context — analyzing a single file without the rest of the project may produce incorrect or missing type information
  • Formatted output requires explicit formatting — ts-morph generates syntactically correct but unformatted code; run Prettier/Biome after generation

Alternatives

Full Evaluation Report

Comprehensive deep-dive: security analysis, reliability audit, agent experience review, cost modeling, competitive positioning, and improvement roadmap for ts-morph.

AI-powered analysis · PDF + markdown · Delivered within 30 minutes

$99

Package Brief

Quick verdict, integration guide, cost projections, gotchas with workarounds, and alternatives comparison.

Delivered within 10 minutes

$3

Score Monitoring

Get alerted when this package's AF, security, or reliability scores change significantly. Stay ahead of regressions.

Continuous monitoring

$3/mo

Scores are editorial opinions as of 2026-03-07.

6451
Packages Evaluated
26150
Need Evaluation
173
Need Re-evaluation
Community Powered