Claude Code

Verified against Claude Code · 2026-08-10

Brief Claude Code to port a codebase between languages without smuggling over the source language's idioms

A four-phase task brief for porting a module or service from one programming language to another, forcing an explicit idiom-mapping pass before any file gets touched so the result reads as native target-language code, not translated source code.

Claude Code6 fillable variables

The prompt

Ready to copy — highlighted parts are example details you can swap.

You are porting Python 3.11 code to Go 1.22. Work in four phases, in order, and do not begin Phase 2 until Phase 1 is written down and confirmed.

PHASE 1 — INVENTORY AND IDIOM MAP
List every file or module in scope: the report_generator/ package (9 files) that builds nightly PDF usage reports. For each source-language idiom that has no direct equivalent in Go 1.22 — error handling style, iteration patterns, null/optional handling, concurrency primitives — write down the target-language idiom it maps to, using these notes as the starting point: Python's try/except with broad catches maps to Go's explicit error-return checking, not to panic/recover; Python generators map to Go channels only where laziness is actually needed elsewhere it's a plain slice. This map is the single most important output of this phase; a port that skips it tends to produce Go 1.22 code that still thinks in Python 3.11, which compiles but reads as foreign to anyone who maintains it afterward.

PHASE 2 — PORT ONE REPRESENTATIVE FILE FIRST
Before touching the rest of the scope, port the single file most representative of the module's overall pattern. Stop and show it. This is the checkpoint where a wrong idiom-mapping decision gets caught once, cheaply, rather than propagated across every remaining file.

PHASE 3 — PORT THE REMAINDER
Apply the confirmed pattern from Phase 2 across the rest of the scope, file by file. For anything genuinely out of scope for this pass — the email-delivery wrapper that calls report_generator, which stays Python and just shells out to the new binary — leave it in Python 3.11 with a clear marker rather than porting it partially or guessing at its intent.

PHASE 4 — PARITY VERIFICATION
Run python scripts/compare_outputs.py --python-cmd 'python -m report_generator' --go-cmd './bin/report_generator' --fixtures tests/fixtures/ against both the original and the ported code on identical input and confirm matching output, not just that the port compiles or passes its own new tests written after the fact. A test suite written by the same pass that wrote the port will tend to test what the port actually does rather than what the original guaranteed — parity means checking against the original's behavior, including its edge cases and error paths, not just against the new code's own assumptions.

WHAT NOT TO DO
- Do not port line-by-line or function-by-function as a literal transliteration; a for-loop that exists because Python 3.11 lacks a construct Go 1.22 has natively should become that native construct, not a hand-rolled loop.
- Do not silently drop or reinterpret error-handling semantics — if Python 3.11 distinguishes recoverable from fatal errors in a way Go 1.22 handles differently, say so explicitly rather than picking one arbitrarily.
- Do not introduce a target-language dependency not already in Go 1.22's ecosystem or the project's existing dependency list without naming it and asking first.
- Do not mark the port complete based on Phase 3 alone; Phase 4 is not optional cleanup, it is the actual acceptance criterion.

End each phase by stating explicitly what was decided and what is still open, so a reviewer or a later session can pick up from that exact point.

Customize

Optional — swap in your own details for the highlighted parts above.

Why this works

The core failure mode of an AI-assisted language port is transliteration — code that compiles in the target language but is structurally still thinking in the source language, which is worse than it sounds because it passes review at a glance and only becomes a maintenance liability months later when someone tries to extend it the target-language way and the transliterated parts fight back. Forcing an explicit idiom map as its own phase, before any porting happens, catches this at the point where it's cheapest to fix: a wrong mapping decision written down and confirmed against one representative file costs a few minutes, while the same wrong decision discovered after all nine files have been ported costs a full re-pass. Porting one representative file before the rest applies the same checkpoint logic Claude Code benefits from in any multi-file task — an agent working file-by-file with no interim checkpoint tends to compound an early wrong assumption silently across every subsequent file, because nothing in the loop forces reconsideration until the very end, by which point the fix touches everything rather than one file. The parity-testing phase is deliberately specified as comparing against the original's behavior on identical input rather than 'passing tests,' because a test suite authored in the same pass that wrote the port is written by something that already believes the port is correct — it will tend to encode the port's own assumptions as the expected behavior rather than catch a case where the port silently changed behavior, which is precisely the blind spot that matters most in a language conversion where semantics like error handling or numeric precision can shift without anyone writing new code that looks obviously wrong. The what-not-to-do section names transliteration, dropped error semantics, and unauthorized new dependencies specifically because these are the three ways a port can look finished while quietly being wrong, none of which show up as a compile error or an obvious code-review red flag.

What you get back

Phase 1 idiom map (excerpt): - Python `except ValueError` broad catch -> Go explicit `if err != nil` with `errors.Is(err, ErrInvalidInput)` - Python list comprehension building report rows -> Go slice with explicit append loop (no lazy-eval need here) Phase 4 parity check: 47/47 fixture reports byte-identical between python and go binaries; 1 discrepancy found in currency rounding, traced to Go's default float formatting — fixed by matching Python's decimal.ROUND_HALF_UP explicitly.

Verified against

Claude Code Sonnet 4.6 · 2026-08-10

Changelog

  • 2026-08-10 Initial publish, verified against Claude Code Sonnet 4.6.

Building this for real?

This is a free starting point. If you'd rather have custom software built and running for your business, that's Scult's day job.

EXPLORE CUSTOM SOFTWARE
All Claude Code prompts

Check your AI visibility

One URL in, a 0–100 score and the exact fixes out.

RUN THE CHECK

Browse all the tools

15 tools across six categories
13 of them never send your data anywhere

Free · No signup · No trial clock

SEE THE DIRECTORY