All notes

How Cursor Can Rewrite 15 Files From One Prompt

Changing one file is easy. But how does Cursor refactor an entire project with a single prompt? The answer isn't just an LLM—it's planning, tool calling, and AI agents working together.

5 min read

Imagine you have a Java project with:

250 Files
 
35 Packages
 
120,000 Lines of Code

You open Cursor and type:

Convert this project from JavaScript to TypeScript.

A few seconds later...

tsconfig.json ✅
 
package.json ✅
 
Login.tsx ✅
 
Navbar.tsx ✅
 
AuthService.ts ✅
 
API Types ✅
 
15 Files Updated

You only wrote one sentence.

How did Cursor know which files to edit?

Surely it didn't send your entire project to GPT.

Most LLMs can't even fit a medium-sized codebase into their context window.

So what's actually happening?

The Naive Solution

Most people imagine something like this.

Entire Repository
 
↓
 
GPT
 
↓
 
Updated Repository

Unfortunately...

That doesn't work.

Imagine your project contains:

500,000 Lines of Code

Even the largest context windows have limits.

Reading the entire repository for every prompt would also be incredibly expensive and slow.

Clearly, Cursor needs a smarter approach.

Step 1: Build A Map Of Your Codebase

Before you even ask a question...

Cursor indexes your project.

It learns things like:

Instead of remembering raw code...

It builds a searchable representation.

Think of it as creating Google Search for your own project.

Step 2: Find Only The Relevant Files

Suppose you ask:

Convert authentication to TypeScript.

Cursor doesn't open every file.

Instead, it searches for files related to authentication.

Something like:

AuthService.js
 
↓
 
Login.jsx
 
↓
 
Register.jsx
 
↓
 
api/auth.js
 
↓
 
types/user.js

Only these files are sent to the model.

This is why Cursor feels so fast.

The AI reads only what matters.

Step 3: The LLM Creates A Plan

This is where Cursor behaves differently from a normal chatbot.

Instead of immediately generating code...

It first reasons about the task.

A simplified plan might look like:

Find JavaScript Files
 
↓
 
Create Type Definitions
 
↓
 
Update Imports
 
↓
 
Rename Extensions
 
↓
 
Fix Compilation Errors
 
↓
 
Verify Build

The model is no longer just generating text.

It's planning work.

This is one of the defining characteristics of an AI Agent.

Step 4: Tool Calling

The AI itself cannot modify your files.

Instead...

It requests tools to perform actions.

For example:

Read File
 
↓
 
Edit File
 
↓
 
Rename File
 
↓
 
Search Project
 
↓
 
Run Terminal Command

The editor executes those actions.

A simplified flow looks like this.

User Prompt
 
↓
 
LLM
 
↓
 
Tool Request
 
↓
 
Cursor Executes Tool
 
↓
 
LLM Receives Result
 
↓
 
Next Decision

This loop repeats until the task is complete.

Step 5: One Edit Changes Everything

Suppose the AI renames:

User.js
 
↓
 
User.ts

Suddenly...

Every import breaks.

Instead of stopping...

The agent searches for every affected file.

Login.tsx
 
↓
 
Dashboard.tsx
 
↓
 
Profile.tsx
 
↓
 
Settings.tsx

Each broken import becomes another task.

The AI continues until the project becomes consistent again.

This is why a single prompt often updates many files.

Step 6: Understanding Code With ASTs

Another interesting question.

Why doesn't Cursor edit code using simple Find & Replace?

Because code isn't plain text.

Consider this.

const user = getUser();

Changing every occurrence of user using string replacement would also modify comments, strings, and unrelated variables.

Instead, modern tools often work with an Abstract Syntax Tree (AST).

An AST represents code as a structured tree rather than plain text.

For example:

Function
 
├── Parameters
 
├── Variable
 
├── Return Statement

By understanding the structure of the code, tools can make much safer edits.

This is one reason large refactors are surprisingly accurate.

Step 7: Verify The Result

Making edits isn't enough.

Cursor often checks whether the project still works.

For example:

Run TypeScript Compiler
 
↓
 
Run ESLint
 
↓
 
Run Tests

If errors appear...

The AI reads them.

Creates another plan.

Applies another fix.

This process repeats until the project builds successfully or the model reaches its stopping point.

This Is Called The Agent Loop

Unlike ChatGPT, which usually answers once...

AI coding assistants continuously iterate.

Think
 
↓
 
Read Code
 
↓
 
Plan
 
↓
 
Call Tool
 
↓
 
Analyze Result
 
↓
 
Repeat

This cycle is called the Agent Loop.

The model keeps solving the problem until it reaches the goal.

Follow-Up Questions Interviewers Love

Why not send the whole repository to the LLM?

Large repositories exceed the model's context window and dramatically increase latency and cost.

Retrieving only relevant files is far more efficient.


Why use tool calling?

LLMs generate text.

They cannot directly edit files or execute commands.

Tool calling allows the model to interact with the outside world safely.


Why are ASTs better than Find & Replace?

ASTs understand the structure of code, making refactors safer and reducing unintended changes.


Why is planning important?

Large tasks are easier to solve when broken into smaller, ordered steps.

Planning also allows the AI to recover from intermediate failures.

Lessons Beyond Cursor

The same architecture powers many modern AI products.

Different products.

The same agent architecture.

Final Thoughts

Cursor isn't impressive because it has a smarter language model.

It's impressive because it combines several engineering ideas:

The magic isn't one giant prompt.

It's a loop of reasoning, acting, observing, and improving.

That's what turns an LLM into an AI agent capable of editing an entire project from a single sentence.