Every fix verified by the TypeScript compiler

Verified TypeScript
Repairs for Agents

ts-repair is an oracle-guided repair engine that turns TypeScript diagnostics into verified repair plans. Every fix is proven to reduce errors before your agent sees it.

$ npm install -g ts-repair
TypeScript errors
ts-repair verifies fixes
Verified repair plan

Quickstart

Get verified TypeScript repairs in under a minute.

CLI Usage

# Install globally
npm install -g ts-repair
# Get a verified repair plan
ts-repair repair ./tsconfig.json
# Apply verified fixes automatically
ts-repair repair --apply

MCP Server Setup

Add to your agent's MCP configuration for automatic TypeScript repair integration.

~/.claude/settings.json
{
  "mcpServers": {
    "ts-repair": {
      "command": "bunx",
      "args": ["ts-repair", "mcp-server"]
    }
  }
}

See all agent configurations →

The Agent Iteration Problem

Without ts-repair
  • Agent receives raw TypeScript errors
  • Guesses at fixes based on error messages
  • Applies fix, runs compiler, new errors appear
  • Repeat until lucky or out of tokens
With ts-repair
  • Agent receives verified repair plan
  • Every fix proven to reduce errors
  • Fixes ordered for maximum impact
  • Apply confidently, no guesswork

The TypeScript Compiler is the Oracle

Instead of giving agents raw errors and hoping they fix them, ts-repair speculatively applies every candidate fix, re-runs the type checker, and only surfaces fixes that provably reduce errors.

No heuristics. No LLM guessing. The actual type checker that will judge your code is the same one verifying the fixes. That's why every fix in a repair plan is guaranteed to help.

What Gets Fixed Automatically

ts-repair verifies which TypeScript fixes actually help and rejects those that introduce new errors.

Missing Imports

Auto-add imports for undefined symbols from your project or dependencies.

Async/Await

Add missing async or await modifiers to functions and calls.

Spelling Fixes

Rename misspelled identifiers to matching names in scope.

Missing Properties

Add missing properties to objects and interfaces.

Remove Unused

Clean up unused imports, variables, and parameters.

ESM Extensions

Add .js extensions to module imports for ESM compatibility.

Plus ~73 other fix types from TypeScript's Language Service, each verified before being surfaced.

Early Benchmark Results

Claude Code fixing TypeScript errors in Zod v4 — with and without ts-repair.

Early results from a single benchmark. We seeded 206 type errors into Zod v4 and measured Claude Code's repair process. Results will vary by project complexity and error types. Full methodology →

52%
Cost Reduction
$2.55 → $1.23
63%
Fewer Tokens
3.58M → 1.32M input
32%
Faster
13m 23s → 9m 6s
6→1
Repair Rounds
Compile-check-fix cycles
67% fewer bash commands (27 → 9) — less compile-check-fix churn

How It Works

ts-repair treats the TypeScript compiler as a verification oracle.

The Algorithm

while diagnostics > 0:
  for each diagnostic, get candidate fixes
  for each candidate:
    apply to in-memory copy
    re-run type checker
    measure delta (errors removed - errors introduced)
  select best candidate (max delta)
  commit and repeat

For each diagnostic, ts-repair generates candidate fixes (from TypeScript's Language Service and custom repair recipes), applies each to an in-memory copy, re-runs the type checker, and measures the exact delta. Only fixes that provably help are included in the plan.

The Output

{
  "status": "12 diagnostics → 0 diagnostics",
  "confidence": "verified",
  "steps": [
    {
      "action": "Add missing import",
      "resolves": 7,
      "file": "src/api.ts",
      "change": "import { User } from './types'"
    },
    {
      "action": "Fix argument type",
      "resolves": 3,
      "file": "src/handlers.ts"
    },
    {
      "action": "Add null check",
      "resolves": 2,
      "file": "src/utils.ts"
    }
  ]
}

Architecture

Virtual File System

In-memory snapshots for speculative evaluation

TypeScript Oracle

Language Service for diagnostics and candidate fixes

Repair Planner

Greedy selection with solver fallback for conflicts

Classifier

Labels each diagnostic by disposition

Verification Cone

Smart scope management keeps verification bounded for structural edits

Memory Guards

Production-ready with telemetry and resource management

Diagnostic Dispositions

After verification, each remaining diagnostic is classified so agents know exactly what to do.

AutoFixable Low risk

Verified fix exists and is safe to auto-apply. Add imports, fix typos, add async/await.

AutoFixableHighRisk Semantic risk

Verified fix exists but involves type assertions or coercions. Opt-in to apply.

NeedsJudgment Multiple options

Multiple verified fixes with comparable scores. Surface ranked options to the agent or human.

NoGeneratedCandidate No fix available

TypeScript has no suggested fix for this diagnostic. Manual investigation needed.

NoVerifiedCandidate Root cause issue

Fixes exist but none reduce errors. Indicates a root cause elsewhere that needs investigation.

Example Output

{
  "remaining": [
    {
      "diagnostic": "TS2304: Cannot find name 'foo'",
      "disposition": "AutoFixable",
      "risk": "low"
    },
    {
      "diagnostic": "TS2352: Type assertion required",
      "disposition": "AutoFixableHighRisk",
      "risk": "high"
    },
    {
      "diagnostic": "TS2345: Argument type mismatch...",
      "disposition": "NeedsJudgment",
      "candidates": 3
    },
    {
      "diagnostic": "TS2339: Property does not exist...",
      "disposition": "NoGeneratedCandidate",
      "note": "No TypeScript fix available"
    },
    {
      "diagnostic": "TS2322: Type mismatch...",
      "disposition": "NoVerifiedCandidate",
      "note": "Fixes exist but none reduce errors"
    }
  ]
}

Guarantees

Verified Fixes

Every fix in the plan is proven by the TypeScript compiler to reduce errors. No heuristics.

Monotonic Progress

Each committed fix reduces the diagnostic count. No fix that introduces more errors than it resolves.

Deterministic Output

Same input yields the same repair plan. No randomness, no heuristics that vary by run.

Agent Integration

ts-repair integrates with AI coding assistants via the Model Context Protocol (MCP).

MCP Tools

ts_repair_plan

Generate a verified TypeScript repair plan

ts_repair_apply

Apply verified repairs to files

ts_repair_check

Quick check for TypeScript error count

Claude Code

~/.claude/settings.json
{
  "mcpServers": {
    "ts-repair": {
      "command": "bunx",
      "args": ["ts-repair", "mcp-server"]
    }
  }
}

OpenCode

opencode.json
{
  "mcp": {
    "ts-repair": {
      "type": "local",
      "command": ["bunx", "ts-repair", "mcp-server"],
      "enabled": true
    }
  }
}

Codex CLI

~/.codex/config.toml
[mcp_servers.ts-repair]
command = "bunx"
args = ["ts-repair", "mcp-server"]
enabled = true

CLI Reference

Key commands for repair planning and application.

repair Primary command
ts-repair repair -p tsconfig.json
ts-repair repair --apply
ts-repair repair --json

Generate a verified repair plan with optional auto-apply.

plan Read-only planning
ts-repair plan -p tsconfig.json --format json

Generate a repair plan without mutating the workspace.

apply Apply fixes
ts-repair apply -p tsconfig.json --auto
ts-repair apply --plan plan.json

Apply verified repairs from a plan or auto-fix low-risk issues.

check tsc wrapper
ts-repair check -p tsconfig.json

Equivalent to tsc --noEmit. Quick error count.

Scoring strategies: --scoring-strategy delta (default) or weighted for nuanced repairs. Full CLI reference →

Programmatic API

Integrate ts-repair directly into your tooling, CI pipelines, or custom workflows.

Basic Usage

import { repair } from 'ts-repair';

const plan = await repair({
  project: './tsconfig.json',
  maxCandidates: 10,
  maxVerifications: 500,
});

console.log(`${plan.initialErrors} → ${plan.finalErrors} errors`);

for (const step of plan.steps) {
  console.log(`Apply: ${step.fixDescription}`);
}

Configuration Options

await repair({
  project: './tsconfig.json',
  // Max candidates per diagnostic
  maxCandidates: 10,
  // Max candidates per iteration
  maxCandidatesPerIteration: 100,
  // Verification budget
  maxVerifications: 500,
  // Include high-risk fixes (type assertions)
  includeHighRisk: false,
  // Scoring: 'delta' or 'weighted'
  scoringStrategy: 'delta',
});

maxCandidates — Limit candidates per diagnostic

maxVerifications — Total verification budget

includeHighRisk — Include type assertions (opt-in)

scoringStrategy'delta' or 'weighted'

What's Next

ts-repair is under active development for TypeScript. Here's what's on the roadmap.

Multi-Language

Rust, Go, and Python support using the same oracle-guided approach.

Protocol Spec

Formal specification for language-agnostic repair integration.

Weight Learning

Learn scoring weights from historical fix success data.