segregate-functional-core

segregate-functional-core is a skill for Claude Code from msbaek/msbaek-claude-plugins. It costs 124 tokens per session (3,832 once invoked), scanned A, original, MIT.

A refactoring method that separates input and output work from calculations. The separated calculation part can run without outside effects, while the surrounding part handles those effects.

In plain words
What is it for?
Use it to split methods that read or write outside data from methods that calculate results, including methods that mix mock stubs with calculations.
Why use it?
Mixing external actions, test doubles, and calculations makes code harder to test and change.

Skill for Claude Code

Written for Claude Code: argument-hint in frontmatter.

Part of the msbaek-tdd plugin — 28 skills, 10 agents, 2 hooks shipped together

Good fit Use it to split methods that read or write outside data from methods that calculate results, including methods that mix mock stubs with calculations.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/msbaek/msbaek-claude-plugins/segregate-functional-core
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.

Any agent
npx skills add msbaek/msbaek-claude-plugins --skill segregate-functional-core
Clone the repo
git clone --depth 1 https://github.com/msbaek/msbaek-claude-plugins

Made for: Claude Code.

Or install msbaek-tdd, the plugin that ships this one along with the rest of its 28 skills, 10 agents, 2 hooks.

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 segregate-functional-core

README.md
[![agentmods](https://agentmods.dev/badge/skills/msbaek/msbaek-claude-plugins/segregate-functional-core/github.svg)](https://agentmods.dev/skills/msbaek/msbaek-claude-plugins/segregate-functional-core)
Your own site
<a href="https://agentmods.dev/skills/msbaek/msbaek-claude-plugins/segregate-functional-core"><img src="https://agentmods.dev/badge/skills/msbaek/msbaek-claude-plugins/segregate-functional-core/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 segregate-functional-core

Your own site · 80×15
<a href="https://agentmods.dev/skills/msbaek/msbaek-claude-plugins/segregate-functional-core"><img src="https://agentmods.dev/badge/skills/msbaek/msbaek-claude-plugins/segregate-functional-core.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 124 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 3,832 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.00124 $0.03832
Opus 5.5 $0.00050 $0.01533
Sonnet 5.5 $0.00025 $0.00766
Haiku 4.5 $0.00012 $0.00383

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

Security

Grade A, and why

segregate-functional-core 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 2mo 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.

msbaek-tdd/skills/segregate-functional-core/SKILL.md · 340 lines

How it starts

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

Segregate Functional Core Skill

I/O 호출이나 Mock collaborator 호출과 순수 계산이 혼재된 메서드를 Impure-Pure-Impure Sandwich(빵속빵) 구조로 분리. Functional Core(순수 로직)와 Imperative Shell(I/O)이 나뉘어 테스트 용이성과 가독성 향상.

GOAL

  • 성공 = I/O/Mock과 계산이 혼재된 메서드가 Functional Core와 Imperative Shell로 분리되어 커밋 완료됨
  • T1(I/O + 계산 혼재) 또는 T2(Mock stub + 계산 혼재) smell 식별
  • Functional Core는 순수 함수로 추출 (입력만 받고 결정/instruction 반환)
  • Imperative Shell은 I/O만 담당 (read → pure → write 순서)
  • Functional Core 테스트는 mock 없이 값 기반으로 작성
  • 모든 기존 테스트 통과

CONSTRAINTS

  • 계열: System-wide — 후보 제시 후 승인 받고 적용 (../../references/refactoring-procedure.md §0·§3-B)

Hard Rules

  • 동작 변경 금지 — 구조 개선만 수행
  • 테스트 수정 금지 — 기존 테스트는 그대로 통과해야 함 (Functional Core 테스트는 추가)
  • 사용자 확인 없이 리팩토링 금지 — 모든 후보는 사용자 승인 후 실행
  • 커밋 단위 — 1파일 x 1기법 = 1커밋 (Shell/Core/새 테스트는 논리적으로 함께 커밋)
  • git add -A 금지 — 변경된 파일만 명시적으로 추가

Functional Core / Imperative Shell 원칙

  • Functional Core: 순수 함수. I/O 호출 없음. mutation 없음. 같은 입력 → 같은 출력
  • Imperative Shell: I/O만 담당 (DB, 파일, 네트워크, 시스템 시간). Functional Core에 데이터를 제공하고, 리턴된 instruction/결정을 실행
  • 구조: Impure(read) → Pure(decide) → Impure(write) — 샌드위치의 빵-속-빵
  • DDD Trilemma: 도메인 모델을 완전한 불변으로 만드는 비용이 지나치게 크면 Mutable Shell 수용. 순수성·완전성·성능 중 둘만 동시 만족 가능

적용 패턴

Segregate Functional Core 리팩토링 단계:

  1. 필요 데이터 식별 — Functional Core가 판단에 필요한 모든 입력을 목록화
  2. 데이터 사전 로드 — Imperative Shell이 함수 시작 전 필요한 데이터를 모두 읽어옴
  3. Functional Core 추출 — 파라미터로 데이터를 받고, 판단 결과 또는 Instruction 객체를 반환하는 순수 static 함수로 추출
  4. Imperative Shell 수렴 — 호출자를 read → pure → write 순서로 재배치
  5. Functional Core 테스트 추가 — Mock 없이 값 기반 테스트로 작성

Before/After 예시 (감사 로그 서비스)

출처: Vladimir Khorikov 『단위 테스트』 + Mark Seemann "Impureim Sandwich"

// Before: I/O + 계산 혼재 (T1) + Mock-heavy test (T2)
public class AuditService {
    private final FilePersister filePersister;  // mock 대상
    private final int maxEntries;

    public AuditService(FilePersister filePersister, int maxEntries) {
        this.filePersister = filePersister;
        this.maxEntries = maxEntries;
    }

    // T1: 읽기(I/O) + 판단(계산) + 쓰기(I/O) 혼재
    public void addRecord(String name, LocalDateTime timestamp) {
        List<Path> files = filePersister.listAuditFiles();            // I/O
        Path current = files.isEmpty() ? null : files.get(files.size() - 1);

        int count = current == null
                ? 0
                : filePersister.readLines(current).size();            // I/O

        String entry = name + ";" + timestamp.toString();

        if (current == null || count >= maxEntries) {                 // 계산
            Path newFile = Paths.get("audit_" + (files.size() + 1) + ".txt");
            filePersister.writeLines(newFile, List.of(entry));        // I/O
        } else {
            filePersister.appendLine(current, entry);                 // I/O
        }
    }
}

// T2: 테스트에서 mock stub이 다수 필요
class AuditServiceTest {
    @Mock FilePersister persister;

    @Test void addRecord_new_file_when_max_entries_reached() {
        when(persister.listAuditFiles())
            .thenReturn(List.of(Paths.get("audit_1.txt")));            // stub 1
        when(persister.readLines(any()))
            .thenReturn(List.of("a;...", "b;...", "c;..."));           // stub 2
        doNothing().when(persister).writeLines(any(), any());          // stub 3
        // ...

        new AuditService(persister, 3).addRecord("d", NOW);

        verify(persister).writeLines(any(), any());                    // verify 1
    }
}

Read the full file on GitHub · 340 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. 2mo ago Changed · +1 lines · +67 tokens per session 2245ee541b46
  2. 2mo ago Changed 75b54cf45fd2
  3. 3mo ago First seen · 339 lines · 57 tokens per session scan A 216a13d1ce8f

Subscribe to this mod's changes

segregate-functional-core is a skill published in the GitHub repository msbaek/msbaek-claude-plugins (8 stars, last pushed 1mo ago), licensed MIT. It adds 124 tokens to every session and 3,832 once invoked, about $0.0005 per session on Opus 5.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-31.

Related

segregate-functional-core compared with skills from other repositories

segregate-functional-core next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
segregate-functional-coremsbaek/msbaek-claude-pluginsSkill81mo agoMITA124Claude Code
systematic-debuggingopen-metadata/OpenMetadataSkill16ktodayApache-2.0A37Claude Code
log-error-digestzebbern/claude-code-guideSkill4.7ktodayMITA71Claude Code, Codex
observability-audit-sessionsIBM/mcp-context-forgeSkill4.9ktodayApache-2.0A64Claude Code, Codex
cwv-optimizeradobe/skillsSkill343todayApache-2.0A112Claude Code
performance-verificationvalkor-ai/loomSkill1.6k3d agoApache-2.0A45Claude Code, Codex
loop-engineeringhuytieu/COG-second-brainSkill1.6kyesterdayMITA63Claude Code