Port code to another language

Have Claude Code port a module to another language while keeping the API and behavior you name, with the tests ported and run against the new code.

Task: Port code to another language · Other tasks

Fill in the details

A file, module or package. In Claude Code you can type @ to reference it.

Optional. Where the code goes, libraries to use or avoid, error handling style.

Optional. Leave empty and Claude will find how the project runs tests in that language.

Copy your prompt

This site doesn't run Claude or show model output. Results depend on your input and the model you use.

3 required fields are empty.

What you type is kept in this tab's session storage so a reload doesn't lose it. Use "Clear this task" to remove it. Browsers can restore session data when they reopen tabs, so closing a tab isn't a guaranteed way to erase it.

When to use this template

  • A module needs to move to another language, for speed, for a shared runtime, or because the rest of the system has moved, and its behavior must not change on the way.
  • The original code has tests, so there is something concrete to port alongside it and run against the new version.
  • You know the target language less well than the source and want an idiomatic result, with the places where the languages differ called out for you.

When not to use it

  • You want to move a whole codebase at once. Port it module by module, using this template for each piece, and plan the order first.
  • The original code has no tests and its behavior is not written down anywhere. Add tests first with the write and run tests template, or the port has nothing to be checked against.
  • The goal is to redesign the module as well. Changing the language and the design in one step makes it hard to tell which change caused a difference; port first, then refactor.

Why this structure

  • The opening line names what must stay the same, not only the target language. That turns "port it" into something Claude can check the result against.
  • Step 1 asks for the list of what must be preserved before any code is written. You can add a forgotten case or correct a misreading while it is still cheap.
  • Step 2 brings the hard parts forward. Differences in typing, errors and number handling are where ports change behavior quietly, so Claude has to name them and ask where it matters.
  • Porting the tests and running them in step 4, with your command when you give one, gives Claude a pass or fail check and a reason to keep going until the new code behaves like the old.
  • Step 5 keeps the change additive. The original stays in place and callers are untouched, so you can compare both versions and switch over when you are ready.
  • The closing table maps each public item to its port, which makes gaps easy to see in review.

Example input (fictional)

Code to port
the Python module billing/invoice.py
Target language
Rust
What must stay the same
public API and test behavior
Constraints for the new code
Put it in the existing crate under rust/billing. Return errors as Result values and never panic on bad input. Use rust_decimal for money.
Command that runs the ported tests
cargo test -p billing

Follow-ups to send Claude

  • Run the original tests and the ported tests on the same inputs and list any case where the results differ.
  • Which parts of the port are least idiomatic for this language? Rewrite them and keep the tests passing.
  • Plan how to switch callers from the old module to the port in small steps, without changing anything yet.

Common mistakes

  • Naming only the target language. Without a statement of what must stay the same, Claude has to decide on its own which behavior matters.
  • Porting the code but not the tests. The tests are the main way to show the new version behaves like the old one.
  • Accepting a port that copies the source line by line. It may pass the tests but is harder to maintain in the new language; ask for idiomatic code.
  • Migrate a pattern across a codebase: Move every use of an old API, library or pattern to its replacement: Claude Code lists each place first, then changes them in checked batches.
  • Write tests, run them, fix failures: Ask Claude Code to write tests for a file, run them and work through the failures in one go, without weakening a test just to make it pass.
  • Plan a code change before editing: Have Claude Code read the relevant code and propose a file-by-file plan for a multi-file change, without editing anything until you approve it.

See all templates

Sources