Agent skill

Safe Extraction

by ZaxbyHub in ZaxbyHub/opencode-swarm

Apply when extracting code from a large monolith file into submodules.

MITAuto-check passedTesting & QA

Install Safe Extraction

skills CLI
$ npx skills add ZaxbyHub/opencode-swarm --skill safe-extraction -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install ZaxbyHub/opencode-swarm safe-extraction --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/ZaxbyHub/opencode-swarm.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.opencode/skills/generated/safe-extraction .claude/skills/safe-extraction && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
safe-extraction
GitHub stars
494
Token cost
~2.6k tokens
SKILL.md length
919 words
Files
2
Skills in repo
91
Repo updated
First seen
Licence
MIT

At a glance

Apply when extracting code from a large monolith file into submodules.

  • Works in 8 steps: Pre-extraction audit → Create the extracted module → Create barrel re-export (if preserving… → …
  • Tasks that involve Failing and flaky tests
  • SKILL.md covers When to use this skill, Step 0 — Pre-extraction audit, Step 1 — Create the extracted… and Step 2 — Create barrel…, plus 7 more sections
  • Calls bun

What it does

Safe Extraction is an agent skill from ZaxbyHub/opencode-swarm. Apply when extracting code from a large monolith file into submodules. Covers barrel re-exports, internals DI seam proxy patterns, CI invariant allowlist updates, and cross-file test verification. Prevents CI failures, broken imports, and test regressions from code extraction.

Its SKILL.md is about 2.6k tokens, which your agent loads only when the skill is triggered. The skill folder holds 1 other file.

It sits in Testing & QA, covering Failing and flaky tests. The repository describes itself as: Architect-centric agentic swarm plugin for OpenCode. Hub-and-spoke orchestration with SME consultation, code generation, and QA review. The licence is MIT.

When your agent uses it

  • Tasks that involve Failing and flaky tests

Example prompts

  • “/safe-extraction”

Workflow steps

8 steps, taken from the step headings in SKILL.md.

  1. Pre-extraction audit
  2. Create the extracted module
  3. Create barrel re-export (if preserving public API)
  4. Handle _internals DI seams
  5. Update CI invariant scripts
  6. 5 — Re-capture SAST baseline
  7. Update documentation
  8. Verification checklist

What it can do on your machine

Read from SKILL.md and the folder at commit b63a4bd. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • bun

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Safe Extraction loads about 2.6k tokens when it runs. Until then it costs about 74 tokens; SKILL.md has 919 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~74
When it runs · the whole SKILL.md, loaded when a task matches
~2.6k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from ZaxbyHub/opencode-swarm at commit b63a4bd, republished under its MIT licence (© ZaxbyHub). 919 words, ~2,584 tokens.

Download SKILL.mdSave it as .claude/skills/safe-extraction/SKILL.md (or your agent's skills folder). This skill also uses 1 other file; get the full folder from GitHub.
name
safe-extraction
description
Apply when extracting code from a large monolith file into submodules. Covers barrel re-exports, _internals DI seam proxy patterns, CI invariant allowlist updates, and cross-file test verification. Prevents CI failures, broken imports, and test regressions from code extraction.
effort
medium
source_knowledge_ids
b02ac9d7-9f2b-4ac0-9afe-5ee5f35f54c3, cc366a49-f097-41a5-847b-ccce077e6c80
generated_at
2026-06-14T16:50:00Z
confidence
0.8
status
active
version
4
skill_origin
generated
provenance_note
Re-linked to current knowledge entries (version 4). The original source ID c276dc6e... is no longer present in the active knowledge store. The skill body and…

Safe Extraction Protocol

Follow every step in order. Do not skip steps.

When to use this skill

  • A source file exceeds team-agreed size thresholds (this repo uses <2000 lines per file per FR-005) and needs splitting
  • A subsystem (destructive-command, worktree-isolation, etc.) is being extracted to its own file
  • Code is being moved from one module to another without changing behavior

Benefit: Prevents the three most common extraction failure modes:

  1. CI invariant check failures (new file paths not in allowlists)
  2. Broken _internals DI seams (test mocks stop working)
  3. Cross-file test regressions (other test files that consume the module)

Step 0 — Pre-extraction audit

Before moving ANY code, inventory every path-scoped artifact that references the source file:

0a. CI invariant scripts
bash
grep -rn "<source-file-path>" scripts/ .github/workflows/

Check:

  • LEGACY_EXEMPTS arrays (e.g., check-invariants.sh)
  • Path-scoped lint/scan configurations
  • GitHub Actions path filters
0b. Mock allowlists
bash
grep -rn "<source-file-path>" scripts/mock-allowlist.txt
0c. Test file inventory
bash
grep -rln "from.*<source-module>" src/ tests/ --include="*.test.ts"
grep -rln "vi.spyOn.*<source-module>" src/ tests/ --include="*.test.ts"
grep -rln "_internals.*<source-module>" src/ tests/ --include="*.test.ts"

Record EVERY test file that imports or spies on the source module. These must all pass after extraction.

Prefer the imports tool or repo_map action for comprehensive consumer discovery. Grep catches direct string matches but misses require() imports, dynamic import(), and re-exports through intermediate modules. Use grep as a secondary cross-check.

0d. Import graph
Use the imports tool or repo_map to find all consumers of exports from the source file.

Step 1 — Create the extracted module

  1. Move the code block(s) to the new file(s)
  2. Move all supporting types, constants, and helper functions used exclusively by the extracted code
  3. Add necessary imports to the new file (from external dependencies)

Step 2 — Create barrel re-export (if preserving public API)

If consumers import from the original path, keep the original file as a barrel:

typescript
// src/hooks/guardrails.ts (barrel — preserves import path)
// Use EXPLICIT named exports, not `export *`, to avoid naming conflicts
// when multiple submodules export symbols with the same name.
export {
  _internals,
  createGuardrailsHooks,
  enforceSpecDriftGate,
} from './guardrails/index';
export {
  buildEffectiveRules,
  checkFileAuthority,
  getGlobMatcher,
} from './guardrails/file-authority';
export {
  createToolBeforeHandler,
  normalizeToolInput,
} from './guardrails/tool-before';
// etc.

Verify: bun run build succeeds. All existing imports still resolve.

Step 3 — Handle _internals DI seams

If the source module exports _internals for test injection:

3a. Direct functions stay in source _internals

Functions that remain in the source file stay as direct entries:

typescript
export const _internals = {
  resolveEvidenceTaskId,      // still in this file
  loadPlanJsonOnly,           // still in this file
  // ...
};
3b. Extracted functions need getter/setter proxies

Functions moved to the extracted module need proxy entries so test mocks propagate:

typescript
import { _internals as _extractedInternals } from './extracted-module';

export const _internals = {
  resolveEvidenceTaskId,      // direct
  get extractedFn() {
    return _extractedInternals.extractedFn;    // proxy to extracted module
  },
  set extractedFn(v) {
    _extractedInternals.extractedFn = v;       // allow test injection
  },
};

The extracted module must ALSO export its own _internals:

typescript
// extracted-module.ts
export const _internals = {
  extractedFn,
  otherExtractedFn,
};

Type annotation: Always include an explicit type annotation on _internals objects to override as const readonly inference. Without it, as const makes properties readonly and test injection (_internals.fn = mockFn) fails at compile time:

typescript
// GOOD — explicit type annotation allows mutation
export const _internals: {
  extractedFn: typeof extractedFn;
  otherFn: typeof otherFn;
} = {
  extractedFn,
  otherFn,
};

CRITICAL: The extracted module's own production code must call mockable functions through _internals.fn(...), NOT through the direct function reference. If extractedFn internally calls otherExtractedFn, it must use _internals.otherExtractedFn() — otherwise test mocks set on _internals won't intercept the internal call. This is the same pattern the parent module follows.

Verify: Run ALL test files from Step 0c — not just the one explicitly in scope.

3c. Alternative: Factory parameter pattern (no _internals proxy needed)

When splitting a factory function into handler files (NOT extracting a subsystem with its own _internals), the getter/setter proxy is unnecessary. Instead:

  1. Handler files export factory functions that receive dependencies as parameters
  2. The orchestrator file calls these factories, passing closure-scoped config
  3. The barrel re-exports only the top-level orchestrator API
typescript
// guardrails/tool-before.ts — handler file
export function createToolBeforeHandler(cfg: Config, deps: Deps) {
  // Receives all dependencies as parameters — no _internals needed
  return function toolBefore(input: ToolInput) {
    /* handler logic using cfg and deps */
  };
}

// guardrails/index.ts — orchestrator
export function createGuardrailsHooks(config: PluginConfig) {
  const cfg = resolveConfig(config);
  return {
    toolBefore: createToolBeforeHandler(cfg, deps),
    // ...
  };
}

Use this pattern when:

  • Splitting a large factory function into handler files
  • The submodules don't have their own mockable functions
  • All dependencies can be passed as closure parameters

Use the _internals proxy pattern (3b) when:

  • Extracting a subsystem that tests mock independently
  • The source module exports _internals for test injection
  • Mockable functions are moving to the extracted module
Show full SKILL.md (375 more words)Show less

Step 4 — Update CI invariant scripts

For EVERY path-scoped artifact found in Step 0a, add the new file paths:

bash
# Example: check-invariants.sh
LEGACY_EXEMPTS=(
  "src/hooks/guardrails.ts"                    # original (still exists as barrel)
  "src/hooks/guardrails/file-authority.ts"     # NEW
  "src/hooks/guardrails/helpers.ts"            # NEW
  "src/hooks/guardrails/index.ts"              # NEW
)

Verify: Run the invariant check script locally if possible (bash on Windows may require WSL).

Step 4.5 — Re-capture SAST baseline

File-path moves alter SAST finding fingerprints, making pre-existing findings appear new. After extraction:

  1. Run sast_scan with capture_baseline: true and the current phase number, including BOTH the old and new file paths in changed_files
  2. Pass baseline_refresh_rationale (e.g. "file relocation only — content unchanged"): a rename always changes the finding's file identity by design, so post-rename recaptures carry novel findings that must satisfy the absorption gate with an audited rationale — this is intended behavior, not a bug
  3. The merge records a who/when/rationale triage entry for every absorbed finding, so relocated pre-existing findings stop failing the gate without silent acceptance

Verify: SAST scan on the new file paths shows only genuinely new findings, not relocated pre-existing ones.

Step 5 — Update documentation

Update any doc references that point to the old monolith for functions that moved:

bash
grep -rn "<source-file-path>" docs/ *.md

Fix references to point to the new submodule location.

Step 6 — Verification checklist

  • bun run build succeeds
  • bun run typecheck succeeds (zero new type errors)
  • biome ci . passes
  • ALL test files from Step 0c pass (not just the one in scope)
  • CI invariant scripts updated for new paths
  • Documentation references updated
  • No runtime behavior changes (pure extraction)

Common mistakes

MistakeWhy it fails
Forgetting to update LEGACY_EXEMPTSCI quality job fails on process.cwd() check for new file paths
Only testing the explicit test fileCross-file regressions in OTHER consuming test files go undetected
Not creating getter/setter proxies for _internalsTest mocks on the parent module don't propagate to extracted functions
Moving helper functions without updating/re-exporting all consumersImport errors in unrelated files that depended on the helper
Updating docs to reference new paths but missing someStale doc references confuse future readers

Relationship to other skills

  • safe-rename: Use when renaming symbols across the codebase. Use safe-extraction when moving code to new files.
  • mock-to-internals-migration: Use when converting test files from mock.module/vi.spyOn to _internals DI seam. May be needed as part of extraction if the source module's _internals changes.
  • subprocess-safety: Relevant if the extracted code calls spawn/spawnSync — ensure the _internals proxy preserves timeout/kill semantics.

© ZaxbyHub, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 1 other file in .opencode/skills/generated/safe-extraction of ZaxbyHub/opencode-swarm.

  • SKILL.md
  • retired.marker

Open the folder on GitHubat commit b63a4bd

Compare with similar skills

Safe Extraction next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Safe Extraction compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Safe Extraction this skillZaxbyHub/opencode-swarm494—~2.6kAutomated safety check: PassMIT
Swig Testswig/swig6.3k—~2.3kAutomated safety check: PassCustom licence
Triage CI FailureDataDog/datadog-agent3.8k—~2.3kAutomated safety check: PassApache-2.0
Dynamo Jira TicketDynamoDS/Dynamo2k—~1.1kAutomated safety check: PassApache-2.0
Fix Ready PRsfastrepl/anarlog9.5k—~1.4kAutomated safety check: PassMIT
Trx Analysismicrosoft/vstest969—~1.8kAutomated safety check: PassMIT

Similar skills

  • Swig Test

    swig/swig

    Run SWIG test suite for specific languages. An agent skill from swig/swig.

    6.3k GitHub stars~2.3k tokensUpdated 4 days ago
    Testing & QAAuto-check passed
  • Triage CI Failure

    DataDog/datadog-agent

    Official

    Classify a failed CI as either caused by an active incident, flakiness, or a true code regression.

    3.8k GitHub stars~2.3k tokensUpdated today
    Testing & QAAuto-check passed
  • Dynamo Jira Ticket

    DynamoDS/Dynamo

    Create structured Jira tickets for Dynamo from bug reports, failing tests, or feature requests.

    2k GitHub stars~1.1k tokensUpdated yesterday
    Testing & QAAuto-check passed
  • Fix Ready PRs

    fastrepl/anarlog

    Inspect every open non-draft PR for CI failures and unresolved Cursor Bugbot findings, then fix them on the existing PR branches.

    9.5k GitHub stars~1.4k tokensUpdated today
    Testing & QAAuto-check passed
  • Trx Analysis

    microsoft/vstest

    Official

    Parse and analyze Visual Studio TRX test result files. An agent skill from microsoft/vstest.

    969 GitHub stars~1.8k tokensUpdated yesterday
    Testing & QAAuto-check passed
  • Wio

    workersio/skills

    Testing workflow skill for finding high-value test candidates, writing focused tests, generating realistic workloads, reviewing test value, and diagnosing test-suite health.

    204 GitHub stars~5.8k tokensUpdated 2 mo ago
    Testing & QAAuto-check passed

More from ZaxbyHub/opencode-swarm

All 91 skills in this repo
  • Codebase Review Swarm

    ZaxbyHub/opencode-swarm

    Runs an evidence-gated, quote-grounded audit of a codebase for security, QA, accessibility, performance and more, and writes a verified report without changing source files.

    496 GitHub stars~2.8k tokensUpdated today
    Auto-check passed
  • Issue Tracer

    ZaxbyHub/opencode-swarm

    Drives a bug report from validation and root-cause tracing through a critic-reviewed plan, an approved minimal fix and a PR-ready closure, never merging without recorded human approval.

    496 GitHub stars~4.4k tokensUpdated today
    Auto-check passed
  • Commit and PR Publishing for Codex

    ZaxbyHub/opencode-swarm

    Codex adapter for opencode-swarm that governs commits, pushes, draft PRs, PR body updates and CI closeout, deferring to the repo's canonical commit-pr protocol.

    496 GitHub stars~1.6k tokensUpdated today
    Auto-check passed
  • Durable Session State

    ZaxbyHub/opencode-swarm

    Keeps plans, decisions, evidence and reviewer verdicts in small files so long multi-phase tasks survive context compaction and session resumes.

    496 GitHub stars~896 tokensUpdated today
    Auto-check passed
  • Swarm PR Feedback Closer

    ZaxbyHub/opencode-swarm

    Ingests existing pull request feedback such as review comments and CI failures, verifies each claim, fixes confirmed issues and reports closure status for every item.

    496 GitHub stars~14k tokensUpdated today
    Auto-check passed
  • Swarm PR Subscribe

    ZaxbyHub/opencode-swarm

    Monitor a pull request after creation and act autonomously on pushed PR activity.

    496 GitHub stars~2.2k tokensUpdated today
    Auto-check passed

Categories

Questions about Safe Extraction

What does Safe Extraction do?

Apply when extracting code from a large monolith file into submodules. Safe Extraction is an agent skill from ZaxbyHub/opencode-swarm. Apply when extracting code from a large monolith file into submodules.

When should I use Safe Extraction?

Safe Extraction fits situations like: tasks that involve Failing and flaky tests.

How do I install Safe Extraction in Claude Code?

Run `npx skills add ZaxbyHub/opencode-swarm --skill safe-extraction -a claude-code`. Or copy the skill folder (.opencode/skills/generated/safe-extraction in ZaxbyHub/opencode-swarm) into .claude/skills/safe-extraction in your project. Claude Code loads it when a task matches its description.

How do I install Safe Extraction in Codex?

Run `npx skills add ZaxbyHub/opencode-swarm --skill safe-extraction -a codex`. Or copy the skill folder (.opencode/skills/generated/safe-extraction in ZaxbyHub/opencode-swarm) into .agents/skills/safe-extraction in your project. Codex loads it when a task matches its description.

Can I use Safe Extraction in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add ZaxbyHub/opencode-swarm --skill safe-extraction -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/safe-extraction, .gemini/skills/safe-extraction, .github/skills/safe-extraction and .opencode/skills/safe-extraction in your project.

What does Safe Extraction need to run?

Going by SKILL.md and its folder, Safe Extraction needs the command-line tools its instructions call (bun).

Does Safe Extraction access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Safe Extraction safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Safe Extraction use?

Safe Extraction is published under the MIT licence (the repository's licence). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Safe Extraction use?

About 2.6k tokens (SKILL.md is roughly 10k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Safe Extraction?

Skills that share tags, products or a category with Safe Extraction: Swig Test (swig/swig, 6.3k stars), Triage CI Failure (DataDog/datadog-agent, 3.8k stars), Dynamo Jira Ticket (DynamoDS/Dynamo, 2k stars) and Fix Ready PRs (fastrepl/anarlog, 9.5k stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Safe Extraction?

ZaxbyHub (a GitHub organization) maintains it in ZaxbyHub/opencode-swarm, which has 494 GitHub stars. The repository holds 91 skills in this directory. The repository was last updated on October 10, 2026.

Source: ZaxbyHub/opencode-swarm on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.