cognitive-refactor

cognitive-refactor is a skill for Claude Code, Codex from luabagg/agent-skills. It costs 72 tokens per session (2,889 once invoked), scanned A, original, MIT.

A code-restructuring guide focused on making functions and modules easier to follow by reducing complexity and clarifying names and contracts.

In plain words
What is it for?
Use it to split complex loops and functions into clear stages and helpers, improve naming, and define clearer module or function contracts.
Why use it?
It addresses code that is hard to understand because of too many branches, long functions, unclear terms, or poorly separated responsibilities.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it to split complex loops and functions into clear stages and helpers, improve naming, and define clearer module or function contracts.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/luabagg/agent-skills/cognitive-refactor
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 luabagg/agent-skills --skill cognitive-refactor
Clone the repo
git clone --depth 1 https://github.com/luabagg/agent-skills

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

README.md
[![agentmods](https://agentmods.dev/badge/skills/luabagg/agent-skills/cognitive-refactor/github.svg)](https://agentmods.dev/skills/luabagg/agent-skills/cognitive-refactor)
Your own site
<a href="https://agentmods.dev/skills/luabagg/agent-skills/cognitive-refactor"><img src="https://agentmods.dev/badge/skills/luabagg/agent-skills/cognitive-refactor/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 cognitive-refactor

Your own site · 80×15
<a href="https://agentmods.dev/skills/luabagg/agent-skills/cognitive-refactor"><img src="https://agentmods.dev/badge/skills/luabagg/agent-skills/cognitive-refactor.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 72 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 2,889 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.00072 $0.02889
Opus 5.5 $0.00029 $0.01156
Sonnet 5.5 $0.00014 $0.00578
Haiku 4.5 $0.00007 $0.00289

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

Security

Grade A, and why

cognitive-refactor 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.

skills/cognitive-refactor/SKILL.md · 221 lines

How it starts

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

Cognitive Refactor

A complexity score counts branches. A reader counts the places they must open to answer one question: functions, files, and conditions they must hold in mind. Refactor to reduce the places. A change that lowers the score and adds places is a regression.

Control flow

  1. Handle each special case first, and return or throw at once. The main path then runs without nesting.
  2. When a function picks one of several outcomes, each branch returns its outcome. Do not write else or else if after a branch that returns.
  3. When every branch tests one value, use a switch on it. Give a switch on a union a default that assigns the value to never, so a new member fails to compile.
  4. Keep nesting to two levels. Deeper code needs a guard clause or an extracted function.
  5. Write the positive case: if (isPosted), not if (!isUnposted). Put a long condition in a named boolean first.
// Wrong: the fee travels through three levels before it returns.
function shippingFeeCents(order: Order): number {
  let fee = 0
  if (order.items.length > 0) {
    if (order.country === "BR") {
      if (order.totalCents < FREE_SHIPPING_MINIMUM_CENTS) {
        fee = DOMESTIC_FEE_CENTS
      }
    } else {
      fee = INTERNATIONAL_FEE_CENTS
    }
  }
  return fee
}

// Right: each case returns where it is decided.
function shippingFeeCents(order: Order): number {
  if (order.items.length === 0) return 0
  if (order.country !== "BR") return INTERNATIONAL_FEE_CENTS
  if (order.totalCents >= FREE_SHIPPING_MINIMUM_CENTS) return 0
  return DOMESTIC_FEE_CENTS
}

One unit, one job

A function, a task, or a module does one job. Two steps of one action are one job: signInAndSaveSession.

These are the signs of two jobs:

  • The name hides one of the effects, or joins two unrelated effects with "and".
  • One job has a risk or a cost the other does not have, such as an email sent, money charged, or an account changed.
  • A parameter serves only one field of the result. loadAvailityClaimStatusPollingCounts(name, since) returned { openNow, cappedSince }, and only cappedSince used since. Split it into one count per question.
  • A decision and its writes sit in one function.

Read the full file on GitHub · 221 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 Changed · +94 lines · +17 tokens per session 266679097059
  2. 2mo ago Changed · -6 tokens per session ae27e2dca9cf
  3. 2mo ago Changed · +56 lines c6329841206f
  4. 2mo ago First seen · 71 lines · 61 tokens per session scan A 8de0e2a54904

Subscribe to this mod's changes

cognitive-refactor is a skill published in the GitHub repository luabagg/agent-skills (3 stars, last pushed 4d ago), licensed MIT. It adds 72 tokens to every session and 2,889 once invoked, about $0.0003 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-09-11.

Related

cognitive-refactor compared with skills from other repositories

cognitive-refactor next to 6 skills from other repositories
ModTypeStarsLast pushLicenceScanTokensWorks with
cognitive-refactorluabagg/agent-skillsSkill34d agoMITA72Claude Code, Codex
mmx.errors-cheatsheetjavimosch/supercliSkill585d agoMITA29Claude Code, Codex
gardenharness-mini/harness-miniSkill7yesterdayMITA60Claude Code, Codex
generator-apply-fixesredker56/auto-harnessSkill157mo agoMITA36Claude Code
gke-workload-scaling-troubleshootinggoogle/skillsSkill25ktodayApache-2.0A170Claude Code, Codex
gke-ai-troubleshooting-jobset-interruptiongoogle/skillsSkill25ktodayApache-2.0A83Claude Code, Codex
bigquery-troubleshootinggoogle/skillsSkill25ktodayApache-2.0A140Claude Code, Codex