---
topic: python3-in-claude-code
title: Whether to replace the python3 that Claude Code uses in Bash (jq, uv, bun, Edit)
description: How often and for what Claude Code reaches for python3 in Bash calls, what the alternatives are and whether a switch pays off; with a measurement on the author's transcripts from November 2026.
aliases: [python, python3, python -c, heredoc, inline script, interpreter, jq, uv, uv run, PEP 723, bun, node, ruby, duckdb, sed, Edit, file editing, replacements, rewind, checkpoint, deny rules, Bash tool, one-liner, miniforge, conda]
domain: ai
created: 2026-11-19
license: CC BY 4.0, Jakub Dudek
address: https://stacks.jakubdudek.com/python3-in-claude-code
---

## Conclusions

It is not worth changing the interpreter. Python is the model's default choice, not a result of configuration: with no language named the agent writes Python [c4], and the surplus code comes from the agent's habits, not from the language [c5]. Anthropic itself treats code written by the agent as a way to a leaner context [c11].

A local measurement of 19 November 2026 (14 days of the author's transcripts [omitted]): python is in 23.2% of Bash calls, its errors are as frequent as in the rest of Bash (2.6%), and process start takes 21 ms against 5 ms for jq. Switching to jq, bun, uv or Ruby therefore gives milliseconds and a fraction of a percent of tokens. In other people's data there is less python but it takes more time [c6]; in the author's case it is the other way round, because these are short edits.

The only switch that changes anything is Edit instead of a script for replacements in existing files: in the measurement about 46% of inline code is such edits, and about 72% of all replacements go through them. A script bypasses diff review [c3], the deny rules for Read and Edit do not cover it [c2], and rewind will not restore a file changed only through Bash [c13]. 40% of the scripts have no assertion on the number of matches, so a replacement that misses ends silently. The recommendation of 19 November 2026: leave it; if the author wants diffs and rewind, one line in CLAUDE.md (Edit for existing files, a script only for a mechanical change across many files and always with an assertion).

How to enforce it, should that be needed: an instruction in CLAUDE.md alone works unreliably, a PreToolUse hook is more dependable [c8], but an account on HN says subagents reached for python anyway [c12]. In the author's sessions subagents make 65% of the calls with python.

uv: it manages environments for scripts by itself [c9], which would solve the dependence on conda base (python3 is miniforge with 443 packages), but a missing module occurred 16 times in 14,565 calls. It does not change permissions, because a broad rule on uv run covers any Python code [c10], and python is not among the listed read-only commands [c1].

For one's own CLIs, a command that returns the finished answer matters more than the scripting language: after such a redesign the model stopped assembling pipelines of jq and python [c7].

## Claims

### c1. Claude Code has a built-in, non-configurable set of read-only commands; the documentation lists among them ls, cat, grep, find and the read-only forms of git.
- source: https://code.claude.com/docs/en/permissions · T1
- quote: The set includes `ls`, `cat`, `echo`, `pwd`, `head`, `tail`, `grep`, `find`, `wc`, `which`, `diff`, `stat`, `du`, `cd`, and read-only forms of `git`. The set is not configurable
- checked: 2026-11-19
- valid until: 2026-12-19

### c2. The deny rules for Read and Edit do not cover a Python or Node script that opens files itself.
- source: https://code.claude.com/docs/en/permissions · T1
- quote: They also don’t apply to arbitrary subprocesses that read or write files indirectly, like a Python or Node script that opens files itself.
- checked: 2026-11-19
- valid until: 2026-12-19

### c3. Editing files through a python3 heredoc or sed -i in Bash bypasses the diff review that the Edit and Write tools give.
- source: https://github.com/anthropics/claude-code/issues/85511 · T4
- quote: In manual permission mode, file modifications made through the **Bash tool** (e.g. a `python3` heredoc or `sed -i` performing string replacements) bypass the per-edit diff review that the Edit/Write tools provide.
- checked: 2026-11-19
- valid until: 2026-12-19

### c4. With no instruction about the language the agent chooses Python: 10 of 10 runs in a practitioner's measurement.
- source: https://dev.to/svyatov/your-agent-writes-python-the-ruby-rule-cuts-that-by-a-third-476 · T2
- quote: All ten wrote Python.
- checked: 2026-11-19
- valid until: 2026-12-19

### c5. Most of the surplus code in Python is the agent's habits (docstring, main, guard), not the language itself.
- source: https://dev.to/svyatov/your-agent-writes-python-the-ruby-rule-cuts-that-by-a-third-476 · T2
- quote: Most of that 120% is not the language, it is what the agent wraps around it: the docstring, the `main()`, the `if __name__` guard, the line-ending bookkeeping.
- checked: 2026-11-19
- valid until: 2026-12-19

### c6. In the TraceLab traces python is 3.7% of the programs Claude runs, but more than half of the total execution time.
- source: https://syfi.cs.washington.edu/blog/2026-07-24-tracelab-bash/ · T2
- quote: For Claude, `python` accounts for only 3.7% of executable invocations but more than half of the total observed execution time.
- checked: 2026-11-19
- valid until: 2026-12-19

### c7. After flags that return the finished answer were added to the Infracost CLI, the model stopped assembling pipelines of jq, python, sort and wc and called one command.
- source: https://www.infracost.io/resources/blog/we-cut-claude-s-token-usage-79-by-redesigning-our-cli-for-agents · T2
- quote: the model stopped writing pipelines. Where it had been chaining `jq`, `python`, `sort`, and `wc`, it produced a single `infracost inspect` invocation that returned the answer directly.
- checked: 2026-11-19
- valid until: 2026-12-19

### c8. An instruction in CLAUDE.md alone is not enough to stop Claude reaching for bare python; a PreToolUse hook is effective.
- source: https://mcginniscommawill.com/posts/2026-04-27-claude-code-hooks-force-uv/ · T4
- quote: This is more reliable than CLAUDE.md instructions because it’s enforcement, not suggestion.
- checked: 2026-11-19
- valid until: 2026-12-19

### c9. uv manages virtual environments for the scripts it runs by itself.
- source: https://docs.astral.sh/uv/guides/scripts/ · T1
- quote: uv automatically manages virtual environments for you
- checked: 2026-11-19
- valid until: 2026-12-19

### c10. A broad permission rule Bash(uv run *) covers the execution of any Python code.
- source: https://pydevtools.com/handbook/how-to/how-to-configure-claude-code-to-use-uv/ · T3
- quote: A broad `Bash(uv run *)` rule includes arbitrary Python execution
- checked: 2026-11-19
- valid until: 2026-12-19

### c11. Anthropic describes code execution by the agent as a way to a leaner context, among other things by filtering data before it reaches the model.
- source: https://www.anthropic.com/engineering/code-execution-with-mcp · T2
- quote: Code execution with MCP enables agents to use context more efficiently by loading tools on demand, filtering data before it reaches the model, and executing complex logic in a single step.
- checked: 2026-11-19
- valid until: 2026-12-19

### c12. A hook that blocks python -c in the main session does not stop subagents (a user's account on HN).
- source: https://news.ycombinator.com/item?id=49557206 · T4
- quote: It can still invoke them in subagents and does this.
- checked: 2026-11-19
- valid until: 2026-12-19

### c13. Rewind does not restore a file that only Bash commands changed; that takes Git.
- source: https://code.claude.com/docs/en/checkpointing · T1
- quote: A file that only Bash commands changed isn’t tracked and stays as it is. To revert it, use version control, such as Git.
- checked: 2026-11-19
- valid until: 2026-12-19

## History
