Skip to content

Instantly share code, notes, and snippets.

@graffhyrum
Created August 29, 2025 23:34
Show Gist options
  • Select an option

  • Save graffhyrum/dbe254f97f12e41d36a69afa73169b90 to your computer and use it in GitHub Desktop.

Select an option

Save graffhyrum/dbe254f97f12e41d36a69afa73169b90 to your computer and use it in GitHub Desktop.
LLM prompt to apply some of my most-used cleanups to a file.

This is a prompt I use often to improve readability of a module. With something like Claude custom slash commands you can map these to an alias for easy use.

Prompt:
Analyze this code in the context of the following rules and apply appropriate refactoring.

Summary:
The goal of these rules is to improve readability within a file. 
It is highly valuable to start at the top of the abstraction hierarchy 
and descend the hierarchy as you read top to bottom.

Rules:
- Decompose all functions into sub-functions until the function body is four lines or less, or you cannot meaningfully extract anymore.
- If a sub-function is only called once, nest it at the bottom of the innermost calling function.
- Use named functions unless there is a strong benefit to using arrow functions or an IIFE.
- Organize code within a file such that function and method declarations are below ALL of their call sites. (stepdown rule).
- If a function has subfunctions inside it, they should be below the return statement(s)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment