{
 "topic": "python3-in-claude-code",
 "url": "https://stacks.jakubdudek.com/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",
 "last_checked": "2026-11-19",
 "claims": [
  {
   "ref": "python3-in-claude-code#c1",
   "url": "https://stacks.jakubdudek.com/python3-in-claude-code/c1",
   "card": "python3-in-claude-code",
   "id": "c1",
   "status": "valid",
   "claim": "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.",
   "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",
   "source_url": "https://code.claude.com/docs/en/permissions",
   "tier": "T1",
   "checked": "2026-11-19",
   "valid_until": "2026-12-19"
  },
  {
   "ref": "python3-in-claude-code#c2",
   "url": "https://stacks.jakubdudek.com/python3-in-claude-code/c2",
   "card": "python3-in-claude-code",
   "id": "c2",
   "status": "valid",
   "claim": "The deny rules for Read and Edit do not cover a Python or Node script that opens files itself.",
   "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.",
   "source_url": "https://code.claude.com/docs/en/permissions",
   "tier": "T1",
   "checked": "2026-11-19",
   "valid_until": "2026-12-19"
  },
  {
   "ref": "python3-in-claude-code#c3",
   "url": "https://stacks.jakubdudek.com/python3-in-claude-code/c3",
   "card": "python3-in-claude-code",
   "id": "c3",
   "status": "valid",
   "claim": "Editing files through a python3 heredoc or sed -i in Bash bypasses the diff review that the Edit and Write tools give.",
   "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.",
   "source_url": "https://github.com/anthropics/claude-code/issues/85511",
   "tier": "T4",
   "checked": "2026-11-19",
   "valid_until": "2026-12-19"
  },
  {
   "ref": "python3-in-claude-code#c4",
   "url": "https://stacks.jakubdudek.com/python3-in-claude-code/c4",
   "card": "python3-in-claude-code",
   "id": "c4",
   "status": "valid",
   "claim": "With no instruction about the language the agent chooses Python: 10 of 10 runs in a practitioner's measurement.",
   "quote": "All ten wrote Python.",
   "source_url": "https://dev.to/svyatov/your-agent-writes-python-the-ruby-rule-cuts-that-by-a-third-476",
   "tier": "T2",
   "checked": "2026-11-19",
   "valid_until": "2026-12-19"
  },
  {
   "ref": "python3-in-claude-code#c5",
   "url": "https://stacks.jakubdudek.com/python3-in-claude-code/c5",
   "card": "python3-in-claude-code",
   "id": "c5",
   "status": "valid",
   "claim": "Most of the surplus code in Python is the agent's habits (docstring, main, guard), not the language itself.",
   "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.",
   "source_url": "https://dev.to/svyatov/your-agent-writes-python-the-ruby-rule-cuts-that-by-a-third-476",
   "tier": "T2",
   "checked": "2026-11-19",
   "valid_until": "2026-12-19"
  },
  {
   "ref": "python3-in-claude-code#c6",
   "url": "https://stacks.jakubdudek.com/python3-in-claude-code/c6",
   "card": "python3-in-claude-code",
   "id": "c6",
   "status": "valid",
   "claim": "In the TraceLab traces python is 3.7% of the programs Claude runs, but more than half of the total execution time.",
   "quote": "For Claude, `python` accounts for only 3.7% of executable invocations but more than half of the total observed execution time.",
   "source_url": "https://syfi.cs.washington.edu/blog/2026-07-24-tracelab-bash/",
   "tier": "T2",
   "checked": "2026-11-19",
   "valid_until": "2026-12-19"
  },
  {
   "ref": "python3-in-claude-code#c7",
   "url": "https://stacks.jakubdudek.com/python3-in-claude-code/c7",
   "card": "python3-in-claude-code",
   "id": "c7",
   "status": "valid",
   "claim": "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.",
   "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.",
   "source_url": "https://www.infracost.io/resources/blog/we-cut-claude-s-token-usage-79-by-redesigning-our-cli-for-agents",
   "tier": "T2",
   "checked": "2026-11-19",
   "valid_until": "2026-12-19"
  },
  {
   "ref": "python3-in-claude-code#c8",
   "url": "https://stacks.jakubdudek.com/python3-in-claude-code/c8",
   "card": "python3-in-claude-code",
   "id": "c8",
   "status": "valid",
   "claim": "An instruction in CLAUDE.md alone is not enough to stop Claude reaching for bare python; a PreToolUse hook is effective.",
   "quote": "This is more reliable than CLAUDE.md instructions because it’s enforcement, not suggestion.",
   "source_url": "https://mcginniscommawill.com/posts/2026-04-27-claude-code-hooks-force-uv/",
   "tier": "T4",
   "checked": "2026-11-19",
   "valid_until": "2026-12-19"
  },
  {
   "ref": "python3-in-claude-code#c9",
   "url": "https://stacks.jakubdudek.com/python3-in-claude-code/c9",
   "card": "python3-in-claude-code",
   "id": "c9",
   "status": "valid",
   "claim": "uv manages virtual environments for the scripts it runs by itself.",
   "quote": "uv automatically manages virtual environments for you",
   "source_url": "https://docs.astral.sh/uv/guides/scripts/",
   "tier": "T1",
   "checked": "2026-11-19",
   "valid_until": "2026-12-19"
  },
  {
   "ref": "python3-in-claude-code#c10",
   "url": "https://stacks.jakubdudek.com/python3-in-claude-code/c10",
   "card": "python3-in-claude-code",
   "id": "c10",
   "status": "valid",
   "claim": "A broad permission rule Bash(uv run *) covers the execution of any Python code.",
   "quote": "A broad `Bash(uv run *)` rule includes arbitrary Python execution",
   "source_url": "https://pydevtools.com/handbook/how-to/how-to-configure-claude-code-to-use-uv/",
   "tier": "T3",
   "checked": "2026-11-19",
   "valid_until": "2026-12-19"
  },
  {
   "ref": "python3-in-claude-code#c11",
   "url": "https://stacks.jakubdudek.com/python3-in-claude-code/c11",
   "card": "python3-in-claude-code",
   "id": "c11",
   "status": "valid",
   "claim": "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.",
   "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.",
   "source_url": "https://www.anthropic.com/engineering/code-execution-with-mcp",
   "tier": "T2",
   "checked": "2026-11-19",
   "valid_until": "2026-12-19"
  },
  {
   "ref": "python3-in-claude-code#c12",
   "url": "https://stacks.jakubdudek.com/python3-in-claude-code/c12",
   "card": "python3-in-claude-code",
   "id": "c12",
   "status": "valid",
   "claim": "A hook that blocks python -c in the main session does not stop subagents (a user's account on HN).",
   "quote": "It can still invoke them in subagents and does this.",
   "source_url": "https://news.ycombinator.com/item?id=49557206",
   "tier": "T4",
   "checked": "2026-11-19",
   "valid_until": "2026-12-19"
  },
  {
   "ref": "python3-in-claude-code#c13",
   "url": "https://stacks.jakubdudek.com/python3-in-claude-code/c13",
   "card": "python3-in-claude-code",
   "id": "c13",
   "status": "valid",
   "claim": "Rewind does not restore a file that only Bash commands changed; that takes Git.",
   "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.",
   "source_url": "https://code.claude.com/docs/en/checkpointing",
   "tier": "T1",
   "checked": "2026-11-19",
   "valid_until": "2026-12-19"
  }
 ],
 "as_of": "2026-12-04",
 "note": "A claim says what its source said on the day it was checked. \"valid_until\" is the date by which it should be checked again, not a promise that it is true today.",
 "license": "CC BY 4.0",
 "author": "Jakub Dudek",
 "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].\n\nA 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.\n\nThe 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).\n\nHow 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.\n\nuv: 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].\n\nFor 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].",
 "history": []
}
