CSpell CLI
cspell-cli is the command-line interface for cspell, a robust spelling checker specifically designed for codebases. It provides comprehensive functionality to lint files, check spelling, trace words, and manage dictionaries directly from the terminal. The package is currently on a major version 10.0.0, released in April 2026, and follows a frequent release cadence, often updating in lockstep with new versions of the core cspell library. These updates can sometimes introduce breaking changes. Its key differentiators include extensive configuration options for various file types and languages, seamless integration with pre-commit hooks, and strong support for custom dictionaries, making it an essential tool for maintaining high code quality and consistency across diverse projects.
Common errors
-
cspell-cli: command not found
cause The `cspell-cli` package is not installed globally, or `npx` is not available/used, preventing the system from finding the executable.fixRun `npx cspell-cli <command>` to use the project-local version or download it temporarily, or install it globally with `npm install -g cspell-cli`. -
Error: EACCES: permission denied, open '.../cspell.json'
cause `cspell-cli` is attempting to create or modify configuration files (e.g., `cspell.json`, `cspell.config.yaml`) in a directory where the current user lacks write permissions.fixEnsure the user executing `cspell-cli` has appropriate write permissions to the target directory. If necessary, adjust file permissions or run the command with elevated privileges (e.g., `sudo npx cspell-cli ...`, used with caution). -
cspell-cli requires Node.js version >=20
cause The current Node.js runtime environment is older than the minimum required version (Node.js 20) specified by `cspell-cli`.fixUpgrade your Node.js installation to version 20 or newer. Tools like `nvm` (Node Version Manager) can help manage multiple Node.js versions: `nvm install 20 && nvm use 20`. -
Configuration file 'cspell.config.yaml' not found.
cause `cspell-cli` could not locate a configuration file in the expected paths, or the specified path was incorrect.fixCreate a `cspell.config.yaml` or `cspell.json` file in your project's root directory, or explicitly specify its location using the `--config <path>` option. Ensure the filename and path are correct.
Warnings
- breaking Version 10.0.0 introduces significant breaking changes due to updating the underlying `cspell` library to its 10.x series. This may affect configuration files, dictionary formats, and CLI options.
- gotcha This package requires Node.js version 20 or higher to run. Using older Node.js versions will result in execution errors.
- gotcha Installing `cspell-cli` globally (`npm install -g cspell-cli`) can lead to version inconsistencies, especially in projects that expect a specific version of `cspell-cli` or `cspell`.
- gotcha The `lint` command is the default action when `cspell-cli` is executed without a specific command. This can lead to unexpected behavior if users intend a different command (e.g., `check`) and omit it.
Install
-
npm install cspell-cli -
yarn add cspell-cli -
pnpm add cspell-cli
Imports
- cspell-cli (command)
import { lint } from 'cspell-cli';npx cspell-cli <command> [args...]
Quickstart
const fs = require('fs');
const { spawnSync } = require('child_process');
const testFilePath = 'test-file.js';
fs.writeFileSync(testFilePath, `
// This is a tst file with some typoes.
const myVariable = 'hte';
function chekSpelling() {
console.log(myVariable);
}
chekSpelling();
`);
console.log(`Checking '${testFilePath}' with cspell-cli...`);
// Execute cspell-cli via npx to check the dummy file
// npx will fetch cspell-cli if it's not locally installed.
const cspellProcess = spawnSync('npx', ['cspell-cli', testFilePath], { encoding: 'utf8' });
console.log('\n--- cspell-cli Output ---');
console.log(cspellProcess.stdout);
console.error(cspellProcess.stderr);
if (cspellProcess.status === 0) {
console.log('\nNo spelling errors found or process exited successfully.');
} else {
console.log(`\nSpelling errors found or process exited with code ${cspellProcess.status}.`);
}
// Clean up the dummy file
fs.unlinkSync(testFilePath);