CLion
 
Get CLion
Join the CLion 2025.1 Early Access Program and try out new features before they are released! Find out more

Format files from the command line

Last modified: 31 October 2024

CLion can format your code according to the configured code style settings. You can also apply your code style formatting to the specified files from the command line.

The command-line formatter launches an instance of CLion in the background and applies the formatting. It will not work if another instance of CLion is already running. In this case, you can perform code style formatting from the running instance. Use the command-line formatter for automated regular maintenance of a large codebase with many contributors to ensure a consistent coding style.

To be able to format files, install and enable plugins with support for the corresponding file types in CLion (for example, the Shell Script plugin to format shell script files).

You can find the executable for running CLion in the installation directory under bin. To use this executable as the command-line launcher, add it to your system PATH as described in Command-line interface.

Syntax
clion64.exe format [<options>] <path ...>
Examples

Format two specific files from the C:\Data\src directory using the default code style settings:

>
clion64.exe format -allowDefaults C:\Data\src\hello.cpp C:\Data\src\world.cpp

Recursively format all files in the C:\Data\src directory including all subdirectories using the default code style settings:

>
clion64.exe format -allowDefaults -r C:\Data\src

Non-recursively format all the .cpp and .h files in the C:\Data\src directory using code style settings from C:\Data\settings.xml:

>
clion64.exe format -s C:\Data\settings.xml -m *.cpp,*.h C:\Data\src