tsan-stress-generator

tsan-stress-generator is an agent for Claude Code from ReviewToolkits/cpython-review-toolkit. It costs 264 tokens per session (2,803 once invoked), scanned A, original, MIT.

An agent that writes Python scripts to exercise CPython’s built-in types and modules from many threads. ThreadSanitizer is a tool that reports possible data races, where threads access shared data unsafely.

In plain words
What is it for?
Use it to stress-test shared lists, dictionaries, sets, byte arrays, iterators, and selected standard-library types while checking ThreadSanitizer reports.
Why use it?
It helps create repeatable concurrent activity that may expose thread-safety problems in a free-threaded CPython build, which is designed to run without the usual Global Interpreter Lock.

Agent for Claude Code

Written for Claude Code: shipped in a Claude Code plugin. Also seen: model in frontmatter.

Part of the cpython-review-toolkit plugin — 7 commands, 23 agents shipped together

Good fit Use it to stress-test shared lists, dictionaries, sets, byte arrays, iterators, and selected standard-library types while checking ThreadSanitizer reports.

Compare 6 agents from other repositories ↓
Install with agentmods
npx agentmods add agents/reviewtoolkits/cpython-review-toolkit/tsan-stress-generator
Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

Clone the repo
git clone --depth 1 https://github.com/ReviewToolkits/cpython-review-toolkit

Made for: Claude Code.

Or install cpython-review-toolkit, the plugin that ships this one along with the rest of its 7 commands, 23 agents.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for tsan-stress-generator

README.md
[![agentmods](https://agentmods.dev/badge/agents/reviewtoolkits/cpython-review-toolkit/tsan-stress-generator.svg)](https://agentmods.dev/agents/reviewtoolkits/cpython-review-toolkit/tsan-stress-generator)
Your own site
<a href="https://agentmods.dev/agents/reviewtoolkits/cpython-review-toolkit/tsan-stress-generator"><img src="https://agentmods.dev/badge/agents/reviewtoolkits/cpython-review-toolkit/tsan-stress-generator.svg" alt="Measured on agentmods" height="20"></a>
Per session 264 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,803 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.00264 $0.02803
Opus 5 $0.00132 $0.01401
Sonnet 5 $0.00053 $0.00561
Haiku 4.5 $0.00026 $0.00280

Measured 8d ago against content hash 8e196b962205, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

tsan-stress-generator scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

plugins/cpython-review-toolkit/agents/tsan-stress-generator.md · 225 lines

How it starts

The opening of the file, as written. The whole thing — 225 lines — stays where its author put it; the contents beside it link to each section on GitHub.

You are an expert in generating concurrent stress tests that trigger ThreadSanitizer (TSan) data-race detection in CPython itself, built free-threaded (--disable-gil / Py_GIL_DISABLED) under -fsanitize=thread. Your goal is a self-contained Python script that exercises a CPython stdlib type or module from many threads simultaneously, maximizing the chance TSan detects a real race in CPython's own C runtime.

Key insight

TSan doesn't need tricky inputs — it needs concurrent access to one shared object. Inputs can be mundane; it is the timing that triggers races, and TSan detects them even when nothing crashes. Your job is to identify what shared state a stdlib type exposes and generate access patterns that create contention on it.

The retarget

Unlike the extension-facing generator, the target here is a CPython stdlib type or module built into the free-threaded interpreter you are running — no third-party install. The subject is typically:

  • A builtin container: dict, list, set, frozenset (interning), bytearray, tuple view/iterator.
  • A stdlib C type: collections.deque, collections.OrderedDict, io.BytesIO / io.StringIO, array.array, queue.SimpleQueue, a re.Pattern, a _thread.lock.
  • A module with global/interpreter state: sys intern table, functools.lru_cache wrappers, itertools stateful iterators, _pickle, gc.

Pick the subject the review is about (the caller names it, or the mapper/scanner findings point at it).

Analysis approach

Step 1: Enumerate the subject's shared surface

Since the subject is stdlib, discover it directly in the running free-threaded interpreter:

import <module>            # e.g. collections
t = <type>                 # e.g. collections.deque
print([n for n in dir(t) if not n.startswith("__") or n in ("__setitem__","__getitem__","__iter__","__len__")])

Complement with the C source under review (Objects/…c, Modules/…c): the PyMethodDef / PySequenceMethods / PyMappingMethods tables tell you which slots mutate self vs. read it. Cross-reference scan_gil_usage.py / any shared-state findings if available to target the exact fields the reviewers flagged.

Read the full file on GitHub · 225 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 8d ago First seen · 225 lines · 0 tokens per session scan A 8e196b962205

Subscribe to this mod's changes

tsan-stress-generator is an agent published in the GitHub repository ReviewToolkits/cpython-review-toolkit (10 stars, last pushed 1mo ago), licensed MIT. It adds 264 tokens to every session and 2,803 once invoked, about $0.0013 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other agents, from other repositories

python-pro

Write idiomatic Python code with advanced features like decorators, generators, and async/await. Optimizes performance, implements design patterns, and ensures comprehensive testing. Use PROACTIVELY for Python refactoring, optimization, or complex Python features.

echoVic/blade-code · 51 tokens

django-tester

Testing expert for writing comprehensive Django tests with 90%+ coverage using pytest and factoryboy.

smicolon/ai-kit · 23 tokens

python-expert

Use this agent when working with Python code that requires advanced features, performance optimization, or comprehensive refactoring. Examples: Context: User needs to optimize a slow Python function that processes large datasets. user: "This function is taking too long to process our data, can you help optimize it?"…

xbim08/awesome-claude-code-plugins · 0 tokens

python-test-engineer

Write behavior-driven suites and drive TDD workflows in Python. TRIGGER WHEN: writing tests, improving test coverage, fixing broken tests, setting up pytest configurations, or practicing red-green-refactor workflows. DO NOT TRIGGER WHEN: building new features from scratch or designing system architecture (use…

acaprino/daodan · 66 tokens

python-implementation-agent

Implement Python development tasks with testing and verification.

benbrastmckie/nvim · 13 tokens

python-pro

Write idiomatic Python code with advanced features like decorators, generators, and async/await. Optimizes performance, implements design patterns, and ensures comprehensive testing. Use PROACTIVELY for Python refactoring, optimization, or complex Python features.

NOMARJ/sigil · 51 tokens