lsp-extract-function

lsp-extract-function is a skill for Claude Code, Codex from blackwell-systems/agent-lsp. It costs 54 tokens per session (1,897 once invoked), scanned A, original, MIT.

A code-refactoring tool that moves an existing block of code into a newly named function, using a language server when available.

In plain words
What is it for?
It helps split large functions into smaller ones and checks captured variables, naming conflicts, and compilation during the extraction.
Why use it?
It reduces the risk of missing variables, changing scope incorrectly, or leaving code that no longer compiles after the move.

Skill for Claude CodeCodex

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.

agentmods
npx agentmods add skills/blackwell-systems/agent-lsp/lsp-extract-function
Any agent
npx skills add blackwell-systems/agent-lsp --skill lsp-extract-function
Clone the repo
git clone --depth 1 https://github.com/blackwell-systems/agent-lsp

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 lsp-extract-function

README.md
[![agentmods](https://agentmods.dev/badge/skills/blackwell-systems/agent-lsp/lsp-extract-function.svg)](https://agentmods.dev/skills/blackwell-systems/agent-lsp/lsp-extract-function)
Your own site
<a href="https://agentmods.dev/skills/blackwell-systems/agent-lsp/lsp-extract-function"><img src="https://agentmods.dev/badge/skills/blackwell-systems/agent-lsp/lsp-extract-function.svg" alt="Measured on agentmods" height="20"></a>
Per session 54 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,897 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
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.00054 $0.01897
Opus 5 $0.00027 $0.00949
Sonnet 5 $0.00011 $0.00379
Haiku 4.5 $0.00005 $0.00190

Measured 5d ago against content hash 72c3dcca12f7, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-05, from the pricing page.

Security

Grade A, and why

lsp-extract-function 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 5d 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/lsp-extract-function/SKILL.md · 242 lines

How it starts

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

Requires the agent-lsp MCP server.

lsp-extract-function: Extract Code Block into a Named Function

This skill RESTRUCTURES existing code — it takes code that already exists and moves it into a new function. This is distinct from /lsp-generate, which creates NEW code that does not yet exist (stubs, mocks, interface implementations). Use this skill when the code is already written; use /lsp-generate when you need to generate code from scratch.

Invocation: User provides file_path (absolute path), start_line and end_line (1-indexed range), and new_function_name (desired name for the extracted function).


Prerequisites

If LSP is not yet initialized, call mcp__lsp__start_lsp with the workspace root first. Auto-inference applies when file paths are provided, but an explicit start is required when switching workspaces.


Step 1 — Get context (document symbols)

Call mcp__lsp__open_document to open the file, then call mcp__lsp__list_symbols to understand the containing function and scope:

mcp__lsp__open_document({ "file_path": "<file_path>" })
mcp__lsp__list_symbols({ "file_path": "<file_path>" })

This establishes:

  • Which function contains the selection
  • Whether new_function_name already exists in the file (name collision check)

Mandatory name collision check: If new_function_name already exists as a symbol in the document symbols list, report the conflict and stop immediately:

Cannot extract: function new_function_name already exists in this file. Choose a different name and retry.


Step 2 — Check server capabilities

Call mcp__lsp__get_server_capabilities to understand what the language server supports:

mcp__lsp__get_server_capabilities({})

Check for codeActionProvider in the response. Note whether execute_command is listed in executeCommandProvider.commands. This determines whether the primary path (Step 3) is available.


Step 3 — Primary path: LSP code action

Call mcp__lsp__suggest_fixes with the selection range:

Read the full file on GitHub · 242 lines

Files

What ships with it

1 file 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. 5d ago First seen · 242 lines · 54 tokens per session scan A 72c3dcca12f7

Subscribe to this mod's changes

lsp-extract-function is a skill published in the GitHub repository blackwell-systems/agent-lsp (121 stars, last pushed today), licensed MIT. It adds 54 tokens to every session and 1,897 once invoked, about $0.0003 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-30.

Related

Other skills, from other repositories

authoring-schemas

Author a mache projection schema (Topology→Node→Leaf) that maps structured data or source code into a filesystem/graph. Use when creating or debugging a -schema.json for a new data source (SQLite/JSON) or a new source language. Covers both dialects — tree-sitter S-expression selectors for code, and JSONPath selectors…

agentic-research/mache · 111 tokens

authoring-smell-rules

Add a findsmells rule to mache — a SQL query over the projected code graph that surfaces a code smell (duplication, complexity, dead code, drift). Use when adding or debugging a SmellRule in cmd/smellrules.go or an external $MACHESMELLRULESDIR rule. Covers the SmellRule struct, the standalone-vs-ast table capability…

agentic-research/mache · 102 tokens

mache-explore

Mount a mache FUSE filesystem inside the project directory so agents can explore structured data without per-file permission prompts.

agentic-research/mache · 27 tokens

analyze-usage

Use when asked to analyze codescout tool usage, check for error patterns, audit tool health, generate a usage report, spot anti-patterns, or clear usage statistics to start fresh.

mareurs/codescout · 42 tokens

code-intelligence

Universal, safe, and professional code modification and refactoring environment for 50+ languages. Use when editing source files to prevent syntax breakage, perform project-wide type-aware renames (LSP), or distill large command output to save context window tokens.

naranor/code-intelligence-skill · 58 tokens

claude

Skill "claude" from paladini/locus-mcp, covering claude code skill (stub), when to use locus, when to use grep, mcp registration and status.

paladini/locus-mcp · 0 tokens