Skip to main content
The SCANOSS pre-commit hooks run just before your changes are committed, triggering automated scans to detect open-source components that have not been declared in your scanoss.json configuration. By catching undeclared components at commit time, issues are identified early in the development process rather than later in the pipeline.

Prerequisites

Before you begin, ensure the following are installed and configured:

Installation

Getting Started

Configure the Hook

Create .pre-commit-config.yaml at the root of your repository:

Verify Configuration

Install the Hook

Test the Hook

Configuration

Environment Variables

The hook automatically loads variables from a .env file in your project root:

How It Works

Example Workflow

Given this project structure:
When you commit:
The hook automatically:
  1. Scans staged files for open-source components.
  2. Compares detected components against the declarations in your scanoss.json file. A declaration is an explicit acknowledgement that a given open-source component is present and approved for use in your project.
  3. Blocks the commit if any undeclared components are found.

Example Output

The following is an example of output produced when undeclared components are detected. File paths and package identifiers are truncated for brevity.
Note: The files were modified by this hook message indicates that the hook wrote scan result metadata to your working directory as part of its analysis. These modifications are rolled back if a conflict with unstaged changes is detected, as shown in the output above.
The commit is blocked until you take one of the following actions:
  1. Declare the components in scanoss.json.
  2. Run scanoss-cc in the terminal to review and declare the components interactively.
  3. Remove the non-compliant or undeclared code.

Troubleshooting

Enable Debug Mode

Method 1: Environment Variable
Method 2: .env File
Method 3: Command-Line Argument