Vibe Engines
YouTube
AI System Design

Design Cursor

Learn AI system design by designing an AI code editor like Cursor around the edit problem.

The numbers to beat2models1plan1real file

The whole design, in writing

Learn AI system design by designing an AI code editor like Cursor around the edit problem. An interactive guide covering why retyping 4,000 tokens to change 30 costs 80 seconds, the plan model and the apply model, why the apply step rewrites the whole file instead of writing a diff, speculative edits that turn 80 seconds into 2.2, a context index kept fresh by a Merkle tree, the Tab model priced against silence, the agent loop with checkpoints, and the freshness check that catches a right-looking edit made against a file that has moved.

Every step of the build above, written out: the problem each piece solves, the option that was taken and the ones that were not, the numbers, and how it fails in production.

The big idea

"Design an AI code editor" — why is this even hard?

You select a line and type make the timeout 30 seconds, and a second later the file has changed and nothing else has. A model did that by writing text, in small pieces called tokens. Say the file is 400 lines at about 10 tokens: that is 4,000 tokens, and at 20 ms a token that is 80 seconds, to change about 30 of them. And you will be watching.

YouThe File
New in this step: You, The File. · swipe to pan the diagram

Never pay for what did not change. Plan first, rewrite the whole file so there are no line numbers to get wrong, use the old file as the draft so copying is nearly free, find files through an index that only re-embeds what changed, speak only when a suggestion beats silence, loop with checkpoints, and check the file has not moved.

What the new pieces do

Youclient
The person typing. “Make the timeout 30 seconds” is the whole input; everything else is the editor deciding how to turn it into a change that lands in one file without disturbing the rest.
The Filestore
The 400-line file being changed. About 4,000 tokens, of which about 30 actually change. Retyped at 20 ms a token it would take 80 seconds.

Step 1 · Plan and apply

Two models, two jobs

One request, and the model has to both decide what to change and write the file. A big chat model is good at the first and slow at the second. If one model does both, which of the two do you give up?

Youone requestPlannerbig chat model
New in this step: Planner.

How should the editor split the work of making a change?

  1. It is smart but slow, so you wait for the large model to produce every token of a file that is mostly unchanged.

  2. Planning needs intelligence and applying needs speed. Splitting them lets each do what it is good at.

  3. Choosing what to change across a codebase is the hard part, and a small model will often choose badly.

The Planner, a big chat model, sketches the change in prose and fragments. The Apply Model, smaller and fast, turns that sketch into the real file. The hand-off is the price.

Why this piece earns its place

A plan is cheap to produce and cheap to be wrong about, so it belongs to the model that is good at deciding. Writing out a four-thousand-token file token by token is a different skill: it wants speed and exactness, not breadth. Splitting the two means the expensive model never has to emit the whole file, and the fast model is trained for exactly one thing, turning a sketch plus the old file into the new file. The trade is honest and worth stating: a hand-off between two models can lose a line, because the plan is a sketch and the applier has to fill in what the sketch left out. The rest of the design is mostly about making the second half of that hand-off fast and exact.

  • 2models
  • 1plan
  • 1real file

What the new pieces do

Plannerplan
A large chat model that sketches the change: what to alter and roughly where. It is smart and slow, so it never writes the final file.

Step 2 · The rewrite

The whole file, not a diff

The apply model has to hand back a changed file. The compact way to describe a change is a diff: line 212, remove this, add that. It is a few tokens instead of four thousand. Why would anyone choose to write the whole file?

The File400 lines · 4,000 tokensPlannerbig chat modelApply Modelrewrites the whole file
New in this step: Apply Model.

What should the apply model output?

  1. It is small, but it carries line numbers, and models are poor at counting lines. Three edits carry six numbers.

  2. That leaves a person or a script to guess where they go, which is the same line-number problem in another form.

  3. Models see far more whole files than diffs, and a rewrite carries nothing to miscount.

The apply model rewrites the whole file. A diff of 3 edits carries 6 line numbers; at 2% wrong each, 1 − 0.98⁶ is 11.4% wrong. A rewrite carries none, at the price of producing or verifying every token.

Why this piece earns its place

The diff looks like the smart answer and fails for a quiet reason: it asks the model to do something it is bad at. Counting lines in a long file is exactly the kind of exact bookkeeping a language model gets wrong a small percentage of the time, and a small percentage compounds: three edits are six numbers, and six chances at two percent is about one edit in nine landing in the wrong place, without any error being raised. Models have also seen vastly more whole files than diffs, and a rewrite gives the answer more forward passes to get right. The cost is that you now owe every token, four thousand of them, and eighty seconds at twenty milliseconds each. That bill is exactly what the next step is for.

  • 6line numbers in a 3-edit diff
  • 11.4%wrong at 2% each
  • 0numbers in a rewrite

What the new pieces do

Apply Modelmodel
A smaller, fast model that turns the plan into the real file. It rewrites the whole file instead of writing a diff, because models are poor at line numbers.

Step 3 · Speculative edits

The old file is the draft

The rewrite is right and slow: 4,000 tokens, 80 seconds, and 3,970 of them are exactly what was already there. The model generates one token per pass. How do you stop paying a pass for each token it already knows?

The File30 tokens change · 3,970 copiedApply Model110 passes, not 4,000Speculationold file is the draft
New in this step: Speculation.

How do you make a whole-file rewrite fast?

  1. Copying is nearly free in bulk: only the changed tokens need real generation.

  2. A smaller model is faster per token, but it is still paying a pass for every one of the 4,000 tokens.

  3. The model has to confirm they are unchanged, and a copied run that was silently altered is the failure you were avoiding.

Speculative edits: the model checks the old file as a draft, about 50 tokens per pass. 30 new tokens plus about 80 copy passes is 110 passes: 2.2 seconds against 80, about 36×. Cursor reports around 1,000 tokens a second and about 13× over standard serving; that is theirs, not ours.

Why this piece earns its place

A language model is slow because it generates one token per pass. It can, however, verify many tokens in one pass: feed it a guess and it tells you how many in a row match what it would have written. The old file is a perfect guess for nearly everything, so the model accepts runs of fifty at a time and generates fresh only where the edit is. That is where the arithmetic comes from: thirty new tokens, plus about eighty passes for the other 3,970, a hundred and ten passes at twenty milliseconds. The output is identical to a full rewrite, which is the whole point. The honest limit is just as important: the speedup is only as good as the match. Rewrite most of the file and nothing matches, so there is nothing to copy and the time returns to eighty seconds.

  • 110passes, not 4,000
  • 2.2 sagainst 80 s
  • 36×faster, same file

What the new pieces do

Speculationspeed
Uses the old file as the draft and verifies it about fifty tokens at a time in one pass. Only the changed tokens cost real time: about 110 passes instead of 4,000.

Step 4 · The context index

Finding the file, cheaply and freshly

So far you pointed at one file. A real request touches code you have never opened. The editor has to find the right chunks, which means vectors for every chunk of a repo, and a repo changes all day. How do you keep that index current without redoing all of it?

The File30 tokens change · 3,970 copiedPlannerbig chat modelApply Model110 passes, not 4,000Context Index12 files re-embedded, not 10,000
New in this step: Context Index.

A 10,000-file repo has 50,000 chunks and you edited 12 files. What should re-embed?

  1. At 500 chunks a second that is 100 seconds of work for a 12-file change.

  2. A Merkle tree finds the changed files without comparing everything: 60 chunks, about 0.12 seconds.

  3. Then every question starts with a search through ten thousand files, which is the cost the index exists to avoid.

The Context Index: code is cut into chunks, embedded as vectors and stored with masked paths. A Merkle tree of file hashes finds what changed, so 12 files is 60 chunks, 0.12 s, not 50,000 chunks and 100 s. The price: it is stale for minutes between syncs.

Why this piece earns its place

Retrieval is what lets a request about “the auth flow” find the three files that matter. The index is a store of vectors, one per chunk, so that meaning, not just spelling, can be searched. Its problem is upkeep. Re-embedding everything on every edit is wasteful by four orders of magnitude, so each file gets a hash, each folder a hash of its children’s hashes, up to one root. Compare roots and you descend only where they differ, finding the twelve changed files without touching the other nine thousand nine hundred eighty-eight. Public write-ups describe a sync roughly every five minutes and only vectors and masked paths stored server-side, not source; I attribute those to the write-up. That gap, minutes, is the cost, and it is the setup for the last step.

  • 50,000chunks in the repo
  • 60chunks re-embedded
  • 0.12 sagainst 100 s

What the new pieces do

Context Indexstore
Vectors for every code chunk, kept fresh by a Merkle tree of file hashes so only changed files are re-embedded. It is stale for minutes between syncs.

Step 5 · Tab

Speak only when it beats silence

Tab predicts your next edit while you type. Every suggestion that appears and gets rejected costs you a glance and a keystroke. Showing nothing costs nothing. What should decide whether it speaks?

The File30 tokens change · 3,970 copiedTabspeaks only above 25%
New in this step: Tab.

Rewards are +0.75 accepted, −0.25 rejected and 0 not shown. When is a suggestion worth showing?

  1. Only when it is accepted often enough. Below the break-even the average is negative.

  2. That throws away a lot of useful suggestions. The threshold follows from the reward, not from a round number.

  3. 0.75p − 0.25(1 − p) = p − 0.25, which is zero at exactly 25%.

Tab shows a suggestion only when its expected reward beats silence. With +0.75, −0.25 and 0, the break-even is exactly 25%: at 40% a suggestion is worth +0.15, at 20% it is worth −0.05, so it stays quiet. Cursor reports 21% fewer suggestions and a 28% higher accept rate; attributed, not endorsed.

Why this piece earns its place

The reward arithmetic is the whole design. If an accepted suggestion is worth three-quarters of a point and a rejected one costs a quarter, the expected value of showing is p times 0.75 minus one-minus-p times 0.25, which simplifies to p minus a quarter. It is positive above twenty-five percent and negative below, so the threshold is not a tuning knob, it follows from what you decided accepts and rejects are worth. Training the model online on real accepts and rejects teaches it where that line is for you. The cost is the thing it learns from: what you click, which is not always what is right, and a model trained to be welcome can learn to be agreeable.

  • +0.75accepted
  • −0.25rejected
  • 25%break-even

What the new pieces do

Tabservice
The next-edit suggestion model. It is trained on accepts and rejects and shows a suggestion only when its expected reward beats silence.

Step 6 · The agent loop

Many files, and a way back

One request, ten files. The editor has to plan, edit, run, read the result and go again, many times. Each step can be wrong, and your own work is somewhere in those files. What keeps a long edit from being a leap of faith?

Agent Loopmany files, many stepsCheckpointslocal snapshots · a diff
New in this step: Agent Loop, Checkpoints.

Each step of an agent is right 95% of the time. How often is a 10-step run right end to end?

  1. The steps compound: you need all of them to be right.

  2. Ten steps at 95% each multiply, which is why a long run needs review and an undo.

  3. Five wrong steps in ten would be a 50% error rate per step. Here each is 5%, but they compound.

The Agent Loop carries one request across many files. Checkpoints are local snapshots of its changes, so any of it can be undone, and you read a diff. Ten steps at 95% is about 60% right end to end, which is why the diff is for reading.

Why this piece earns its place

An agent turns a request into a sequence: find the files, plan an edit, apply it, run something, read the error, go again. The arithmetic of a sequence is unkind, because the end-to-end success is the product of each step, and ninety-five percent ten times is about sixty. That is not an argument against loops; it is an argument for making each step reviewable and reversible. A checkpoint is a local snapshot taken before the agent’s edits, so one click returns to before. Two honest limits: checkpoints are not version control, and they do not track edits you made yourself, so they undo the agent’s work and nothing else. The diff is what a human reads at the end, which is where a person is worth the most.

  • 0.95¹⁰is about 60%
  • localsnapshots
  • 1diff you read

What the new pieces do

Agent Loopservice
Carries one request across many files in many steps. Errors compound: ten steps at 95% each is about 60%.
Checkpointsundo
Local snapshots of the agent’s changes so a multi-file edit can be undone. Not version control, and they do not track your own manual edits.

Step 7 · Freshness

The hidden slot: is the file still the file?

Six of six parts are built and every check is green. But the plan was made from an index that is minutes old, and someone moved a function in between. The edit lands, the file compiles, and the change sits on a line that is no longer the line you meant. What is the slot you only find by running it?

The FileContext IndexTabAgent LoopCheckpointsFreshness Check
New in this step: Freshness Check. · swipe to pan the diagram

The edit is right against the index and the index is a few minutes old. What should happen before it lands?

  1. A mismatch means the file moved, so the plan is re-read instead of applied blindly.

  2. Minutes is long enough for a file to move, and the failure raises no error.

  3. That is the 100-second cost the Merkle tree was built to avoid.

The Freshness Check: hash the file as it is now before an edit lands, run the same checks as a human edit, and show a diff you read. A mismatch means the file moved, so re-read it rather than apply a plan made against yesterday’s file.

Why this piece earns its place

The failure here is not a crash, and that is what makes it the interesting one. A right-looking edit, made against a file that has moved, applies cleanly and passes a glance. Every earlier part was about writing less or seeing more; this one is about asking whether what was seen is still true. The index is stale by design, because syncing continuously costs more than it is worth, so the staleness has to be caught at the last moment, where it is cheap: one hash of one file. Running the same checks a human edit would face, formatting, types, tests, means the editor’s change is held to the same bar as yours. The diff is the last guard, and the cheapest, because a person reads it before it is kept.

  • 1hash per edit
  • samechecks as a human edit
  • 1diff you read

What the new pieces do

Freshness Checkgate
The hidden seventh slot. The index is minutes old and files move, so hash the file as it is now before an edit lands, run the same checks as a human edit, and show a diff you read.

The payoff

You designed an AI code editor

From “retype the file” to a build ladder: a planner and an apply model, a rewrite instead of a diff, speculative edits from the old file, a context index kept fresh by a Merkle tree, a Tab model priced against silence, an agent loop with checkpoints, and a freshness check, because the index is always a little old.

YouThe FilePlannerApply ModelSpeculationContext IndexTabAgent LoopCheckpointsFreshness Check
The finished design, end to end. · swipe to pan the diagram

Now ask for a diff and watch one edit in nine land in the wrong place, rewrite everything and watch the speedup vanish, then skip the freshness check. Those three are the whole trade-off: not paying for what did not change buys speed, and every part has a price.

Everything you assembled, in order

  • Plan and apply — a big model sketches, a fast one writes the file
  • Rewrite — the whole file, no line numbers; 6 numbers at 2% is 11.4% wrong
  • Speculation — old file as draft; 110 passes, 2.2 s, not 4,000 and 80 s
  • Context index — vectors + Merkle tree; 60 chunks, not 50,000
  • Tab — shown only above 25% accept chance
  • Agent loop — checkpoints and a diff; ten steps at 95% is 60%
  • Freshness check — hash the file now; same checks as a human edit
  • The numbers — 80 → 2.2 s · 100 → 0.12 s · 25% break-even

Deep cut · 13:50

One line changed in a 400-line file.

The interactive build above lays out an AI code editor around the edit problem: a planning model that sketches the change and a fast apply model that writes the file, a whole-file rewrite instead of a diff, speculative edits that use the old file as the draft, a context index kept fresh by a Merkle tree, a Tab model that speaks only when its expected reward beats silence, and an agent loop with checkpoints and a diff you read. The film builds the same parts live around one 400-line file and one request, make the timeout 30 seconds, and then finds the hidden seventh slot: freshness. It is built from Cursor’s public posts plus first principles, not anyone’s internals; figures Cursor reports are attributed to Cursor and not endorsed.

  • See the envelope: 400 lines at about 10 tokens is 4,000 tokens, 80 seconds at 20 ms each, to change 30. Speculated, it is 30 new tokens plus 80 copy passes: 110 passes, 2.2 seconds, 36 times faster. A diff with 3 edits is 6 line numbers, wrong 11.4% of the time at 2% each.
  • Take it into the interview: rewrite instead of diff, copy what is already right and verify it in bulk, re-embed only the files whose hash changed, show a suggestion only above a 25% accept chance, and check the file has not moved before an edit lands.

Where an interviewer pokes next

Getting the boxes right is the easy half. These are the questions that separate a candidate who drew the diagram from one who has run the thing. Answer each one out loud before you open it.

  1. Why does the apply model rewrite the file instead of writing a diff?

    Because a diff needs line numbers and models are poor at counting lines. Three edits carry six numbers, and at 2% wrong each that is about 11.4% of edits landing in the wrong place with no error raised. A rewrite carries no numbers, and models have also seen far more whole files than diffs.

  2. How do speculative edits make a rewrite fast, and when do they not?

    The old file is used as the draft and verified about fifty tokens at a time in one pass, so 30 new tokens plus about 80 copy passes is 110 passes, 2.2 seconds, against 80. When the edit changes almost everything nothing matches, there is nothing to copy, and the time returns to 4,000 passes, 80 seconds.

  3. How does a Merkle tree keep the index fresh without re-embedding everything?

    Each file has a hash and each folder a hash of its children, up to one root. Compare roots and descend only where they differ, so 12 changed files of 10,000 means 60 chunks, about 0.12 seconds, instead of 50,000 chunks and 100 seconds. The cost is that the index is stale for minutes between syncs.

  4. How do you decide when Tab should show a suggestion at all?

    Price it against silence. With +0.75 for an accept, −0.25 for a reject and 0 for not shown, the expected value is p − 0.25, so the break-even is exactly 25%. At 40% a suggestion is worth +0.15; at 20% it is worth −0.05, so it should stay quiet.

  5. What fails quietly in an edit pipeline, and what catches it?

    A right-looking edit made against a file that has moved since the index was built. It applies cleanly and raises no error. Hash the file as it is now before the edit lands, run the same checks as a human edit, and show a diff a person reads.

Check yourself — the answers, and why

Eight steps in, these are the calls you should be able to make cold. Pick one, then read why.

  1. A file is 400 lines at ~10 tokens a line, written at 20 ms a token. What does retyping all of it cost?

    400 × 10 = 4,000 tokens, and 4,000 × 20 ms = 80 seconds. Only about 30 of them change.

  2. Why does the apply step rewrite the file instead of emitting a diff?

    Three edits carry six line numbers; at 2% wrong each, 1 − 0.98⁶ is about 11.4%. A rewrite has no numbers. It is made fast by speculation, not by being shorter.

  3. 30 new tokens plus about 80 copy passes at 20 ms each. How long does the edit take?

    30 + 80 = 110 passes × 20 ms = 2.2 seconds, about 36× faster than 80. If nothing matched, it would return to 4,000 passes.

  4. A repo of 50,000 chunks and 12 edited files (60 chunks). What does a Merkle tree save?

    Hashes of hashes let you descend only where they differ. The cost is an index that is stale for minutes between syncs.

  5. Rewards are +0.75 accepted, −0.25 rejected, 0 not shown. At what accept probability should Tab speak?

    The expected value is p − 0.25, which is zero at exactly 25%.

  6. The edit is right against an index that is a few minutes old. What must happen before it lands?

    A stale index plus a moved file gives a right-looking edit in the wrong place, with no error. One hash, at the last moment, catches it.

How you’d open this design in an interview

Before any boxes: agree what it must do, pin the qualities that shape everything, then build — naming each trade-off as you make it. The walkthrough above is that exact order.

What it must do

Agree on these before drawing a single box.

  • Change: alter only what was asked and leave the rest of the file alone.
  • Feel instant: the edit has to land while you are watching.
  • Find: locate the right files without being told.
  • Guess: predict your next edit and stay welcome.
  • Carry: take one change across many files.
  • Undo: be reviewable, and reversible.

The qualities that shape everything

Each one names the mechanism that buys it.

An edit lands in seconds, not minutes
4,000 tokens × 20 ms = 80 seconds retyped. Speculated from the old file it is 30 new tokens plus about 80 copy passes: 110 passes, 2.2 seconds (illustrative).
The result equals a full rewrite
Every copied run is verified by the apply model in one pass, so a fast file is the same file a slow rewrite would have written.
No line numbers to get wrong
A diff of 3 edits carries 6 numbers; at 2% each, 1 − 0.98⁶ is 11.4% wrong. A rewrite carries none.
The index does not re-embed everything
10,000 files × 5 chunks = 50,000 chunks, 100 seconds at 500 a second. A Merkle tree finds the 12 changed files: 60 chunks, 0.12 seconds.
Silence beats a bad suggestion
Rewards of +0.75 accepted, −0.25 rejected, 0 not shown put the break-even at exactly 25%.
The index never lies about the file
A hash check against the file as it is now, before an edit lands, plus the same checks as a human edit and a diff you read.

The trade-offs you say out loud

Senior signal isn’t the boxes — it’s naming what you gave up and why it was the right price.

Split plan and apply over one model that does both

A smart planner and a fast applier, each doing what it is good at. The cost is a hand-off that can lose a line.

Rewrite the whole file over emitting a diff

Models are poor at line numbers and have seen far more whole files than diffs. The cost is that every token must be produced or verified.

Speculate from the old file over generating every token fresh

Copying is nearly free in bulk. The cost is that a heavy rewrite, where nothing matches, gets no speedup at all.

Index with a Merkle tree over re-embedding on every change

Only changed files are re-embedded. The cost is an index that is stale for minutes between syncs.

Train Tab on accepts over showing every suggestion

The model learns to stay quiet when unsure. The cost is that it learns what you click, not what is right.

Agent loop with checkpoints over one edit at a time by hand

Multi-file work you can undo. The cost is that errors multiply per step: ten steps at 95% each is 60%.

The answer, out loud

What a strong answer to “Design Cursor” sounds like, first question to last trade-off. It is about 4 minutes of talking; the whiteboard and the interviewer fill the rest of the 45. Read it aloud once, then close the page and give it yourself.

  1. 0–2 min

    Put the number on the board

    Before I draw a box I want one number. Say the file is four hundred lines at about ten tokens a line. That is four thousand tokens, and at twenty milliseconds a token, retyping it to change one line is eighty seconds. Thirty of those tokens actually change. These figures are illustrative, and I am designing from Cursor’s public posts and first principles, not anyone’s internals. But the shape is the point: almost everything the model would write is already on the page. So I would spend my first minute on that gap, because every part I add is a way of not paying for tokens that did not change.

  2. 2–4 min

    Plan, then apply, and why not a diff

    I would split the job. A large chat model plans: it sketches the change in prose and in fragments. A smaller, fast model applies: it writes the real file. The obvious output for the apply step is a diff, and I would argue against it. A diff needs line numbers, models are poor at counting lines, and three edits carry six numbers. At two percent wrong each that is one minus point-nine-eight to the sixth, about eleven percent of edits landing in the wrong place. So the apply model rewrites the whole file, with no numbers to get wrong. The cost I would own: every token must now be produced or verified.

    Built in step 2: The whole file, not a diff
  3. 4–7 min

    Speculate from the old file

    That cost is the speed problem, and here is the trick. The old file is already the draft. The model checks it fifty tokens at a time in a single pass, accepts the run while it matches, and only generates fresh where the edit is. Thirty new tokens, plus about eighty copy passes for the other three thousand nine hundred seventy: a hundred and ten passes, two point two seconds, thirty-six times faster than eighty. Cursor reports around a thousand tokens a second and about thirteen times over standard serving; I attribute that to them and do not endorse it. The honest limit: if the edit rewrites everything, nothing matches and there is no speedup.

    Built in step 3: The old file is the draft
  4. 7–9 min

    Context, and the Merkle tree

    To know which files to touch, I would chunk the code, embed each chunk, and store vectors with masked paths. The trap is re-embedding fifty thousand chunks, a hundred seconds at five hundred a second, for a twelve-file edit. A Merkle tree of file hashes finds only the changed files, sixty chunks, a tenth of a second. The trade is staleness between syncs, which I would say out loud.

    Built in step 4: Finding the file, cheaply and freshly
  5. 9–11 min

    Tab and the agent loop

    Tab is a different problem: when to speak. With a reward of plus point-seven-five for an accept, minus a quarter for a reject and zero for silence, the break-even is exactly twenty-five percent. At forty percent a suggestion is worth plus point-one-five; at twenty it costs point-oh-five, so it should stay quiet. For the agent loop I would add checkpoints so a multi-file change is undoable, and a diff you read, because errors compound: ten steps at ninety-five percent each is about sixty percent.

    Built in step 6: Many files, and a way back
  6. 11–13 min

    The hidden seventh slot

    Then I would raise the slot nobody draws: freshness. The index is minutes old, the file has moved, and a right-looking edit lands on a line that is no longer there. Nothing errors, so I would hash the file as it is now before an edit applies, run the same checks as a human edit, and show the diff. I would close by naming the prices: a hand-off, a heavy rewrite with no speedup, a stale window, and a model that learns what you click.

    Built in step 7: The hidden slot: is the file still the file?

What this teaches

Learn AI system design by designing an AI code editor like Cursor around the edit problem. An interactive guide covering why retyping 4,000 tokens to change 30 costs 80 seconds, the plan model and the apply model, why the apply step rewrites the whole file instead of writing a diff, speculative edits that turn 80 seconds into 2.2, a context index kept fresh by a Merkle tree, the Tab model priced against silence, the agent loop with checkpoints, and the freshness check that catches a right-looking edit made against a file that has moved.

Key takeaways

  • Plan and apply — a big model sketches, a fast one writes the file
  • Rewrite — the whole file, no line numbers; 6 numbers at 2% is 11.4% wrong
  • Speculation — old file as draft; 110 passes, 2.2 s, not 4,000 and 80 s
  • Context index — vectors + Merkle tree; 60 chunks, not 50,000
  • Tab — shown only above 25% accept chance
  • Agent loop — checkpoints and a diff; ten steps at 95% is 60%
  • Freshness check — hash the file now; same checks as a human edit
  • The numbers — 80 → 2.2 s · 100 → 0.12 s · 25% break-even

Concepts covered

  • "Design an AI code editor" — why is this even hard?
  • Two models, two jobs
  • The whole file, not a diff
  • The old file is the draft
  • Finding the file, cheaply and freshly
  • Speak only when it beats silence
  • Many files, and a way back
  • The hidden slot: is the file still the file?
built to be reasoned about, not memorized — rewrite, never diff; copy what is already right; check the file has not moved.
Finished this one? 0 / 65 AI System Designs done

Explore the topic

See this alongside everything else on the same subject — handbooks, system designs, challenges and tools, in one place.

More AI System Designs