You are Codex CLI running locally in the user’s current repository.
SKILL INTENT
- This skill performs an evidence-first dead-code audit for Python repositories and writes a reviewable report.
- It also supports an optional “apply” phase where you remove ONLY items the user approves (via explicit IDs or by marking
x in docs/audit/dead_code_progress.txt).
SKILL FORMAT NOTES
- This SKILL.md uses YAML front matter (
name, description) as required by Codex skills. :contentReference[oaicite:1]{index=1}
- Codex injects only the skill’s name/description/path by default; the instruction body is injected only when explicitly invoked. :contentReference[oaicite:2]{index=2}
WHERE TO WRITE OUTPUTS (MANDATORY)
Write ALL audit artifacts under:
- docs/audit/audit.md (canonical, detailed)
- docs/audit/dead_code_audit.md (human summary)
- docs/audit/dead_code_audit.json (machine)
- docs/audit/dead_code_progress.txt (user approval workflow)
DEFAULT EXCLUSIONS
Avoid scanning large/binary/data folders unless necessary:
- Ignore: db/, out/, .venv/, dist/, build/, node_modules/, docs/ (except docs/audit/), **/*.pdf, **/*.png, etc.
UV REQUIREMENT
- The repo is expected to be managed with uv (pyproject.toml + uv.lock).
- Prefer running tests/coverage via uv tasks defined in pyproject.
- If uv is not available, do NOT “fake it”; instead, generate the static audit and clearly note what could not be run.
== MODES ==
A) AUDIT MODE (default)
B) APPLY MODE (explicit)
NEW: REPO TYPE DETECTION (PUBLISHED LIBRARY HEURISTIC)
Goal: avoid breaking public API surfaces in publishable/distributed libraries.
Define a boolean: PUBLISHED_LIBRARY
Set PUBLISHED_LIBRARY=true if at least TWO of the following signals are present:
- pyproject.toml has [project] with name AND (version OR dynamic version) AND a build-system backend (setuptools/hatchling/poetry/pdm).
- README mentions "pip install" OR "PyPI" OR contains a pypi.org link.
- CI/workflows mention publish/release (e.g., "pypi", "twine", "publish", "release", "build wheel", "sdist").
- Project metadata suggests distribution: classifiers, keywords, project.urls, license fields, long_description/readme, etc.
If uncertain, default to PUBLISHED_LIBRARY=true (conservative).
NEW: API SURFACE SAFETY RULE (PROMOTE RE-EXPORTS)
If PUBLISHED_LIBRARY=true:
- ANY finding that is:
a) defined in any _init.py (package or subpackage), OR
b) only referenced via _init.py re-export (e.g., imported into init.py, listed in all, star exports),
MUST be classified as “Needs manual confirmation” (NOT “Safe removal”), even if it has zero in-repo call sites.
- Rationale: it may be public API used by downstream consumers, not by this repo itself.
- In the audit.md, explicitly note this rule in Methodology and in the per-item Recommendation include:
"Confirm downstream usage: search dependent repos / pip consumers / internal packages before removal."
If PUBLISHED_LIBRARY=false:
- You may classify re-export-only items as dead only with exceptionally strong evidence (still prefer “manual confirmation”).
AUDIT MODE — REQUIRED WORKFLOW (execute fully)
- Prep
- Ensure docs/audit exists (create if needed).
- Read README.md and pyproject.toml to find entrypoints, tasks, scripts, console scripts.
- Detect code roots dynamically (do not assume src/guardrail):
- likely roots: src/, app/, packages/, services/, scripts/, tests/
- Run REPO TYPE DETECTION and set PUBLISHED_LIBRARY accordingly (document it in audit.md).
- Inventory
- Enumerate top-level python packages/modules (and key subpackages).
- Identify public API boundaries:
- init.py re-exports
- all
- registries / plugin discovery
- Identify leaf modules likely unused.
- Evidence-first reference mapping
- Use ripgrep to find imports/usages across the repo roots.
- For each candidate file/symbol:
- direct references (SymbolName)
- module imports (import x / from x import y)
- dynamic usage signals: importlib, getattr, registry patterns, plugin discovery, all, side-effect imports
- Apply the API SURFACE SAFETY RULE when PUBLISHED_LIBRARY=true.
- Runtime signals (uv)
- Discover the correct uv commands from pyproject (tasks).
- Run the test suite with uv (and coverage if available).
- Capture pass/fail and note low-coverage modules.
- Dependency hygiene
- Cross-check pyproject dependencies vs in-repo imports (src/scripts/tests).
- Mark “definitely unused” vs “maybe unused (plugins/extras)” depending on evidence.
- Write artifacts (MANDATORY)
Create:
- docs/audit/audit.md (canonical, strict format)
- docs/audit/dead_code_audit.md (summary format)
- docs/audit/dead_code_audit.json (schema below)
After generating docs/audit/dead_code_audit.json, run:
- uv run python /scripts/update_dead_code_progress.py --audit-json docs/audit/dead_code_audit.json --progress docs/audit/dead_code_progress.txt
Where:
- = the directory containing this SKILL.md (resolve via the skill path available in context; use an absolute path when running the command).
- Acceptance criteria
- No “dead” claim without evidence.
- Every candidate includes: confidence + risk + exact evidence.
- No production-code modifications in audit mode.
CANONICAL AUDIT DOC — docs/audit/audit.md (REQUIRED FORMAT)
Title: "Dead Code & Repo Hygiene Audit"
Header block (bullets):
- Repo:
- Generated at:
- Scope: <detected roots e.g., src/, scripts/, tests/, pyproject.toml>
- Exclusions:
- How to reproduce: exact commands executed (copy-paste)
Section 1: Methodology
Section 2: Findings Summary (table)
Categories:
- Safe removal (high confidence)
- Needs manual confirmation
- Dependency findings
- Not dead but problematic
Section 3: Safe Removal Candidates (table columns)
ID | Item | Type | Location | Why it looks dead | Evidence (commands + results snippets) | Confidence (0-1) | Risk (L/M/H) | Recommendation
Section 4: Needs Manual Confirmation (same table)
Recommendations MUST include “how to confirm”.
Section 5: Dependency Findings (table)
Dependency | Declared in | Observed imports (paths) | Confidence | Recommendation
Section 6: Not Dead, But Problematic
Section 7: Appendix — Evidence Log
- Commands executed
- Key rg searches
- Test output summary
FEW-SHOT SAMPLE — INCLUDE THIS BLOCK VERBATIM, then fill real findings below it
Example finding row (illustrative only; replace with real ones after the example block):
| ID |
Item |
Type |
Location |
Why it looks dead |
Evidence (commands + results snippets) |
Confidence (0-1) |
Risk (L/M/H) |
Recommendation |
| DR-001 |
path/to/module.py:some_helper() |
function |
path/to/module.py |
No imports/call sites found in src/scripts/tests; not referenced by registry |
rg -n "some_helper" src scripts tests -> (no matches); rg -n "from package.module" src scripts tests -> (no matches) |
0.92 |
Low |
Mark for removal after confirming no dynamic import; run full tests + grep in CI |
SUMMARY DOC — docs/audit/dead_code_audit.md (REQUIRED FORMAT)
A) Executive summary (5–10 bullets)
B) Safe removal candidates (table)
C) Needs manual confirmation (table)
D) Not dead, but problematic (bullets)
E) Dependency findings (table)
F) Suggested follow-up plan (checklist)
JSON — docs/audit/dead_code_audit.json (REQUIRED SHAPE)
{
"generated_at": "...",
"repo_roots": ["..."],
"safe_removal_candidates": [
{
"id": "DR-001",
"type": "file|module|class|function|constant|dependency",
"name": "...",
"path": "...",
"confidence": 0.0,
"evidence": ["..."],
"risk": "low|medium|high",
"recommendation": "..."
}
],
"needs_manual_confirmation": [
{
"id": "MC-001",
"type": "...",
"name": "...",
"path": "...",
"confidence": 0.0,
"evidence": ["..."],
"risk": "low|medium|high",
"recommendation": "..."
}
],
"dependency_findings": [
{
"id": "DEP-001",
"type": "dependency",
"name": "...",
"path": "pyproject.toml",
"confidence": 0.0,
"evidence": ["..."],
"risk": "low|medium|high",
"recommendation": "..."
}
],
"notes": ["..."]
}
APPLY MODE — REQUIRED WORKFLOW (only when explicitly asked)
INPUTS USER MAY PROVIDE
- Inline:
Remove: DR-001, DR-002
- Inline with extra checks:
Remove:
- MC-001: rg -n "lorem_ipsum" .
- Dependency httpx: rg -n "httpx" .
More instructions...
- Progress file:
- docs/audit/dead_code_progress.txt (user marks
x in Remove?)
RULES
- Remove ONLY what the user approved.
- Before deleting each item:
- Re-run the evidence checks (rg + entrypoint review) and confirm no dynamic usage.
- If uncertainty remains, stop and ask for explicit confirmation (or leave it).
- After changes:
- Run uv-based lint/test tasks if present (discover from pyproject).
- Summarize changes + show what was removed + where.
- Never delete files outside the repo or touch large data artifacts.
When user says:
- “$dead-code-audit apply from progress”
You must:
- Read docs/audit/dead_code_progress.txt
- Collect items with Remove? == 'x' (case-insensitive)
- Apply removals safely and update:
- docs/audit/audit.md (add an “Applied changes” section)
- docs/audit/dead_code_audit.json (mark removed items with a note or move to a new field if you prefer)
- docs/audit/dead_code_progress.txt (preserve Notes; optionally mark as DONE)
NOW START when invoked.
Converted and distributed by TomeVault — claim your Tome and manage your conversions.
1---2name: dead-code-audit3description: Exhaustively audit Python repos for dead code and dependency hygiene; use when you need evidence-backed removal candidates with docs/audit/ artifacts. Use when this capability is needed.4---56You are Codex CLI running locally in the user’s current repository.78SKILL INTENT910- This skill performs an evidence-first dead-code audit for Python repositories and writes a reviewable report.11- It also supports an optional “apply” phase where you remove ONLY items the user approves (via explicit IDs or by marking `x` in docs/audit/dead_code_progress.txt).1213SKILL FORMAT NOTES1415- This SKILL.md uses YAML front matter (`name`, `description`) as required by Codex skills. :contentReference[oaicite:1]{index=1}16- Codex injects only the skill’s name/description/path by default; the instruction body is injected only when explicitly invoked. :contentReference[oaicite:2]{index=2}1718WHERE TO WRITE OUTPUTS (MANDATORY)19Write ALL audit artifacts under:2021- docs/audit/audit.md (canonical, detailed)22- docs/audit/dead_code_audit.md (human summary)23- docs/audit/dead_code_audit.json (machine)24- docs/audit/dead_code_progress.txt (user approval workflow)2526DEFAULT EXCLUSIONS27Avoid scanning large/binary/data folders unless necessary:2829- Ignore: db/, out/, .venv/, dist/, build/, node_modules/, docs/ (except docs/audit/), **/\*.pdf, **/\*.png, etc.3031UV REQUIREMENT3233- The repo is expected to be managed with uv (pyproject.toml + uv.lock).34- Prefer running tests/coverage via uv tasks defined in pyproject.35- If uv is not available, do NOT “fake it”; instead, generate the static audit and clearly note what could not be run.3637== MODES ==38A) AUDIT MODE (default)39B) APPLY MODE (explicit)4041---4243## NEW: REPO TYPE DETECTION (PUBLISHED LIBRARY HEURISTIC)4445Goal: avoid breaking public API surfaces in publishable/distributed libraries.4647Define a boolean: PUBLISHED_LIBRARY4849Set PUBLISHED_LIBRARY=true if at least TWO of the following signals are present:50511. pyproject.toml has [project] with name AND (version OR dynamic version) AND a build-system backend (setuptools/hatchling/poetry/pdm).522. README mentions "pip install" OR "PyPI" OR contains a pypi.org link.533. CI/workflows mention publish/release (e.g., "pypi", "twine", "publish", "release", "build wheel", "sdist").544. Project metadata suggests distribution: classifiers, keywords, project.urls, license fields, long_description/readme, etc.5556If uncertain, default to PUBLISHED_LIBRARY=true (conservative).5758---5960## NEW: API SURFACE SAFETY RULE (PROMOTE RE-EXPORTS)6162If PUBLISHED_LIBRARY=true:6364- ANY finding that is:65 a) defined in any _**init**.py (package or subpackage), OR66 b) only referenced via _**init**.py re-export (e.g., imported into **init**.py, listed in **all**, star exports),67 MUST be classified as “Needs manual confirmation” (NOT “Safe removal”), even if it has zero in-repo call sites.68- Rationale: it may be public API used by downstream consumers, not by this repo itself.69- In the audit.md, explicitly note this rule in Methodology and in the per-item Recommendation include:70 "Confirm downstream usage: search dependent repos / pip consumers / internal packages before removal."7172If PUBLISHED_LIBRARY=false:7374- You may classify re-export-only items as dead only with exceptionally strong evidence (still prefer “manual confirmation”).7576---7778## AUDIT MODE — REQUIRED WORKFLOW (execute fully)79800. Prep8182- Ensure docs/audit exists (create if needed).83- Read README.md and pyproject.toml to find entrypoints, tasks, scripts, console scripts.84- Detect code roots dynamically (do not assume src/guardrail):85 - likely roots: src/, app/, packages/, services/, scripts/, tests/86- Run REPO TYPE DETECTION and set PUBLISHED_LIBRARY accordingly (document it in audit.md).87881. Inventory8990- Enumerate top-level python packages/modules (and key subpackages).91- Identify public API boundaries:92 - **init**.py re-exports93 - **all**94 - registries / plugin discovery95- Identify leaf modules likely unused.96972. Evidence-first reference mapping9899- Use ripgrep to find imports/usages across the repo roots.100- For each candidate file/symbol:101 - direct references (SymbolName)102 - module imports (import x / from x import y)103 - dynamic usage signals: importlib, getattr, registry patterns, plugin discovery, **all**, side-effect imports104- Apply the API SURFACE SAFETY RULE when PUBLISHED_LIBRARY=true.1051063. Runtime signals (uv)107108- Discover the correct uv commands from pyproject (tasks).109- Run the test suite with uv (and coverage if available).110- Capture pass/fail and note low-coverage modules.1111124. Dependency hygiene113114- Cross-check pyproject dependencies vs in-repo imports (src/scripts/tests).115- Mark “definitely unused” vs “maybe unused (plugins/extras)” depending on evidence.1161175. Write artifacts (MANDATORY)118 Create:1191. docs/audit/audit.md (canonical, strict format)1201. docs/audit/dead_code_audit.md (summary format)1211. docs/audit/dead_code_audit.json (schema below)122123After generating docs/audit/dead_code_audit.json, run:124125- uv run python <SKILL_DIR>/scripts/update_dead_code_progress.py --audit-json docs/audit/dead_code_audit.json --progress docs/audit/dead_code_progress.txt126127Where:128129- <SKILL_DIR> = the directory containing this SKILL.md (resolve via the skill path available in context; use an absolute path when running the command).1301316. Acceptance criteria132133- No “dead” claim without evidence.134- Every candidate includes: confidence + risk + exact evidence.135- No production-code modifications in audit mode.136137---138139## CANONICAL AUDIT DOC — docs/audit/audit.md (REQUIRED FORMAT)140141- Title: "Dead Code & Repo Hygiene Audit"142- Header block (bullets):143 - Repo: <repo name or path>144 - Generated at: <ISO datetime>145 - Scope: <detected roots e.g., src/, scripts/, tests/, pyproject.toml>146 - Exclusions: <folders>147 - How to reproduce: exact commands executed (copy-paste)148149- Section 1: Methodology150- Section 2: Findings Summary (table)151 Categories:152 - Safe removal (high confidence)153 - Needs manual confirmation154 - Dependency findings155 - Not dead but problematic156157- Section 3: Safe Removal Candidates (table columns)158 ID | Item | Type | Location | Why it looks dead | Evidence (commands + results snippets) | Confidence (0-1) | Risk (L/M/H) | Recommendation159160- Section 4: Needs Manual Confirmation (same table)161 Recommendations MUST include “how to confirm”.162163- Section 5: Dependency Findings (table)164 Dependency | Declared in | Observed imports (paths) | Confidence | Recommendation165166- Section 6: Not Dead, But Problematic167- Section 7: Appendix — Evidence Log168 - Commands executed169 - Key rg searches170 - Test output summary171172FEW-SHOT SAMPLE — INCLUDE THIS BLOCK VERBATIM, then fill real findings below it173Example finding row (illustrative only; replace with real ones after the example block):174| ID | Item | Type | Location | Why it looks dead | Evidence (commands + results snippets) | Confidence (0-1) | Risk (L/M/H) | Recommendation |175| --- | --- | --- | --- | --- | --- | --- | --- | --- |176| DR-001 | path/to/module.py:some_helper() | function | path/to/module.py | No imports/call sites found in src/scripts/tests; not referenced by registry | rg -n "some_helper" src scripts tests -> (no matches); rg -n "from package.module" src scripts tests -> (no matches) | 0.92 | Low | Mark for removal after confirming no dynamic import; run full tests + grep in CI |177178---179180## SUMMARY DOC — docs/audit/dead_code_audit.md (REQUIRED FORMAT)181182A) Executive summary (5–10 bullets)183B) Safe removal candidates (table)184C) Needs manual confirmation (table)185D) Not dead, but problematic (bullets)186E) Dependency findings (table)187F) Suggested follow-up plan (checklist)188189---190191## JSON — docs/audit/dead_code_audit.json (REQUIRED SHAPE)192193{194"generated_at": "...",195"repo_roots": ["..."],196"safe_removal_candidates": [197{198"id": "DR-001",199"type": "file|module|class|function|constant|dependency",200"name": "...",201"path": "...",202"confidence": 0.0,203"evidence": ["..."],204"risk": "low|medium|high",205"recommendation": "..."206}207],208"needs_manual_confirmation": [209{210"id": "MC-001",211"type": "...",212"name": "...",213"path": "...",214"confidence": 0.0,215"evidence": ["..."],216"risk": "low|medium|high",217"recommendation": "..."218}219],220"dependency_findings": [221{222"id": "DEP-001",223"type": "dependency",224"name": "...",225"path": "pyproject.toml",226"confidence": 0.0,227"evidence": ["..."],228"risk": "low|medium|high",229"recommendation": "..."230}231],232"notes": ["..."]233}234235---236237## APPLY MODE — REQUIRED WORKFLOW (only when explicitly asked)238239INPUTS USER MAY PROVIDE2402411. Inline:242 Remove: DR-001, DR-0022432. Inline with extra checks:244 Remove:245 - MC-001: rg -n "lorem_ipsum" .246 - Dependency httpx: rg -n "httpx" .247 More instructions...2483. Progress file:249 - docs/audit/dead_code_progress.txt (user marks `x` in Remove?)250251RULES252253- Remove ONLY what the user approved.254- Before deleting each item:255 - Re-run the evidence checks (rg + entrypoint review) and confirm no dynamic usage.256 - If uncertainty remains, stop and ask for explicit confirmation (or leave it).257- After changes:258 - Run uv-based lint/test tasks if present (discover from pyproject).259 - Summarize changes + show what was removed + where.260- Never delete files outside the repo or touch large data artifacts.261262When user says:263264- “$dead-code-audit apply from progress”265 You must:266- Read docs/audit/dead_code_progress.txt267- Collect items with Remove? == 'x' (case-insensitive)268- Apply removals safely and update:269 - docs/audit/audit.md (add an “Applied changes” section)270 - docs/audit/dead_code_audit.json (mark removed items with a note or move to a new field if you prefer)271 - docs/audit/dead_code_progress.txt (preserve Notes; optionally mark as DONE)272273NOW START when invoked.274275---276> Converted and distributed by [TomeVault](https://tomevault.io/claim/y4rd13) — claim your Tome and manage your conversions.277<!-- tomevault:4.0:skill_md:2026-04-14 -->