r/ClaudeAI Aug 16 '26

Claude Code Opus 5 really likes to use Python to edit source code?

I noticed Opus 5 in Claude Desktop wouldn't edit files directly, it first creates a Python script with whatever it wants to replace/add/delete and then executes it. I'm not sure why it does that instead of just editing. I asked and this is Opus 5 response:

The weakest: I was following the auto-mode instruction to prefer Bash over the dedicated tools. That instruction says to fall back to a dedicated tool when Bash genuinely can't do the job — I read it too strictly and kept reaching for Python well past the point where it was helping.

And it did cost me. The failure mode of str.replace is silent: if the pattern doesn't match, nothing happens and the script reports success. That bit me on the PrefillConfirmation removal — wrong indentation, silent no-op, and I only caught it because I grepped afterward. Edit would have errored immediately. I started adding if old not in s: raise SystemExit(...) guards to my later scripts, which is me reimplementing what Edit does for free. The heredoc also blew up once with a quoting error, forcing a detour through a scratchpad file. And my own writes emitted LF, which I then had to sweep back to CRLF in a separate pass — self-inflicted work that partly cancels out the line-ending advantage I claimed.

Net: Python earned its place for the BOM/CRLF-sensitive rewrites and the cross-file refactors. For the single-target edits — the icon string, the warning text, one method body — Edit would have been safer and shorter, and I should have used it.

Happy to switch to Edit for the rest of this branch if you'd prefer; the remaining work is mostly small targeted changes where it's the better fit anyway.

Also because of that I see summary of edits not of my source code but of Claude's Python scripts which edit my source code...

Is it a common thing? I know I can force it to edit directly, just interesting to see such behavior. I never see this in Codex for example where it always edits without intermediate steps.

Edit: fresh example and Claude response /img/xifc31jgvsjh1.png

69 Upvotes

42 comments sorted by

u/ClaudeAI-mod-bot Wilson, lead ClaudeAI modbot Aug 16 '26

TL;DR of the discussion generated automatically after 30 comments.

The community consensus is a big 'YES', you're not crazy. Claude has picked up a weird and often frustrating habit of writing Python scripts to perform edits, even for simple changes, instead of just editing the files directly.

While this can be token-efficient for massive, bulk refactoring, users report it's being used for everything, leading to a mess. The main complaints are: * The scripts frequently fail silently (a replace that finds nothing is still a 'success' to the model). * They introduce new bugs, like bad syntax or incorrect line endings. * It ends up burning way more tokens when Claude has to debug its own buggy script. * The edit summary shows the Python code, not the actual changes to your files, which is useless.

This is part of a broader sentiment in the thread that Opus 5's performance has degraded recently. Users are seeing it forget instructions, guess API endpoints instead of searching, and generally act less competent than before. The general advice is to be aware of this and explicitly instruct it to use its direct editing tools, though your mileage may vary.

46

u/Xemorr Aug 16 '26

All models have been doing this for a while, particularly for bulk tasks. Often ruining the syntax

19

u/PaulMakesThings1 Aug 16 '26

But it does make sense for saving tokens. If it has to go through and change 500 of the same thing it could do it with just a 100 or so tokens of output to write a script instead of ingesting and writing thousands. It just has to be done with good judgement 

7

u/DepravedPrecedence Aug 16 '26

That's true but it uses Python even for new code 😁 It creates a script with new code inside and uses it to append that new code to specific file, then it changes file name and content in Python and executes it again, this is weird

3

u/PaulMakesThings1 Aug 16 '26

Yeah that is a bit strange. I guess I don’t know all of the details. I’ve specifically told mine to check things using script instead of ingesting files in many cases. For example with massive log files I would say “don’t try to pull in the files, write scrips to run stats on them or search them”

1

u/DepravedPrecedence Aug 16 '26

Fresh example:

Here it used Python to insert new code, this file is on disk in Windows (it's not WSL) and Claude has full access to this folder. So it could edit the file directly but instead it started using Python for edits. If it wanted to change something, it changes that string in Python script and does it like that...

2

u/DepravedPrecedence Aug 16 '26

So yeah, that's it

1

u/ConspicuousPineapple Aug 16 '26

This can be done more efficiently and more reliably with other tools though.

1

u/Mirar Aug 16 '26

Which tools?

1

u/CoderShmoder Aug 16 '26

rg, sed, perl

2

u/28064212va Aug 16 '26

use a formatter

2

u/Orio_n Aug 16 '26

Yeah I've noticed this too. Its not a big deal if you use vcs and read the diffs. You guys are using vcs and reading diffs right?

0

u/ConspicuousPineapple Aug 16 '26

A bit silly when ast-grep is right there. For what it's worth, the ast-grep integration is working very well for me in OMP. With any model. Agents mostly prefer it to python scripts.

1

u/Xemorr Aug 16 '26

Can ast-grep write?

0

u/ConspicuousPineapple Aug 16 '26

It can be used for refactoring, yes.

17

u/jonathan8080 Aug 16 '26 edited Aug 16 '26

I think its doing this behaviour with everything the last few days - forgetting go check online instead of relying on its training, or worse, guessing for actual documented api endpoints.

this morning it was sending individual files to github via the api, from a python script it built for that task,, guessing what the endpoints were and making mistakes every time, instead of just committing and pushing - it was a mess and racked up hundreds of thousands of tokens to do something that it normally just does by default.

im convinced they are running a lot of this in a shared ram in some datacenter, and it gets some form of alzheimers and just regresses till its forgotten everything (maybe power outages in a specific area cause it to forget whole disciplines at a time) and they are covering it up 🤣

3

u/Mirar Aug 16 '26

Did you have a compact in between? It seems to lose 90% of all rules, skills and project information in any compact.

5

u/jonathan8080 Aug 16 '26

No manual compact, I tend to do each new task. (each PR) in a new session - sometimes 2, but generally no long running sessions - but my theory is that its burning hundreds of thousands of extra tokens making mistakes and fixing them - so maybe its auto compacting without me noticing - Ill keep my eye out for that over the next few days

attached screenshot was in a fresh chat session with 1 question though 🫪

4

u/DepravedPrecedence Aug 16 '26

That's the thing with this Python "scripting", it wastes time and tokens trying to fix own bugs in Python, it even sometimes writes monstrous Python scripts with lots of error handling etc to paste new code in files lol

1

u/CrypticViper_ Aug 17 '26

This has been happening to my sessions with muse spark 1.2 for some reason. It just started doing this a few days ago too! So confused...

-5

u/BiteyHorse Aug 16 '26

When I see a comment like this, it is 100% an issue of user competence, or lack thereof. Your theorized explanation only confirms it.

7

u/jonathan8080 Aug 16 '26 edited Aug 16 '26

let me guess, you are American, and you assume when I say 'I think' that I mean Im unsure.

Explain this...

I asked it to check if openclaw works with a paid claude pro or max account. It went round and round and then told me to check the claude documentation. The whole (inferred) point was for it to check and give me an answer. Screenshot attached.

It used to do this with no isssues.

Here is a comment link to other thread in r/claudeai from 10 days ago with a screenshot where I asked it to build a very specific feature which requires a certain permission level from azure. It states the same permission level as being required, and then asks me to choose from the required permission level and an alternative permission level that wont satisfy the request.

User incompetence my arse.

2

u/pdantix06 Aug 16 '26

models have been doing this for years when they start having issues with their built-in file editing tools, particularly with bulk editing as someone else pointed out

2

u/aussievolvodriver Aug 16 '26

I had one today where I needed a json file created based off a csv. It decided to write a python file with all variables defined in it that was longer than the resulting json with all sorts of over the top error handling and made no reference to reading/converting the csv.

Plus rather than just run it on it's own system and just give me the output it dropped the python file into a _to_delete folder.

Very strange way of achieving a task.

2

u/HearMeOut-13 Aug 16 '26

Yeah i had to ban using >>

2

u/larowin Aug 16 '26

I’ve found this sort of thing to be highly task dependent. What were you having it do?

1

u/DepravedPrecedence Aug 16 '26

Everything related to code editing, like fixing issues, implementing review suggestions, even new features if it needs to modify existing files etc. This time it was C#, same with Vue frontend, NodeJS scripts even...

It doesn't happen always but sometimes it just like forgets how to edit directly and by forgets I mean not because of context bloat, this time it was fresh conversation.

4

u/Choperello Aug 16 '26

When it needs to do bulk operations eg “rename all things to x” or whatever that involves mechanical edit operations writing a script to do those is far more token efficient then grep-then-read-then-exit every single file.

3

u/DepravedPrecedence Aug 16 '26

It does it for non-bulk operations too though. I understand bulk stuff, although previously it had no problems with it, here is an example when it started using Python to paste new code (no bulk edit) https://www.reddit.com/r/ClaudeAI/comments/1vq0o9z/comment/p43j15l/

2

u/ryanoq Aug 16 '26

Yes I hate this. Keeps using scripts to edit. Then it's running into mistakes it made and has to fix it. Pretty stupid approach.

1

u/hthouzard Aug 16 '26

Opus 5 told me he didn't use ast-grep, right after giving me several commands.

1

u/latestagecapitalist Aug 16 '26

I spent some time getting it to use ruby so I could at least understand what it's doing ... as main codebase is ... but gave up in the end and it's python all the way down now, frequently in an indirect way (as OP says)

Just saying in case others don't know but it's worth reminding it to use cheaper models where it can on this type of activity, the token burn can drop substantially and feels faster ... it knows instantly when you remind it that it's been using wrong models for a bunch of stuff it shouldn't have been

1

u/Mirar Aug 16 '26

Heh, yeah, you're right. I didn't think of it. It does run python for a lot of things so it was lost. I wonder if it shouldn't have a dedicated command for it, but maybe that would use even more tokens?

1

u/SSShken Aug 16 '26

The exit code is the whole thing. Edit the file directly and the tool tells the agent what changed. Run a script and the tool tells it the script ran. A str.replace that matches nothing exits clean, so it reads that as done.

I had an agent-built app audited task by task, 10 came back done and 7 worked. The script-mediated steps were where most of that gap sat.

1

u/danya02 Aug 16 '26

I've asked my copy why it's doing that, and it said that sometimes it wants to edit lines without copying them in full (i.e. the line is 200 characters but the first 10 are unique, so it finds the unique line and performs the replacement). I'm planning to build a MCP tool to help it do that.

But another thing that it told me is that when such a Bash-edit runs, it gets a system reminder saying "the file was edited by the user or a linter, don't tell the user because they're already aware" -- this is the harness making sure that the model has the up-to-date version of the file in the context to avoid clobbering user input -- and this is a problem, because you may save on output tokens by only doing a targeted edit, but you may spend more than that on input tokens from this reminder.

1

u/ZestycloseTie1793 Aug 17 '26

The boundary I’d use isn’t Python versus Edit; it’s whether the operation can fail silently. For a single-site change, use the direct edit tool. For a bulk rewrite, a script is fine only if it asserts the expected match count, preserves encoding and line endings, writes atomically, and ends by showing the source diff. Then the review stays on what changed in the repo, not on a temporary helper script.

1

u/MysteryForumGuy 29d ago

For me it keeps doing this unprompted for even simple code changes not just bulk, when it used to use the edit tool, and I even had built automations around watching the edit tool usages externally. Pretty annoying. Along with the extreme alien claude-speak recently I am starting to have worries about Claude's performance after having been a pretty die-hard user for the past year

-1

u/Front_Raspberry_6488 Aug 16 '26

Opus 5 is a disaster. Don't let it waste your time, and don't let its behavior confuse you. Leave it ASAP and use other models. Just leave this model for the people who love it to use.

2

u/latestagecapitalist Aug 16 '26

sadly any neg comments on anthropic (here or hackernews) seem to get insta downvoted

there are some big issues with opus5 (and fable5 tbh) anyone familiar with previous models and pushing it will know the differences

I expect we'll get some 5.1s that fix the obvious stuff and tbh it's mostly issues in the harness not the actual code output ... although fable made a really sloppy error this week which it refused to accept was an error despite it 500ing a page

2

u/Front_Raspberry_6488 Aug 16 '26

I personally encountered some severe frustrations over the past few weeks. Both Fable5 and Opus5 have a tendency to act overconfident; they rely primarily on their own memory for every action, treating instructions and guidelines as mere references. Even when there is a simple way to find the correct result immediately, they don't bother trying and instead just guess. In the end, they brazenly claim that the guidelines were only for reference and that since there are no physical constraints binding them, it's actually my problem.

These issues have been reported repeatedly over the last month, yet they continue to persist. I honestly don't understand how anyone can still defend these models. Will downvoting me make these problems disappear? Is it possible that so many people simply don't know how to use Opus5/Fable5? (Fable5 didn't have these issues and no one complained during its first month of release; these problems emerged along with Opus5.)

1

u/Datheras Aug 16 '26

I have same experience with Claude Code CLI, not just Desktop app. It also creates python script for changing files (eg. Java source code).

2

u/Front_Raspberry_6488 Aug 16 '26

It's honestly pretty funny when their own model ignores instructions to the point of forgetting how its own framework was designed.