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

  1. To view/edit: open the .kts file in a code editor (any plain-text editor works for reading).
  2. 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.

  1. Open the file in a code editor to inspect it as text.
  2. 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.

  1. If the file is named build.gradle.kts (or settings.gradle.kts), treat it as a Gradle build configuration.
  2. 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.

  1. Install the Kotlin command-line tools.
  2. Verify kotlinc is available by running: kotlinc -version
  3. 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.

Back to .KTS extension page