---
title: "How Cursor Apply Works"
url: "https://www.morphllm.com/blog/cursor-apply"
description: "An analysis of Cursor's breakthrough in achieving 1000 tokens per second for code edits through specialized models and inference methods."
date: "2025-05-01"
---
# How Cursor Apply Works

# Analyzing Cursor Apply

Cursor put out a [technical deep-dive](https://web.archive.org/web/20240823050616/https://www.cursor.com/blog/instant-apply) on how they apply code edits, and it's worth reading closely. The headline number is 1000 tokens per second on large edits, but the interesting part is what they had to do to get there.

## The problem nobody warns you about

Everyone assumes the hard part of an AI code editor is deciding what to change. It isn't. The hard part is applying the change, fast, and having it work every single time at scale. Cursor lays out why frontier models like GPT-4o and Claude fall down here. Token-by-token generation is too slow to feel instant. The models make real mistakes on anything complex. And when you retry, multiple model calls drift into inconsistency or loop forever.

That last one is the killer, and Cursor has the receipt for it:

> "Even small, isolated edits are plagued with bugs [...] SWE-Agent attempts a simple edit seven times before giving up due to a consistent syntactic error."
<video src="https://morphllm.com/swe_agent.mp4" autoPlay muted loop playsInline className="w-full rounded-lg">
  <p>Figure 1: SWE-Agent attempts a simple edit seven times before giving up due to a consistent syntactic error.</p>
</video>

Seven tries at one edit, then it quits. That's not a model that can't reason. It's a model that can't reliably type the answer it already has. Which is exactly the wall we keep hitting too.

## How Cursor sets up the context

Before Cursor applies anything, it works hard to hand the model the right context. A query gets embedded with a specialized model, and the system pulls the top-k most relevant syntax chunks out of the codebase, so the model sees what matters without drowning in the whole repo. Those chunks then get reranked, so the most useful code lands first rather than somewhere in the middle where it gets ignored. They run all of this through Priompt, their own prompting framework built to prioritize context and put the critical pieces in the positions a model actually attends to. Only after all that does the apply phase run, on their specialized fast-apply model, Llama-3-70b-ft, which executes the planned change against the context that was gathered.

## The implementation choices that matter

The first real decision is full-file rewriting versus diffs, and Cursor went with rewriting the whole file. Three reasons, and they're good ones. More output tokens means more forward passes for the model to reason its way to the right answer, so the extra tokens buy accuracy rather than waste. Models have also simply seen far more complete files than diffs in training, so full files sit closer to what they're good at. And diffs force the model to count line numbers, which models are famously bad at.

On architecture, they started from Llama-3-70b and report a "~13x speedup over vanilla inference," and a "~9x speedup over previous GPT-4 speculative edits deployment." The mechanism behind that is their most interesting idea, speculative edits, which they describe like this:

> "With code edits, we have a strong prior on the draft tokens at any point in time, so we can speculate on future tokens using a deterministic algorithm rather than a draft model."

In plain terms: when you're editing a file, you already know most of what the output will be, because most of the file isn't changing. So instead of training a separate draft model to guess the next tokens, you just use the original file as the guess. That gets them a 4-5x speedup with the same accuracy as a full rewrite, and it comfortably beats GPT-4 running standard speculative decoding.

## How they measure it

Their evaluation is refreshingly literal. Speed is characters rewritten divided by how long the rewrite took:

```python
speed = Num_Rewritten_Chars / Latency_for_Rewrite_in_seconds
```

By that measure they land around 1000 tokens/s and 3500 char/s, and it holds steady on files up to 400 lines.

## What they learned training the model

A few of their training calls are worth stealing. They downsampled files under 100 LOC, balanced the number of examples per filename so no single file dominated, and threw out no-op transformations that teach the model nothing. On model choice, they tried both Deepseek Coder Instruct and Llama 3, and the fine-tuned Llama-3-70b came out ahead, beating even GPT-4 Turbo in their evals.

They're honest about what's still hard. Long context is the big one, with files up to 2500 lines on the roadmap. They're looking at distilling down to llama-3-8b to shrink the model, and at on-policy RL to push accuracy further.

## Why this lines up with what we're building

Reading this felt like validation, because it confirms the things we've been betting on at Morph. That code editing wants a specialized model, not a general one stretched to fit. That full-file context beats diffs. And that speculative decoding is the right tool for code, where the prior is unusually strong.

More than anything, their split of the problem into a planning phase and an apply phase is the right shape. It takes something messy and turns it into two clean jobs, and that clarity is most of the battle.

## Where morph-v0 lands

We've been chasing the same target as Cursor Apply, with the dial turned harder toward speed and accuracy. Our version uses one specialized model to plan the change and a separate specialized model to apply it. That's gotten us to 10,500+ tokens/s, holding across files up to 1500 lines.

A few things we ran into along the way. Linearly scaling RoPE ids doesn't hold up; to make this work you have to train on a large dataset of real code edits with genuinely long input and output sequences, not short ones stretched. Large files get memory-hungry fast and eat a lot of compute. And process reward modeling looks promising but would slow applies down, since the reward model would have to emit diffs and those diffs would need to earn their keep as better context than the original code, which isn't a given.
