Skip to content
Happy Programming Guide
Start learning
AI for Programmers

Fixing Cursor’s “Error Calling Tool edit_file” and “write”

Cursor's agent fails partway through an edit with a tool error. The causes: a file it cannot see or write, a stale index, a change too large for one call, and a session that needs restarting.

A ladybird crawling along a plant stem

When Cursor’s agent reports error calling tool edit_file or error calling tool write, the model decided what to change and the editor failed to carry it out. That points at the editor side, not the model: the file is outside what Cursor can access, the path is wrong or ignored, the edit was too large or conflicted with the file’s current state, or the agent session itself has gone stale. Each has a quick check, and the ordering below goes from most to least common.

What is happening#

In agent mode, the model produces structured requests: read this file, edit that one, run this command. Cursor executes them. A tool error means one of those requests failed in Cursor, and the message you see is the model relaying it. The underlying reason is usually visible if you expand the failed step in the chat, or in the output panel; read it before trying anything.

Cause 1: the file is out of reach#

  • Outside the workspace. The agent can only edit files under the folder you opened. A path it guessed from a symlink, a parent folder or an absolute path elsewhere fails. Open the correct folder, or the parent that contains everything.
  • Ignored. Files matched by .cursorignore, and by default anything in .gitignore, are invisible to indexing and often to tools. A generated file or something in a build folder is a common case. Remove the pattern, or add the path to .cursorindexingignore instead if you only want it out of the index.
  • Read-only. A file checked out read-only, owned by another user, or on a mount without write permission. Check the file’s permissions; try saving it manually.
  • Locked or dirty. A file with unsaved changes in another editor window, or held by a process on Windows. Save or close it and retry.

Cause 2: stale state#

Long agent sessions, an update applied while Cursor was open, or a codebase index that has fallen behind can all leave the agent working from a picture of the file that no longer matches disk, and the edit fails to apply.

  1. Start a new chat. The old one’s context is the problem.
  2. Developer: Reload Window from the command palette.
  3. Resync the index: Cursor settings, Indexing, then delete and rebuild it. Large repositories take a few minutes.
  4. If Cursor updated recently, quit fully and relaunch.

Cause 3: the edit is too large or ambiguous#

The edit tool applies a change by matching the file’s current content. A very large rewrite, an edit to a file that changed since the agent read it, or a target region that appears several times can fail to apply. The symptom is repeated failures on the same file.

  • Ask for smaller steps: “change only the save function” rather than “refactor this file”.
  • Tell it to re-read the file first: “read the current version of app.py, then make the change”.
  • For a rewrite, ask it to create a new file and then replace the old one, which uses the write tool with a clean target.

Cause 4: the write tool and new files#

write failures usually mean the directory does not exist, the path contains characters the platform rejects, or the location is ignored or outside the workspace. Ask the agent to create the folder first, or create it yourself. On Windows, a path that is too long or contains a colon fails at the file-system level.

Cause 5: network and account#

Occasionally the tool error is a symptom of the request to the model failing mid-stream: a dropped connection, a rate limit, or a plan limit reached. The output panel shows a network or quota message in that case. Retry once; if it persists, check Cursor’s status page and your usage in settings.

Recovering the work#

Cursor keeps a checkpoint before each agent step; the restore control in the chat rolls the workspace back to before the failed change if it left things half-applied. Git is the more reliable net: commit before starting an agent task, and git diff after any failure to see exactly what landed.

Terminal
git status
git diff
git checkout -- path/to/file    # discard a half-applied edit to one file

Questions people ask#

Is the model broken or is Cursor?

A tool error is on the editor side. The model can still be wrong about what to edit, but this error means the edit could not be applied, whatever its merits.

Why does it work in chat mode and fail in agent mode?

Chat shows you a diff to apply yourself; agent mode applies it through the tools. The tools are the part that can fail on permissions and paths.

Does this happen in other assistants?

Every agentic tool that edits files has an equivalent failure mode, with the same causes: reach, permissions, stale state, edit size.

Can I see a log?

The output panel has a Cursor channel, and Help, Toggle Developer Tools shows the console with more detail.

Where to go next#

Cursor for beginners: a first-week guideRead next

Keep reading

Keep going — pick your next guide

The fastest way to improve is to read one guide, then build the thing it describes. Start with the basics, or jump straight to a project.

Ask a question or share what worked

Your email address will not be published. Required fields are marked *