Skip to main content

Sharing and testing code with GitHub gists

Running code from gists

Scala CLI lets you run Scala code straight from GitHub gists, without the need to manually download them first. This is done by passing the link to a gist as an argument to Scala CLI:

For example, given the gist, which contains these two files:

object Messages {
def hello = "Hello"

You can run them with Scala CLI like this:


This example prints Hello to the standard output.


As shown in this example, the gist isn't limited to just one file. Scala CLI downloads the gist's archive and unzips it, so the gist can contain multiple files that depend on each other.

Scala CLI also caches the project sources using Coursier's cache.

Sharing code snippets

Together with the GitHub CLI (gh), it becomes really easy to share Scala code. If you want to share a code file named file.scala, just run this command to create the gist:

gh gist create file.scala

Then you (and others) can run it quickly, using the Scala CLI approach shown above.

Resources from gists

You can also use resources from gists archive. This is done by passing resourceDir in using directives.

For example, given the gist which containing Scala code and text file:

//> using resourceDir "./"

object Hello extends App {
val inputs = Source.fromResource("input")

and run them:


it will print 1,2,3,4 to the standard output.

Gists and Markdown code


This feature is a work in progress and should currently be treated as experimental. Markdown sources are ignored by default unless passed explicitly as inputs. You can enable including non-explicit .md inputs by passing the --enable-markdown option.

It is possible to run markdown sources from a GitHub gist. The gist is technically treated as a zipped archive (which it is downloaded as), so it is necessary to pass the --enable-markdown option alongside the gist URL to run any contained Markdown sources.

scala-cli --power --enable-markdown

You can find more information on working with Markdown in the Markdown guide.