Morph forces LLMs to declare intent, not diffs. The open-source CLI in the dakshjain-1616 repo asks a model to emit a typed TransformationPlan, validates that plan against an AST-level dependency graph, then applies tree-sitter edits and runs pytest, rolling back on failures. The README and an accompanying Medium post show how to preview plans, save them as JSON, apply saved plans, run verification, and generate Markdown reports. Morph turns brittle model output into a verifiable, test-driven refactoring pipeline you can run locally or in the cloud.
Morph reframes where the large language model sits in the refactoring loop. Instead of asking the model to output diffs or patched source, Morph asks the LLM Planner for a typed TransformationPlan composed of Pydantic-modeled operations. Those operations look like RenameSymbol, MoveFunction, and ExtractModule. They read as intent, not raw edits. That difference is literal and consequential. A plan is human readable, machine checkable, and serializable as JSON.
How Morph separates intent from edits
At the center of Morph is a strict separation between intent generation and code mutation. The Planner is an LLM prompt that returns a TransformationPlan typed with Pydantic schemas. The Plan Validator then parses the repository with tree-sitter and builds a dependency graph represented with NetworkX. Validation checks include file existence, symbol existence, dependency conflicts, and conflicting operations inside the same plan. Only a plan that passes those checks moves forward.
When a plan is validated, a Transformer applies operations in dependency order using tree-sitter AST manipulation. Morph creates file backups before changing anything. After each atomic apply the Verifier runs the project's pytest suite. If any test fails the tool automatically rolls back to the backed-up state. Clean, test-passing changes are staged with GitPython and summarized in a machine-readable report for human review. The README frames the LLM's role as declaring intent rather than writing code, with the engine enforcing correctness and repeatability.
The repository includes concrete examples that make the workflow tangible. One example command runs a live refactor: morph refactor --goal "rename calculate_total to compute_total" ./src. You can preview without touching files by adding --dry-run, as in morph refactor --goal "extract validation logic into validate_input" ./src --dry-run. To persist a plan the README shows morph plan --goal "add type annotations to all functions in utils.py" ./src --output plan.json, and to apply a saved plan it documents morph refactor --plan plan.json ./src. Morph also exposes morph verify ./src to run test verification and morph report ./src --format markdown --output REFACTOR_REPORT.md to produce a human-readable run summary.
Backends, performance, and commercial siblings
Installation and backend setup are explicit in the README. The repo installs from source with pip install -e . For local inference the README recommends installing Ollama and pulling a model. For cloud backends Morph requires the appropriate API key environment variable. OpenRouter is labeled as recommended in the documentation, and OpenAI and Anthropic are supported as well.
The repo includes a live dry-run result that reports a rename goal parsed via anthropic/claude-haiku-4-5 through OpenRouter producing a validated RenameSymbol plan in under 5 seconds.
Separate commercial offerings using the same name also exist. A Morph-branded commercial product set described on a vendor site and a third-party integration page presents a Morph Apply model that claims semantic code application at more than 2,000 tokens per second, along with self-hosting and enterprise deployment options such as VPC deployment and GDPR compliance. Those materials position Morph-style tooling as complementary to frontier models like GPT-4o and Claude while packaging enterprise features and deployment controls that the open source repo doesn't provide out of the box.
The open source repository positions itself as both a usable CLI and a reference implementation for teams that want deterministic, test-driven AI-assisted refactoring. The operation set is extensible: teams can add new Pydantic operation schemas and update the planner prompts. This project's blog and repository notes recommend starting with a small real-world dataset and running end-to-end commands to compare output quality and latency before attempting production scale.
Practically speaking Morph gives engineers a way to treat LLMs as planners and validators rather than as direct code authors. That matters for teams who want auditability and rollback guarantees.
Plans are readable JSON, verification is automated with pytest, and every mutating step creates backups so rollbacks are reliable. The pipeline binds model output to actual tests rather than trust.
There are trade-offs. Requiring a validated plan adds latency compared with sending an LLM-generated diff straight into a codebase. You also need a test suite that catches regressions for the rollback safety net to work. The README recommends those same caveats: start small, measure latency and output quality, then expand to production workloads if the results meet your standards.
Related Articles
- 3 Requirements for Shipping a Healthcare iOS App
- Maka Kids raises $3M, launches screen-time app for ages 0-6
- 8 Healthchecks.io Alternatives for Developers
Morph is available now on GitHub under dakshjain-1616. The README includes installation steps such as pip install -e ., documents supported inference backends and required API keys, and links to reproduction steps for the demo dry-run.
This article was created with AI assistance.