CodeScene CLI tool

What You Can Do With The CLI

The CodeScene CLI helps you run CodeScene analyses where developers work: locally, in pre-commit/push hooks, and in CI.

What you can do with the CLI:

  • Review non-committed or staged changes before opening a PR.

  • Compare branches with delta analysis to see code health impact.

  • Use pre-commit and pre-push hooks to catch issues early.

  • Integrate with editors and CI/CD pipelines.

cs git-hook flow-chart

Run The CLI In A Git Pre-Commit Hook

Use this pre-commit hook as a deterministic quality gate that blocks commits which would lower Code Health or introduce new unhealthy code.

  • It complements the CodeScene MCP safeguard guidance. AI-assisted workflows are non-deterministic, so the hook adds a local, deterministic safety net before code is committed.

  • For manual coding workflows, it shortens the feedback loop by catching Code Health regressions so you don’t have to wait for Pull Request checks.

The script below prefers interactive mode when a TTY is available, and falls back to a non-interactive git-hook mode in editors that do not expose terminal input to hooks.

#!/bin/sh

# Skip the hook when the CodeScene CLI is not installed.
if command -v cs > /dev/null 2>&1; then
   # Some editors run hooks without a TTY, so interactive prompts are not possible.
   if (exec </dev/tty) > /dev/null 2>&1; then
      # Reattach stdin to the terminal before starting interactive mode.
      exec < /dev/tty
      cs delta --interactive --staged
   else
      # Fall back to non-interactive hook mode when no terminal input is available.
      cs delta --git-hook --staged
   fi
fi

👉 Save the script as .git/hooks/pre-commit``epository and make it executable with ``chmod +x .git/hooks/pre-commit.

Command Guides And Reference

Here is a quick guide to the core workflows:

  • cs delta for change-based analysis between working tree, commits, or branches.

  • cs review and cs check for file-focused code health feedback.

  • cs rules-config and cs check-rules for custom code health rule tuning.

Install The CLI

Installation

Linux, macOS and Windows (if WSL)

The install script will download the binary, move it to ~/.local/bin and make it executable. If ~/.local/bin is not in the user’s PATH, it will be added.

It works if your shell is one of: bash, zsh or fish

curl https://downloads.codescene.io/enterprise/cli/install-cs-tool.sh | sh

Windows (powershell)

The powershell script downloads the windows binary, moves it to $env:USERPROFILE\AppData\Local\Programs\CodeScene and makes it executable.

Invoke-WebRequest -Uri 'https://downloads.codescene.io/enterprise/cli/install-cs-tool.ps1' -OutFile install-cs-tool.ps1
.\install-cs-tool.ps1

Note, on non-server editions of Windows, the script execution policy is set to Restricted by default, and script execution is disabled. It can be enabled with:

Set-ExecutionPolicy RemoteSigned

This allows for the execution of trusted scripts downloaded from the internet, and all local scripts. In our case the script is considered a local file.

Manual installation

The binaries are also available for manual installation. Just download the binary for you platform and make it executable.

Platform specific notes

  • MacOS binaries are not signed, thus you have to manually move them out of quarantine using xattr -dr com.apple.quarantine <binary>.

  • Windows users might have to set the script execution policy manually as mentioned above: Set-ExecutionPolicy RemoteSigned

Updating

To update the tool, just run the install script again or re-do the manual installation.

You can check the version of the installed tool via cs version, which will print out the build date and SHA for the installed version.

Authenticate The CLI

For interactive use, set the CodeScene URL and sign in with your account. The command opens a browser for login and stores a refreshable session locally. The CLI refreshes the session automatically. Sign in again if the session expires, or revoke it from Manage OAuth2 Authorizations.

export CS_ONPREM_URL=<https://your.codescene.com>
cs auth login

Use --no-browser when the CLI cannot open a browser, for example in an SSH session or on a headless machine. It prints a login URL that you can open in a browser on this or another computer:

cs auth login --no-browser

Check the stored session, or sign out:

cs auth status
cs auth logout

For CI or other non-interactive environments, use a user with a Technical role - see Users and Roles. Create a Personal Access Token at https://your.codescene.com/configuration/user/token.

Set the environment variables as follows:

export CS_ONPREM_URL=<https://your.codescene.com>
export CS_ACCESS_TOKEN=<your-token>

Or in Windows PowerShell:

$env:CS_ONPREM_URL = '<https://your.codescene.com>'
$env:CS_ACCESS_TOKEN = '<your-token>'

Windows setup options

Windows Command Prompt (temporary, current session):

SET CS_ACCESS_TOKEN=<your-token>
SET CS_ONPREM_URL=<https://your.codescene.com>

Windows Command Prompt (persistent):

SETX CS_ACCESS_TOKEN=<your-token>
SETX CS_ONPREM_URL=<https://your.codescene.com>

You can also set variables through System Properties:

  1. Right-click “This PC” or “My Computer”

  2. Click “Properties”

  3. Click “Advanced system settings”

  4. Click “Environment Variables”

Shortcut:

  1. Press Windows + R

  2. Type sysdm.cpl

  3. Go to the “Advanced” tab

  4. Click “Environment Variables”

Off-line use

Once the CLI tool has successfully authenticated with the server once, it can be used offline until the end of the server’s license period. The offline license is stored in the directory defined by the CODESCENE_HOME environment variable. If you want to run offline in builds such as GitHub Actions, you can copy this folder into the Docker image.

If environment variable CODESCENE_HOME is not set:

  • in Windows it is $APP_DATA/Codescene

  • else it is .codescene directory in user home directory

Command Guides And Reference