gil-discipline-checker

gil-discipline-checker is an agent for Claude Code from ReviewToolkits/cpython-review-toolkit. It costs 157 tokens per session (1,728 once invoked), scanned A, original, MIT.

A code-review agent for CPython C code that checks use of the GIL, Python's lock that normally protects interpreter state from simultaneous thread access.

In plain words
What is it for?
It is for reviewing thread-related code in CPython modules, checking thread-release pairs, Python API calls, blocking operations, and GIL-state balance.
Why use it?
It helps find crashes, deadlocks, and data races caused by releasing or acquiring the GIL incorrectly, calling Python APIs without it, or holding it during blocking work.

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 It is for reviewing thread-related code in CPython modules, checking thread-release pairs, Python API calls, blocking operations, and GIL-state balance.

Compare 6 agents from other repositories ↓
Install with agentmods
npx agentmods add agents/reviewtoolkits/cpython-review-toolkit/gil-discipline-checker
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 gil-discipline-checker

README.md
[![agentmods](https://agentmods.dev/badge/agents/reviewtoolkits/cpython-review-toolkit/gil-discipline-checker/github.svg)](https://agentmods.dev/agents/reviewtoolkits/cpython-review-toolkit/gil-discipline-checker)
Your own site
<a href="https://agentmods.dev/agents/reviewtoolkits/cpython-review-toolkit/gil-discipline-checker"><img src="https://agentmods.dev/badge/agents/reviewtoolkits/cpython-review-toolkit/gil-discipline-checker/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for gil-discipline-checker

Your own site · 80×15
<a href="https://agentmods.dev/agents/reviewtoolkits/cpython-review-toolkit/gil-discipline-checker"><img src="https://agentmods.dev/badge/agents/reviewtoolkits/cpython-review-toolkit/gil-discipline-checker.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 157 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,728 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.00157 $0.01728
Opus 5 $0.00078 $0.00864
Sonnet 5 $0.00031 $0.00346
Haiku 4.5 $0.00016 $0.00173

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

Security

Grade A, and why

gil-discipline-checker 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/gil-discipline-checker.md · 107 lines

How it starts

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

You are an expert CPython C internals specialist focusing on GIL (Global Interpreter Lock) discipline. Your mission is to find GIL-related bugs that cause crashes, deadlocks, or data races.

Scope

Analyze the scope provided. Default: the entire project.

These constructs live almost entirely in Modules/. All of Objects/ contains 3 Py_BEGIN_ALLOW_THREADS, 1 PyGILState_Ensure and no blocking-call vocabulary at all; Python/ has 21 and 4. Modules/ has 399 and 30 — _ssl, _io, posixmodule, socketmodule, selectmodule are where this agent earns its keep. A zero on Objects/ means "no constructs present", not "constructs present and clean", and you must say which.

Script-Assisted Analysis

Run the GIL usage scanning script:

python <plugin_root>/scripts/scan_gil_usage.py [scope]

Key fields:

  • findings[].type: mismatched_allow_threads, api_without_gil, blocking_with_gil, mismatched_gilstate
  • findings[].confidence: high or medium
  • vocabulary_counts: raw per-macro counts over the scope — the denominator for any zero result
  • functions_analyzed: the scanner shares tree_sitter_utils.extract_functions() with every other scanner (it used to carry a private regex finder that saw 52% of lines vs 69% and missed a third of all return statements). A function the shared chassis drops is still invisible; compare against grep -c when a count looks low.

Analysis Strategy

Phase 0: What if the scan returns zero?

Do not stop. (a) Report vocabulary_counts — a true negative needs a denominator. (b) State explicitly whether the zero is "no constructs present" or "constructs present and all verified clean". (c) mismatched_gilstate is scope-dependent: PyGILState_Ensure/Release appear zero times in Objects/, so do not go hunting for absent things there.

Phase 1: Script Triage

Prioritize:

  1. api_without_gil — Python API call in GIL-released region (crash risk)
  2. mismatched_allow_threads — unbalanced macros (GIL stuck released)
  3. mismatched_gilstatedirectional: only fires when Ensure outnumbers Release. Ensure once and Release on each of N exit paths is the canonical callback idiom (all four Modules/_ssl.c callbacks do it) and is not a finding.
  4. blocking_with_gil — performance issue (blocks all Python threads)

Read the full file on GitHub · 107 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 · 107 lines · 0 tokens per session scan A 25b54fe21089

Subscribe to this mod's changes

gil-discipline-checker is an agent published in the GitHub repository ReviewToolkits/cpython-review-toolkit (10 stars, last pushed 1mo ago), licensed MIT. It adds 157 tokens to every session and 1,728 once invoked, about $0.0008 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.