Code Translator — Claude & Claude.ai prompt: translate code between
A prompt that turns code in one language into another, keeping behaviour intact and commenting the key parts.
Open on GitHubWhat Code Translator: Any Language to Any Language does
The prompt puts the model in the role of a code translator. You fill in ${sourceLanguage} and ${targetLanguage}, paste a snippet, and get the same code back in the target language with explanatory comments.
Three steps are spelled out: analyse the syntax and semantics of the source, convert the code while preserving functionality, and annotate the important sections. The rules also ask the model to keep the structure and efficiency of the original and to avoid losing behaviour along the way.
It is written for chat use in Claude or Claude.ai. In Claude the repository ships .claude/commands/prompts.csv.md, so you invoke it as a slash command instead of pasting the text into a conversation. Since the model rewrites the whole snippet, long modules are a good reason to split the translation into chunks.
What it helps with
- port a script from Python to JavaScript
- move a function to another language without breaking behaviour
- get comments on unfamiliar code while translating it
- rewrite a snippet in the target language for a project
- read the source syntax before converting it
Example prompts for the agent
- Translate this code from Python to Go: <code>
- ${sourceLanguage}: JavaScript, ${targetLanguage}: Python — convert the function below
- Translate the class to TypeScript and comment the key methods
How to install Code Translator: Any Language to Any Language
How to use
Paste the text at the start of a chat or into project instructions
Manually: put the files in place
.claude/commands/prompts.csv.mdQuestions about Code Translator: Any Language to Any Language
How do I install Code Translator in Claude Code?
Add .claude/commands/prompts.csv.md to your project; the prompt then works as a slash command.
What does Code Translator do?
It converts code from one language to another while preserving functionality and adds comments to the key parts.
Where can I use it?
The prompt targets ChatGPT and Claude.ai, and Claude Code gets .claude/commands/prompts.csv.md as a command file.
Source text
prompts.csv · CC0-1.0
Act as a code translator. You are capable of converting code from any programming language to another. Your task is to take the provided code in ${sourceLanguage} and translate it into ${targetLanguage}. Ensure to include comments for clarity and understanding.
You will:
- Analyze the syntax and semantics of the source code.
- Convert the code into the target language while preserving functionality.
- Add comments to explain key parts of the translated code.
Rules:
- Maintain code efficiency and structure.
- Ensure no loss of functionality during translation.
© woyxiang · CC0-1.0 · f/prompts.chat