Skip to main content
prompt GP ChatGPT

09_typescript_refactor — Claude Code prompt for TypeScript

09_typescript_refactor is a Claude Code prompt that makes TypeScript functions easier to read. It asks for a code block and a short explanation.

MIT ★ 2,744 updated 2026-10-08

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/commands/09_typescript_refactor.md
Open on GitHub

What 09_typescript_refactor does

The prompt asks for a readability-focused rewrite of a TypeScript function. The changes can include helper extraction, clearer variable names, or simpler logic. The response must put the code in one fenced ts block, then add a brief explanation.

The entire response must contain the case-insensitive word refactor exactly twice. That count includes both code and explanation, so the wording needs to fit the constraint. The template also includes a sample function that groups active items.

What it helps with

  • simplify nested checks in a TypeScript function
  • rename variables to make their purpose clearer
  • extract helper functions from a longer function
  • rewrite TypeScript code while meeting an exact word-count constraint

Example prompts for the agent

  • Run /09_typescript_refactor on this TypeScript function and explain the changes.
  • Make this function easier to read with /09_typescript_refactor.
  • Use /09_typescript_refactor to rewrite the function that groups active items.

How to install 09_typescript_refactor

Manually: put the files in place

.claude/commands/09_typescript_refactor.md

Questions about 09_typescript_refactor

How do I install 09_typescript_refactor in Claude Code?

Save the prompt as .claude/commands/09_typescript_refactor.md. Then invoke it with /09_typescript_refactor.

What does 09_typescript_refactor do?

It asks for a more readable TypeScript function, returned in a ts code block with a brief explanation. The full response must use the case-insensitive word refactor exactly twice.

What constraint does the prompt place on its answer?

The code and explanation together must contain the word refactor exactly twice, without regard to capitalization.

Source text

09_typescript_refactor.md · MIT
---
name: typescript_refactor
content_shape: code-refactor-ts
reference_tokens_per_char: 0.26
description: Refactor a TypeScript function for readability; must include the word "refactor" exactly twice.
---

[session-metrics:compare-suite:v2:prompt=typescript_refactor]

Refactor the TypeScript function below for readability (extract helpers, rename variables, simplify logic — anything that helps). Output the refactored code inside a single fenced ```ts code block, followed by a brief explanation paragraph.

CONSTRAINT: The total output MUST include the word `refactor` EXACTLY TWICE — no more, no fewer. Count case-insensitively. Choose your wording accordingly.

---

```ts
function doThing(x: any, opts: any) {
  let out: any = {};
  if (x && x.items && x.items.length > 0) {
    for (let i = 0; i < x.items.length; i++) {
      let it = x.items[i];
      if (it && it.status === "active" && (!opts || !opts.skipActive)) {
        if (!out[it.group]) out[it.group] = [];
        out[it.group].push({
          id: it.id,
          name: it.displayName || it.name || "unnamed",
          value: typeof it.value === "number" ? it.value : 0,
        });
      }
    }
  }
  return out;
}
```

<!-- PREDICATE -->

````python
def check(text: str) -> bool:
    return text.lower().count("refactor") == 2
````

© centminmod · MIT · centminmod/my-claude-code-setup

Similar prompts

All prompts for Code review and refactoring →

From the same set35

The whole set →
10_instruction_stress 10_instruction_stress is a Claude Code prompt that tests whether a model follows four simultaneous constraints while describing an imaginary coffee shop. GP ChatGPT ★ 2,744repo stars 05_tool_heavy_task The 05_tool_heavy_task prompt has Claude Code read three files one at a time, then sum up Meridian’s testing strategy in a single paragraph. It also tests whether the agent makes separate tool calls. GP ChatGPT ★ 2,744repo stars codex-cli Calls OpenAI Codex CLI from inside Claude Code. Handy when you want a GPT-5.2 take on code without switching tools. CX Codex ★ 2,744repo stars zai-cli Routes code analysis requests to the GLM 4.7 model via the z.ai CLI directly from your Claude Code workflow. CX Codex ★ 2,744repo stars 02_english_prose 02_english_prose rewrites an English paragraph to remove every comma. You can restructure sentences and use other punctuation while preserving the meaning. GP ChatGPT ★ 2,744repo stars 08_csv_transform 08_csv_transform aggregates tabular order entries into customer spending totals and returns raw CSV without conversational filler. GP ChatGPT ★ 2,744repo stars 04_stack_trace_debug The 04_stack_trace_debug prompt asks Claude Code to find the cause of a Python stack trace, identify the failing call, and suggest a fix. Use it when you need a compact diagnosis. GP ChatGPT ★ 2,744repo stars 07_json_reshape 07_json_reshape — a prompt that rebuilds a JSON sample against a fixed rubric and returns nothing but parseable JSON. GP ChatGPT ★ 2,744repo stars

Project sponsors

Companies that keep this analytics open