clj
Run Clojure programs or start a REPL
TLDR
Start a REPL (interactive shell)
Execute a function
Run the main function of a specified namespace
Prepare a project by resolving dependencies, downloading libraries, and making/caching classpaths
Start an nREPL server with the CIDER middleware
Start a REPL for ClojureScript and open a web browser
SYNOPSIS
clj [options] [main-expression] [arguments]
clj -M:alias [main-expression] [arguments]
clj -A:alias [arguments]
clj -R:alias [arguments]
clj -S:subcommand [subcommand-arguments]
clj -P
PARAMETERS
-M or -M:<I>alias</I>
Invokes a main entry point. Uses configuration from alias if provided.
-A or -A:<I>alias</I>
Adds paths or dependencies to the classpath. Includes configuration from alias if provided.
-R or -R:<I>alias</I>
Configures REPL behavior. Applies REPL-specific settings from alias if provided.
-S<I>subcommand</I>
Executes system-level operations. Common subcommands include path (prints classpath), describe (prints environment info), and install (installs the tool).
-P
Resolves and downloads dependencies, then prints the resulting classpath.
-e <I>expression</I>
Evaluates the given Clojure expression directly.
-r, --repl
Starts a standard Clojure REPL session.
-m <I>ns-name</I>
Specifies the namespace containing the 'main' function to be executed.
-i <I>file</I>
Loads a Clojure source file before execution.
--config <I>file</I>
Specifies an alternative 'deps.edn' configuration file.
--verbose
Prints additional diagnostic information.
--help, -h
Displays usage information and available options.
DESCRIPTION
clj is the official command-line interface for Clojure, part of the tools.deps.alpha project. It simplifies the process of running Clojure programs, managing project dependencies, and launching a REPL (Read-Eval-Print Loop). It leverages deps.edn files to define project dependencies and source paths, allowing for easy execution of Clojure code without requiring a separate build tool like Leiningen or Boot. clj handles dependency resolution and classpath construction automatically, making it convenient for both development and scripting tasks in Clojure. It provides a lightweight and flexible alternative for project management.
CAVEATS
Requires Java Development Kit (JDK) installed and configured in the system PATH. Relies heavily on deps.edn for configuration, which can have a learning curve. Not a standalone executable, but a wrapper script invoking Java. Network access is typically required for initial dependency resolution and downloads. Initial startup can be slow due to JVM startup and classpath construction.
<I>DEPS.EDN</I> INTEGRATION
clj heavily utilizes deps.edn files, which are central to defining project dependencies, source paths, and aliases. These files are typically found in the project root and allow for declarative configuration of the Clojure environment.
ALIAS SYSTEM
The clj tool employs a powerful alias system within deps.edn, allowing users to define specific configurations (e.g., different main functions, extra dependencies, JVM options) that can be invoked with options like -M:<I>alias</I>, -A:<I>alias</I>, or -R:<I>alias</I>. This promotes reusable and flexible project setups.
HISTORY
clj was introduced as part of Clojure's official tools.deps.alpha project, aiming to provide a simpler, dependency-driven way to manage Clojure projects without the overhead of existing build tools. It emerged in the late 2010s (around 2018-2019) to address community needs for a more lightweight and integrated project management solution, particularly for scripting and smaller applications. It gained significant traction as the preferred official method for starting Clojure projects and REPLs, moving away from relying solely on third-party tools.