Skip to content
Back to skills

Extract Function

ASecurity

Pulls a block of code into a well-named function with few parameters, updates the callers and checks nothing else changed.

  • 3 stars
  • 0 votes
  • 0 copies
  • 3 views
  • Added November 15, 2026
ai-agents

Security analysis

A100/100

Scanned November 15, 2026

npx -y skills add workspace-templates/ai-agent-templates --skill extract-function --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Extract Function?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Extract Function
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/workspace-templates-extract-function-ai-agent-templates/badge)](https://www.skillsdirectory.com/skills/workspace-templates-extract-function-ai-agent-templates)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: extract-function
description: Pulls a block of code into a well-named function with few parameters, updates the callers and checks nothing else changed.
disable-model-invocation: true
---

Extract a function from: $ARGUMENTS

1. Read the surrounding function. Identify the block and mark every variable it reads (becomes a parameter), writes (becomes a return value) and any side effect (I/O, mutation, logging).
2. Reject the extraction if the block exits the outer function (early return, break, throw) in several ways and the result would need flags. Explain and suggest a different boundary.
3. Choose a verb-noun name that describes the purpose, not the steps. Keep parameters to three or fewer; group related ones into an object only if they already travel together.
4. Prefer a pure function. If it must touch state, keep that visible in the signature.
5. Place it near its only caller if private, or in the right shared module if two places use it. Match the file's style and add types or docstrings as neighbors do.
6. Replace the original block, and replace duplicates elsewhere only when they are truly identical.
7. Run tests and the type check. Add a direct test for the new function when it has logic.

Show the new function and the changed call site. Ask before touching duplicates in other files.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.