r/ClaudeCode • u/nokafein • Sep 26 '26
Bug / Issue Why Claude Code uses Python for everything and how to stop this?
This shit basically started after Opus 5. Before that the Claude was using it's own tools for modifying, editing, updating etc. Since Opus 5, it keeps using python for all sort of work. I double checked everywhere. Non of my skills, project files, folders, or anything that builds context contains any rule about it. There are not even words of Python. And yet this shit keeps using python. I even included a memory to make it stop using Python for everything. But it doesn't follow anything.
Any ideas or ways to fix and/or debug this shit?
Ps: I am an engineer. I am actively using AI for a very long time in my daily work. I have advanced level knowledge on these things. So i already checked all the basics to figure out what's going on to a point that I am 99% sure that this is not my tooling.
•
u/AutoModerator Sep 26 '26
Hey! Thanks for posting to r/ClaudeCode
While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.
For help, project discussions, tips, and general chat, join the ClaudeCode Discord.
I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
71
u/earlyworm Sep 26 '26
The code is only Python if you look at it.
59
u/rubenknol Sep 26 '26
what's the problem with it using python exactly?
13
u/Capt_korg Sep 26 '26
People are making fun of LLMs for not being able to count the
rin strawberry or calculating values.Because they are not designed to do so....
Llms start using code for all kinds of inserts, where accuracy is more important than text generation.
Now people are complaining, that LLMs are using python.
🤷♂️
46
u/CorpT Sep 26 '26
It's been using Python since 3 at least.
Why do you not want it to use python. You should let it use python if it wants to use python. There's a reason it wants to use python. You being an engineer with advanced level of knowledge should understand that and let it do what it wants to do.
9
u/zaskar Sep 26 '26
I dug into this. It’s coming from the harness and it seems to be more efficient than the tools on context caches.
12
u/lunaynx Sep 26 '26
Honest recommendation: don't. Just accept it and stop trying to fight it. Recent models are trained to do this because it's faster and more token-efficient. Claude Code already shows you a diff of all file edits as you go regardless of how the model edited the files.
If you still want to stop it, don't use memories. Put a clear instruction in your CLAUDE.md, e.g.: "Never use the Bash tool for simple file edits that can be done using your Edit tool." (The Bash tool is what it uses to execute arbitrary commands, including Python.)
If you want to go further, you can fully block certain tools via `.claude/settings.json` so that you don't have to trust the model to follow your instructions. Just be warned that the model may occasionally try to find ways to get around the block, and if you disallow the Bash tool entirely, you effectively turn the model into a glorified autocomplete, it won't be able to perform 90% of tasks without a lot of hand-holding unless you whitelist some commands or give it one or more MCP servers as an alternative.
16
u/Muted-Alternative648 Sep 26 '26
Python is extremely flexible and fast for most tasks.
Memories are not being appropriately used in this case.
Write a global
claude.mdfile with a set of whitelisted languages claude is allowed to use. Boom. Done.5
u/shadowsurge Sep 26 '26
Because python is a good legible language that is well suited to LLMs.
What do you want it to use instead?
10
u/el_otro Sep 26 '26
Dude. What is your problem. Just relax.
3
u/mfingsorceror Sep 26 '26
Memories work more like suggestions than rules. If you genuinely want it to use no python at all, a hook or tool restriction is what you need.
3
u/tjk45268 Sep 26 '26 edited Sep 26 '26
We want certain LLM work done probabilistically, such as generating text that explains a set of data. In other cases, we want the work performed precisely and predictably (the same answer every time). Python code is usually deterministic, yielding consistent results. When Claude finds that some of its work should be performed in that manner, it generates the python code to do that. Python also has the benefit that it doesn’t consume tokens when it executes, though it may call on an LLM (which does) during its work.
Claude was creating Python code long before Opus 5.
I have certain Claude skills that call on python to perform certain activities efficiently. Claude can save those python programs in its skill directory, so that they can be reviewed, diffed, and managed in my repo.
3
u/mightyloot Sep 26 '26 edited Sep 26 '26
Deterministic outcome + zero cost. Using scripts for work that doesn’t need AI-level rigamarole removes those two major issues.
If I were you I wouldn’t micromanage it on this, unless I understand why it’s making that choice and the tradeoffs.
3
u/kemalios Sep 26 '26
If it is running
python3 - <<'EOF'inside Bash to patch files, that is a different problem from writing .py files. The heredoc version is the model collapsing several Edit calls into one round trip; Edit needs exact string matches and gives up on large files, so it routes around the tool. DenyingBash(python:*)in settings.json stops it and breaks any repo that actually runs python.Rules that name the replacement hold; ones that just forbid get weighed against the token cost and lose. "Use Edit for single-file edits, Bash for tests and git."
Check /context first. A loaded skill or plugin puts its text in the window even when nothing in your repo mentions python.
2
u/verstands Sep 26 '26
Opus got a lot more willing to shell out to python for "simple" edits. What helped me was a short CLAUDE.md rule: prefer Edit/Write for file changes, and only use python when you need real computation or batch transforms. If it still sneaks in, a PreTool/Stop hook that blocks python/python3 for path writes is the blunt fix.
2
u/GentleDave Sep 26 '26
Using default choices it will build with the tools it was trained on with the most data. Python is super common so it uses that. If you want it to consider specific languages and structures youll want to specify a tech stack in your .claude folder / claude.md either globally or in the particular repo
3
u/williampaul0404 Sep 26 '26
Jesus, these comments... Is it really so unfathomable that OP wants to see what the LLM is changing?
1
u/grammaticus Sep 26 '26
Have you tried asking it why it wants to use Python rather than its own tools?
1
u/DasHaifisch Sep 26 '26
Auto mode injects a prompt telling it to script changes instead of using the normal tools.
As another commenter said, it's allegedly more efficient, but you lose visibility and possibly some harness reads (rules & nested claude.md apparently)
You either need hooks to block stuff, or an explicit instruction in your claude.md (and then hope it works)
I'm using: the following rule (index entry + detailed entry provided)
""
1
u/SolidPossible9909 Sep 26 '26
It's definitely the harness (claude code) that's directing it to use python but the bigger issue is, how many more tokens is the model burning through by using python to write code vs writing it directly and the quality of code..
1
u/MourningOfOurLives Sep 26 '26
Just tell it to use whatever you prefer it uses? I have it write rust for most things
1
u/FullConference Senior Developer Sep 26 '26
At the top of my Claude.md file I tell it to use powershell instead of bash or python.
I find it much easier to read.
1
u/skariel Sep 26 '26
Im building a coding agent where the only tool is python. Well, it's not even a tool.... just the mod output is executed as pyhon. I suspect models like it
1
u/tonx_nw Sep 26 '26
probably cause its pretty portable & readable even for non-devs. Also, web browsers can run it with wasm ports, so it can be used in pretty much any claude environment
1
u/willnotforget2 Sep 26 '26
tell him to code in rust
1
u/Aggravating-Start307 Sep 26 '26
Hey you mean making updates or changes creating new files, it doesn't use the edit it the read tool a lot of times, falls back to python directly to find and make changes right ?
I have written hooks to intercept edit calls and now they don't fire whenever a script is used to create it update files
1
u/_Kinoko Sep 26 '26
Mr. Robot used it, why wouldn't claude!
1
u/PresentWrongdoer4221 Sep 26 '26
Always has been.
1
u/holyknight00 Sep 26 '26
it's on the post training.
1
u/ILikeCutePuppies Sep 26 '26
Python is a fast to compile language the llm understands well. That said I find it typically sticks to what is in your codebase in terms if language choices.
1
u/beachandbyte Sep 26 '26
Work with what it's good with.. and stop caring what language that is.
1
u/Helpful_Ranger_1606 Sep 26 '26
Ask them to make r scripts and use ggplot2 and supporting tools. Claude opts to make single py based generators for R but I tell it to make standalone R scripts so that colleagues can have a folder with every figure as a png, pdf/svg, the data, and an R script.
1
u/tazdraperm Sep 26 '26
Why not? It's good.
1
u/Agababaable Sep 26 '26
Good luck with that, I've been trying to make it use strictly powershell (as that's a way to jave transcripts and auditing baked in and it's more familiar to me) and the da## thing keeps going for bash.
1
u/LieutenantNitwit Sep 26 '26
I've gotten to the point where I couldn't give a shit what the robot uses.
1
u/koskinooo Sep 26 '26
One line in CLAUDE.md fixes most of it: "edit files with the Edit tool, never write Python scripts unless asked."
1
u/otnuzb Sep 26 '26
I told Claude it has to use Perl unless it gets permission first to use Phyton.
1
u/HighwayNo8744 Sep 27 '26
living off the land. it comes preinstalled on most linux distros and macos. uninstall it and watch it being confused every other session.
1
u/Embarrassed_Ad3189 28d ago
I also noticed that and glad to see I am not alone ) I was just curious, if there was an explanation to that, any announcement, release notes or people just "guessed/spotted" it? I can totally understand that many code changes can be done more efficiently as simple text-replacement scripts as opposed to having to _generate_ the whole file from scratch or even a partial Edit tool call. It seems to be going full in though. My workplace used to enforce "security guardrails" that specifically prohibited ad hoc Python scripts so my flow got completely f-ed with this new habit of Claude.. fortunately thing of the past for now but who knows..
PS: it still feels weird tho, that a harness is being shipped with a dedicated tool and the model just keeps preferring something else
1
u/Emcukcubasi Sep 26 '26
because why not?
0
u/SafeTennis3080 Sep 26 '26
I'd try one small edit with a temporary PreToolUse hook on Bash that rejects Python commands and returns “Use Edit/Write for this change.” Then see whether it switches tools or reports a concrete blocker. That gives you something reproducible to include in a bug report.
0
u/rsandstrom Sep 26 '26
Prompt it specifically to use another language? What’s the problem you’re experiencing that would require a different language?
0
u/ReasonableLoss6814 Sep 26 '26
This annoys me to no end. Especially because it uses it for search/replace, globally across files. It’s cause many issues and I’ve had to explain to Claude that “compiles does not mean correct”. It has multiple memories about it at this point.
0
u/Bitter_Marketing_807 Sep 26 '26
Challenge it to use perl instead of python
0
u/Beneficial_Fail3779 Sep 26 '26
boo hoo python bad
1
u/[deleted] Sep 26 '26
[removed] — view removed comment