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
.claude/commands/09_typescript_refactor.mdWhat 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_refactoron this TypeScript function and explain the changes. - Make this function easier to read with
/09_typescript_refactor. - Use
/09_typescript_refactorto rewrite the function that groups active items.
How to install 09_typescript_refactor
Manually: put the files in place
.claude/commands/09_typescript_refactor.mdHow to use
Paste the text at the start of a chat or into project instructions
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