claude-code icon indicating copy to clipboard operation
claude-code copied to clipboard

[BUG] Claude Code + Visual Studio Code throwing error on diff

Open Rprp12 opened this issue 10 months ago • 13 comments

Environment

  • Platform (select one): Anthropic API
  • Claude CLI version: 1.0.0
  • Operating System: Windows 11
  • Terminal: Visual Studio Code + WSL

Bug Description

Everytime Claude Code wants to edit a file, it will throw the following error in the terminal - probably because of the visual studio code plugin / diff viewer. I would like to see the changes in visual studio code.

This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason: Error: String not found in file. Failed to apply edit. at gm (file:///usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js:1530:518) at S25 (file:///usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js:1953:8393) at J (file:///usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js:1953:7717) at file:///usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js:1953:7952 at f7 (file:///usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js:150:21374) at gZ (file:///usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js:150:40861) at file:///usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js:150:39057 at Iy1 (file:///usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js:144:155632) at Immediate.rj1 (file:///usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js:144:156050) at process.processImmediate (node:internal/timers:476:21)

Steps to Reproduce

  1. Will happen on every edit / diff.

Expected Behavior

Showing diff / line changes

Rprp12 avatar May 22 '25 18:05 Rprp12

A fix will be coming to address where this happens periodically, but it is unexpected that it happens for every edit. Can you confirm that this is indeed every edit?

blois avatar May 22 '25 19:05 blois

A fix will be coming to address where this happens periodically, but it is unexpected that it happens for every edit. Can you confirm that this is indeed every edit?

I just updated to Claude Code 1.0.2 and unfortunately the issue seems to be still here. I changed about 10 CSS files, no issues, but when asking to update the README.md I am still getting the error:

Opened changes in Visual Studio Code ⧉ │ │ Save file to continue… │ │ │ │ Do you want to make this edit to README.md? │ │ ❯ 1. Yes │ │ 2. Yes, and don't ask again this session (shift+tab) │ │ 3. No, and tell Claude what to do differently (esc) │ │ │ ╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯

This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason: Error: String not found in file. Failed to apply edit. at mm (file:///usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js:1530:518) at _25 (file:///usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js:1953:8755) at J (file:///usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js:1953:7717) at file:///usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js:1953:7952 at f7 (file:///usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js:150:21374) at gZ (file:///usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js:150:40861) at file:///usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js:150:39057 at Gy1 (file:///usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js:144:155632) at Immediate.oj1 [as _onImmediate] (file:///usr/local/lib/node_modules/@anthropic-ai/claude-code/cli.js:144:156050) at process.processImmediate (node:internal/timers:476:21)

Rprp12 avatar May 23 '25 09:05 Rprp12

I am also getting this bug a lot. I will get it for both sonnet and opus, same setup as OP.

I appear to get it when its trying to do a larger diff, if i ask it to make a small change it will be fine, I believe its when it tries to do a large diff is when it fails

GoldenE avatar May 23 '25 21:05 GoldenE

Actually, i've had it happen on files now that were also short, perhaps the issue happens more often in longer context windows? I'm not sure what the cause is but it seems to be getting more frequent and is blocking me from completing large changes as i dont want to blindly accept a change

GoldenE avatar May 23 '25 22:05 GoldenE

Same here, I'm getting this error message on every single edit when in VSCode (WSL2, Ubuntu 24.04). In Windows Terminal, Claude Code works just perfectly.

This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason: Error: String not found in file. Failed to apply edit. at mm (file:///home/xxxxxxx/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:1468:518) at N25 (file:///home/xxxxxxx/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:1837:9445) at J (file:///home/xxxxxxx/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:1837:8407) at file:///home/xxxxxxx/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:1837:8642 at b7 (file:///home/xxxxxxx/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:150:21374) at hZ (file:///home/xxxxxxx/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:150:40861) at file:///home/xxxxxxx/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:150:39057 at Qy1 (file:///home/xxxxxxx/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:144:155632) at Immediate.sj1 [as _onImmediate] (file:///home/xxxxxxx/.claude/local/node_modules/@anthropic-ai/claude-code/cli.js:144:156050) at process.processImmediate (node:internal/timers:485:21)

octanevz avatar May 24 '25 08:05 octanevz

Happening for me as well running clade code via wsl distro in vs code

This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason: Error: String not found in file. Failed to apply edit. at mm (file:///home/unix/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:1468:518) at N25 (file:///home/unix/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:1837:9445) at J (file:///home/unix/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:1837:8407) at file:///home/unix/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:1837:8642 at b7 (file:///home/unix/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:150:21374) at hZ (file:///home/unix/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:150:40861) at file:///home/unix/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:150:39057 at Qy1 (file:///home/unix/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:144:155632) at Immediate.sj1 [as _onImmediate] (file:///home/unix/.npm-global/lib/node_modules/@anthropic-ai/claude-code/cli.js:144:156050) at process.processImmediate (node:internal/timers:491:21)

tim-basic avatar May 26 '25 06:05 tim-basic

I'm going to cancel max subscription after this month ... vs code integration is so unstable on wsl

tim-basic avatar May 27 '25 08:05 tim-basic

As a status update, we're actively working to fix the WSL integration in the coming updates. Please stay tuned!

hackyon-anthropic avatar May 28 '25 02:05 hackyon-anthropic

@tim-basic what version of claude are you hitting this with (claude --version)

igorkofman avatar May 29 '25 17:05 igorkofman

@tim-basic what version of claude are you hitting this with (claude --version)

@igorkofman prints out 1.0.3 (Claude Code)

Thanks for jumping on this :)

tim-basic avatar May 30 '25 11:05 tim-basic

Please update to latest (claude update). This should be significantly less common now and we'll have a fix that full resolves it early next week. Thanks for the report.

igorkofman avatar May 30 '25 11:05 igorkofman

Thanks - I thought I did a fresh install 2 days ago. Just updated now. Will let you know if it continues.

tim-basic avatar May 30 '25 12:05 tim-basic

Was using claude code 1.0.6 last night for 4 hours and didn't see the bug appear. @igorkofman

tim-basic avatar May 31 '25 04:05 tim-basic

It's happening on every new file for me - using Node 22.16.0 with Claude Code 1.0.33 with WSL.

marty0678 avatar Jun 24 '25 03:06 marty0678

Not sure if this will work for you but I uninstalled the extension and installed from scratch and that resolved the issue for me. @marty0678

tim-basic avatar Jun 24 '25 04:06 tim-basic

Not sure if this will work for you but I uninstalled the extension and installed from scratch and that resolved the issue for me. @marty0678

Thanks @tim-basic but no luck. Before I posted I also set up a new nvm of the latest Node 22 LTS and installed it there and same issue.

Just tried logging out and re-installing it fresh again from that node instance and does the same thing once it tries to make a new file.

marty0678 avatar Jun 24 '25 13:06 marty0678

Interesting hmm @marty0678

I'm using the following with no issues:
Node version: v22.14.0 Claude Code VS Code extension version: 1.0.33 (server version: 1.0.31) WSL version: 2.5.9.0

tim-basic avatar Jun 25 '25 00:06 tim-basic

I woke up to this error with no updates in my systems through the night; been using latest Claude and Intellij.

oytuntez avatar Jul 22 '25 17:07 oytuntez

This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

github-actions[bot] avatar Jul 30 '25 14:07 github-actions[bot]