thinkhard.SI

Prompt repository Engineering & code

Brief a coding agent to split a large file into modules with tests passing at each step

One file in your codebase has grown too big, and you want a coding agent to split it into modules in small steps that change no behavior.

Registry no.
ENG-052
Collection
Engineering & code
Laid out for
Coding agent
Score
10 out of 10
Blanks to fill
6

Engineering & codeCode agent

The prompt

Score 10 of 10, Excellent

Use it when One file in your codebase has grown too big, and you want a coding agent to split it into modules in small steps that change no behavior.

  • {{file_path}}
  • {{problems}}
  • {{proposed_grouping}}
  • {{test_command}}
  • {{check_commands}}
  • {{commit_rule}}
Full prompt and why it works
Prompt
Goal: Split {{file_path}} into smaller modules, so that each part has one job and can be read and changed on its own, while nothing outside the file has to change and the tests pass after every step.

Context:
- Why the file is hard to work with: {{problems}}
- How I would group it, if I have a view: {{proposed_grouping}}
- Test command: {{test_command}}
- Lint and type check commands, if any: {{check_commands}}
- Commits: {{commit_rule}}

Step 1, plan before editing. Read the file, list its top-level functions, classes, constants and types, and search the codebase for every place that imports each one. Then reply with a plan: the new modules and their names (for example helpers.py split into dates.py and money.py), which symbols go where, the order of moves, and any risk of circular imports. Wait for my go-ahead before moving anything.

Step 2, move in small steps, one group of symbols per step:
- Move code exactly as it is. Change only import lines, never the body of a function or its signature.
- Keep the original file importing and re-exporting every moved symbol, so existing imports elsewhere keep working.
- Run the tests and the checks after every step. If anything fails, undo that step and tell me why before trying again.

Constraints:
- Do not rename, reformat, fix or improve anything during the split. Note what you would change and leave it for a separate task.
- Do not edit or delete tests to make them pass.
- Stop and ask if a group shares module-level state with code that is staying, such as a global variable, a cache, a singleton or code that runs on import, because moving it can change behavior.

Done when:
- {{test_command}} and the checks pass after the final step, with the same tests as before.
- The original file contains only the re-exports, or what we agreed stays there.
- There are no new circular imports.
- git diff shows moved code and changed import lines, and nothing else.

Report in this format: each step with the symbols moved and its test result, the final layout with each module's job in one line, the commands you ran, and anything you noticed but left alone. Verify the last step by running the full test command and including the last 20 lines of its output.

Variables

{{file_path}}
The file to split, for example "app/services/orders.py" or "src/utils.ts".
{{problems}}
What makes it hard to work with, for example "2,400 lines with pricing, emails, exports and reports all mixed together".
{{proposed_grouping}}
Your idea of the modules, for example "pricing, notifications, exports and reports", or "no view, propose one".
{{test_command}}
How tests run, for example "pytest" or "npm test".
{{check_commands}}
Lint and type check commands, for example "ruff check . and mypy app", or "none".
{{commit_rule}}
Whether to commit, for example "one commit per step" or "do not commit, leave changes for me to review".

Why it works

  • If unsure. A plan comes back before any code moves, and shared module-level state stops the work, since that is where a pure move can change behavior.
  • What to avoid. Code moves exactly as it is, with re-exports left in place, so the diff is moves and imports only and nothing outside the file has to change.
  • What good looks like. Tests and checks run after every step and a failing step is undone, so any break points to one move.

How to use it

  1. Press Fill in blanks and type your details into each blank. What you type stays in this browser.
  2. Copy the filled prompt into the AI tool you already use, such as ChatGPT, Claude or Gemini, or open it in the Grader or the Prompt Tester here.
  3. Before you rely on it, try it on three or four real examples. The Prompt Tester runs them all at once and shows which ones go wrong.
Use it from code

Get this prompt as JSON from the free REST API, with your own text in the blanks, or let an AI assistant fetch it through the MCP server. No key.

curl -s https://thinkhard.si/api/v1/prompts/coding-agent-split-large-file

With the MCP server added to Claude, ChatGPT, Cursor or VS Code, call get_prompt with {"prompt": "coding-agent-split-large-file"}, or just ask for it by name.