gateway-module-extraction

gateway-module-extraction is a skill for Claude Code, Codex from humanerd-drew/opencode-drewgent. It costs 46 tokens per session (8,111 once invoked), scanned A, original, MIT.

A guide to splitting a very large Python runner file into smaller modules without losing access to the runner's shared state.

In plain words
What is it for?
Use it when extracting gateway, session, scheduling, or lifecycle code into separate files and checking the result across multiple sessions.
Why use it?
It addresses common refactoring problems such as name clashes with Python's standard library, circular references, and tests that depend on fixture setup order.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one. Also seen: mentions subagents; mentions OpenCode.

Needs its repository: it reads a path above its own folder, which exists only inside the repository. The line is if ! grep -q "self\.$attr\s*=" ../run.py; then.

Good fit Use it when extracting gateway, session, scheduling, or lifecycle code into separate files and checking the result across multiple sessions.

Compare 6 skills from other repositories ↓
Install

Getting it into your agent

It runs from inside its repository, so the clone comes first — what it calls does not travel with the file alone.

Clone the repo
git clone --depth 1 https://github.com/humanerd-drew/opencode-drewgent
agentmods
npx agentmods add skills/humanerd-drew/opencode-drewgent/gateway-module-extraction

Made for: Claude Code, Codex.

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 gateway-module-extraction

README.md
[![agentmods](https://agentmods.dev/badge/skills/humanerd-drew/opencode-drewgent/gateway-module-extraction.svg)](https://agentmods.dev/skills/humanerd-drew/opencode-drewgent/gateway-module-extraction)
Your own site
<a href="https://agentmods.dev/skills/humanerd-drew/opencode-drewgent/gateway-module-extraction"><img src="https://agentmods.dev/badge/skills/humanerd-drew/opencode-drewgent/gateway-module-extraction.svg" alt="Measured on agentmods" height="20"></a>
Per session 46 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 8,111 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.00046 $0.08111
Opus 5 $0.00023 $0.04056
Sonnet 5 $0.00009 $0.01622
Haiku 4.5 $0.00005 $0.00811

Measured 3d ago against content hash 903288dac67c, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-07, from the pricing page.

Security

Grade A, and why

gateway-module-extraction 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 3d 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.

skills/software-development/gateway-module-extraction/SKILL.md · 616 lines

How it starts

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

Skill: Extracting Modules from gateway/run.py

When to Use

When splitting GatewayRunner methods into separate modules under gateway/ and the extracted class needs to read/write the runner's many attributes (adapters, session_store, hooks, task_manager, _running_agents, etc.).

Three Things That Bite

1. stdlib name collision

Dispatcher clashes with asyncio.Dispatcher (or any stdlib symbol you forgot). Symptom: mysterious AttributeError or TypeError at import time, not at use time. Fix: prefix with the domain — MessageDispatcher, SessionLifecycle, CronRunner. Always grep stdlib before naming:

python3 -c "import asyncio; print(hasattr(asyncio, 'Dispatcher'))"

2. circular reference via runner

Extracted class needs self.adapters, self._running_agents_ts, etc. Two ways to give it access:

a) Pass runner in __init__ and store as self.runner:

class SentinelGuard:
    def __init__(self, runner):
        self.runner = runner  # NOT self.run_agent
    def is_sentinel(self, session_key):
        return self.runner._running_agents.get(session_key) is _SENTINEL

b) Pass the specific attributes the class needs (cleaner but verbose).

For {{AGENT_NAME}} gateway, use (a) — 51 attribute references would make (b) painful.

3. Mock fixture sync order

After extracting modules, tests fail because mock_gateway_runner (built via object.__new__(GatewayRunner)) doesn't have the new attributes. Order matters:

  1. First: replace the original method body with self._new_module.method() delegate
  2. Then: update mock fixture to set the new attributes
  3. Then: run tests

Doing fixture first leaves the real runner working but the mock broken. Doing tests first leaves everything broken. Delegate-first means the wiring is provably correct before any test changes.

  • references/pyc-staleness-pitfall.md.pyc staleness masking extraction errors (stale bytecode loads instead of modified source). Always clear __pycache__ after modifying multiple Python files during extraction.

Read the full file on GitHub · 616 lines

Files

What ships with it

2 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

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. 3d ago First seen · 616 lines · 0 tokens per session scan A 903288dac67c

Subscribe to this mod's changes

gateway-module-extraction is a skill published in the GitHub repository humanerd-drew/opencode-drewgent (2 stars, last pushed 1mo ago), licensed MIT. It adds 46 tokens to every session and 8,111 once invoked, about $0.0002 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-09-03.

Related

Other skills, from other repositories

mem0-oss-to-platform

Plan and then execute a migration of a project from the mem0 open-source / self-hosted SDK (the local Memory class) to the mem0 Platform / hosted / managed SDK (the MemoryClient class). Use this whenever a developer wants to move, switch, or migrate their mem0 usage off OSS/self-hosted to the hosted API — e.g.…

mem0ai/mem0 · 273 tokens

agui-dotnet-protobuf

Use the protobuf wire transport (instead of the default Server-Sent Events) for an AG-UI connection with the AG-UI .NET SDK — a compact binary event stream negotiated via the Accept header. USE FOR: making an AGUIChatClient prefer protobuf by wiring an AGUIEventStreamHandler with ProtobufEventStreamFormatter (then…

ag-ui-protocol/ag-ui · 162 tokens

azure-mgmt-botservice-dotnet

Azure Resource Manager SDK for Bot Service in .NET. Management plane operations for creating and managing Azure Bot resources, channels (Teams, DirectLine, Slack), and connection settings. Triggers: "Bot Service", "BotResource", "Azure Bot", "DirectLine channel", "Teams channel", "bot management .NET", "create bot".

microsoft/skills · 78 tokens

fastapi-router-py

Create FastAPI routers with CRUD operations, authentication dependencies, and proper response models. Use when building REST API endpoints, creating new routes, implementing CRUD operations, or adding authenticated endpoints in FastAPI applications.

microsoft/skills · 46 tokens

migrate-segw-to-rap

Reverse-engineer a SEGW-built OData V2 service (MPC/DPC/MPCEXT/DPCEXT) into a modern RAP V4 service — tables, CDS views (interface + projection), behavior definitions, draft entities, service definition + binding. Use when asked to "migrate this SEGW service to RAP", "convert OData V2 to V4 RAP", "modernize this…

arc-mcp/arc-1 · 106 tokens

telnyx-messaging-hosted-curl

Set up hosted SMS numbers, toll-free verification, and RCS messaging. Use when migrating numbers or enabling rich messaging features. This skill provides REST API (curl) examples.

team-telnyx/ai · 45 tokens