mcp-memory-service: Command for Claude Code

.claude/commands/refactor-function.md

refactor-function is a command for Claude Code from doobidoo/mcp-memory-service. It costs 0 tokens per session (1,588 once invoked), scanned A, original, Apache-2.0.

A command that simplifies a selected function by measuring its complexity and applying common code-organization changes.

In plain words
What is it for?
Use it to split large functions into helpers, reduce nesting, replace long condition chains, and move repeated text into constants.
Why use it?
It reduces deeply nested or hard-to-maintain code and shows the proposed changes before they are applied.

Command for Claude Code

Written for Claude Code: installed under .claude/. Also seen: reads .claude/ paths.

This is doobidoo/mcp-memory-service's own configuration. It tells Claude Code how to work on mcp-memory-service itself, so it is not a mod to install elsewhere. Copy it as a starting point and replace the rules that are about this project. Everything mcp-memory-service configures →

About the project

mcp-memory-service is a self-hosted memory backend that lets AI agents store and retrieve shared project context through REST, MCP, OAuth, a command-line interface, and a dashboard. It is intended for agent pipelines and clients such as LangGraph, CrewAI, AutoGen, Claude Desktop, and OpenCode, with support for knowledge graphs and memory consolidation. The catalogue includes skills, agents, commands, instructions, hooks, a setting, an MCP entry, and a plugin for its workflows.

doobidoo/mcp-memory-service · 2,021 stars · on GitHub

Reuse

Borrowing it

Nothing to install: this file belongs to doobidoo/mcp-memory-service. Take a copy, put it at the same path in your own repository, and replace the rules that are about this project with yours.

Copy the file
curl -O https://raw.githubusercontent.com/doobidoo/mcp-memory-service/main/.claude/commands/refactor-function.md
Clone the repo
git clone --depth 1 https://github.com/doobidoo/mcp-memory-service

Made for: Claude Code.

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 refactor-function

README.md
[![agentmods](https://agentmods.dev/badge/commands/doobidoo/mcp-memory-service/refactor-function/github.svg)](https://agentmods.dev/commands/doobidoo/mcp-memory-service/refactor-function)
Your own site
<a href="https://agentmods.dev/commands/doobidoo/mcp-memory-service/refactor-function"><img src="https://agentmods.dev/badge/commands/doobidoo/mcp-memory-service/refactor-function/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for refactor-function

Your own site · 80×15
<a href="https://agentmods.dev/commands/doobidoo/mcp-memory-service/refactor-function"><img src="https://agentmods.dev/badge/commands/doobidoo/mcp-memory-service/refactor-function.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,588 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.00000 $0.01588
Opus 5.5 $0.00000 $0.00635
Sonnet 5.5 $0.00000 $0.00318
Haiku 4.5 $0.00000 $0.00159

Measured 1mo ago against content hash 3b66847514b5, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

refactor-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 1mo 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.

.claude/commands/refactor-function.md · 273 lines

How it starts

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

/refactor-function Command

Automated function complexity reduction using multi-agent workflow.

Usage

# In editor, select a function and run:
/refactor-function

# With options:
/refactor-function --target-complexity 6 --max-helpers 3
/refactor-function --pattern extract-method
/refactor-function --dry-run  # Show plan without applying

Workflow

1. Context Extraction

  • Detect selected function or function at cursor
  • Extract function signature, body, surrounding context
  • Parse imports and dependencies

2. Baseline Analysis (code-quality-guard)

- Measure current complexity
- Identify nesting depth
- Count boolean operators
- Calculate maintainability index
- Generate refactoring targets

3. Refactoring (amp-bridge)

- Apply Extract Method pattern
- Create helper functions
- Reduce nesting with early returns
- Replace if-elif chains with dictionaries
- Extract magic strings to constants

4. Validation (code-quality-guard)

- Measure new complexity
- Verify targets met
- Check for regressions
- Generate diff report

5. User Review

Before:
  Function: parse_output
  Complexity: 12 (C-grade)
  Nesting: 5 levels

After:
  Main: parse_output (C=6, B-grade)
  Helpers:
    - _parse_field (C=4, A-grade)
    - _validate_output (C=3, A-grade)

Apply changes? [y/n]

6. Optional Commit

If applied, offer to commit:
  "refactor: Reduce complexity in <function_name>

  - Complexity: C=12→6 (-50%)
  - Extracted N helpers (avg C=X)
  - Pattern: Extract Method"

Options

Option Description Default
--target-complexity Target cyclomatic complexity 6
--max-helpers Max helper functions to create 5
--pattern Refactoring pattern extract-method
--dry-run Show plan without applying false
--auto-commit Commit if successful false
--scope Scope (function|class|file) function

Patterns Supported

Read the full file on GitHub · 273 lines

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. 1mo ago First seen · 273 lines · 0 tokens per session scan A 3b66847514b5

Subscribe to this mod's changes

refactor-function is a command published in the GitHub repository doobidoo/mcp-memory-service (2,021 stars, last pushed yesterday), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 1,588 tokens. 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 commands, from other repositories

setup-context

Set up your Skill Memory — a pm-context.md every skill reads so outputs come back tailored to you.

mohitagw15856/pm-claude-skills · 21 tokens

perf-difficult-conversation

Three-conversations framework rehearsal (Stone/Patton/Heen — Harvard Negotiation Project) for high-stakes conversations — termination, demotion, hard feedback, conflict surfacing. Produces three-conversations breakdown (what-happened / feelings / identity), conversation script with multiple opening choices, SCARF…

frankxai/Starlight-Intelligence-System · 93 tokens

culture-onboarding-90

Design a 90-day onboarding architecture for a role. First day (psychological safety + belonging activation), first week (relationship + role context + early wins), first month (skill ramp + integration + baseline), first quarter (autonomous performance + cultural integration check). Written-first elements for…

frankxai/Starlight-Intelligence-System · 101 tokens

reclaim-knowledge

Organize scattered professional material into a domain-based second-brain architecture. Maps existing sources (Canva, Drive, local folders, Notion, screenshots) to functional domains. Non-technical-friendly — produces folder structure + drag-and-drop instructions, not CLI commands.

frankxai/Starlight-Intelligence-System · 58 tokens

discover-genius

Excavate genius from a person's scattered corpus. Produces Genius Profile (what only they uniquely see) + Freedom Path (four-bucket sort of every activity). Gateway to all downstream intelligence systems. For humans, not agents.

frankxai/Starlight-Intelligence-System · 49 tokens

orchestrate-brain

Weekly 30-minute second-brain review ritual. Orchestrates inbox clear, lightweight distillation, vault maintenance, cross-reference pass, and next-week capture focus. The compounding rhythm that keeps the system alive.

frankxai/Starlight-Intelligence-System · 49 tokens