Codeshift is a command-line tool to translate and transform source code files between programming languages.
- Select output language to convert source code into
- Support for multiple input files
- Output results to a file or stream directly to
stdout
- Customize model and provider selection for optimal performance
- Supports leading AI providers:
- Node.js (Requires Node.js 20.17.0+)
- An API key from any of the following providers:
- OpenAI
- OpenRouter
- Groq
- any other AI provider compatible with OpenAI's chat completions API endpoint
-
Clone the repository with Git:
git clone https://github.com/uday-rana/codeshift.git
- Alternatively, download the repository as a .zip from the GitHub page and extract it
-
In the repository's root directory (where
package.json
is located), runnpm install
:cd codeshift/ npm install
-
To be able to run the program without prefixing
node
, runnpm install -g .
ornpm link
within the project directory:npm install -g .
-
Create a file called
.env
by copying the.env.example
file -
Add your API key, preferred base URL, and preferred model. It should look similar to the example below:
-
For OpenAI, use the base URL
https://api.openai.com/v1
-
For OpenRouter, use the base URL
https://openrouter.ai/api/v1
-
For Groq, use the base URL
https://api.groq.com/openai/v1
. -
For a list of models for each provider, see:
# .env API_KEY=YOUR_API_KEY_HERE BASE_URL=https://api.groq.com/openai/v1 MODEL=llama3-8b-8192
-
codeshift [options] <output-language> <input-files...>
<output-language>
: The desired language to convert source files to<input-files...>
: Paths to the source files, separated by spaces
-o, --output
: Specify filename to write output to-t, --token-usage
: Display the number of tokens used by the AI for processing-h, --help
: Display the help message explaining usage, options, and arguments-v, --version
: Display the program name and version number
# Converts a JavaScript file (index.js) to Go, saving the output in index.go
codeshift -o index.go go examples/index.js
See CONTRIBUTING.md
This project is licensed under the MIT License. See the LICENSE file for more details.