How to open .KTS files on Windows
To open .KTS files on Windows, to view/edit: open the .kts file in a code editor (any plain-text editor works for reading).
Step-by-step instructions
- To view/edit: open the .kts file in a code editor (any plain-text editor works for reading).
- To run as a Kotlin script: install the Kotlin command-line compiler and run: kotlinc -script path\to\file.kts
Common issues
Double-clicking doesn’t run the script
.kts files are source code; most operating systems do not execute them by default when you double-click.
- Open the file in a code editor to inspect it as text.
- Run it from a terminal with the Kotlin compiler: kotlinc -script file.kts
Trying to run a Gradle Kotlin DSL file as a standalone script
Files like build.gradle.kts are Gradle build scripts written in Kotlin DSL; they are meant to be evaluated by Gradle, not executed as a generic Kotlin script.
- If the file is named build.gradle.kts (or settings.gradle.kts), treat it as a Gradle build configuration.
- Run it through Gradle as part of the project (not via kotlinc -script).
Script fails because Kotlin tooling isn’t installed or on PATH
Running a .kts file requires the Kotlin command-line compiler (kotlinc). If it is missing or not available in your shell PATH, the command won’t work.
- Install the Kotlin command-line tools.
- Verify kotlinc is available by running: kotlinc -version
- Re-run the script using: kotlinc -script file.kts
Security note
.kts files are executable code when run (for example with kotlinc -script). Only run scripts from sources you trust, because they can perform actions allowed by your user account.