# lint-staged — card for AI agents

Run linters on git staged files to catch issues before commit.

Category: Dev workflow and config · npm package `lint-staged` · latest version 17.6.0 (checked 2026-11-01)
Install: `npm install lint-staged`
License: MIT (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (paste into AGENTS.md or CLAUDE.md)

## lint-staged
- Install with `npm install --save-dev lint-staged`, then wire it into a `pre-commit` git hook (the README names Husky). Commit `package.json` and `.husky` so the team shares the setup.
- Do not pass file paths in config commands: lint-staged appends the staged files as arguments.
- Never let two globs that match the same files both run editing tasks. Use a negation pattern such as `!(*.ts)` plus the array syntax.
- Use an array (`["prettier --list-different", "eslint"]`) to run commands in order for one glob. Nest one more array to run them in parallel.
- In CI, run `npx lint-staged --all`. Note that it implies `--no-stash`.
- Type JS configs with `defineConfig` from `lint-staged/config`.
- If tasks may edit files that have unstaged changes, use `--hide-unstaged`, or those changes get staged too.

## Docs written for agents
- [llms.txt (index of the docs)](https://nextjs.org/llms.txt)

## What it is
- lint-staged runs formatters, linters and other commands only on the files you have staged for a commit. The README states the reasoning: running a task on a whole project "can be slow", and "you only want to check files that will be committed." The repository was created on 2016-01-15 and is MIT licensed.
- You write a config object. Each key is a glob and each value is a command. At commit time, lint-staged appends the matching staged file paths to that command as arguments, so `{ "*": "your-cmd" }` becomes `your-cmd file1.ext file2.ext`. Before tasks run, it backs up the original state. Changes that tasks make are staged and added to the commit.
- It does not install a git hook on its own. The README tells you to set up a `pre-commit` hook and names Husky as "a popular choice". It is for JavaScript projects that want checks on every commit without linting the whole tree each time.

## Caveats
- Overlapping globs can race: Globs run concurrently by default. If two globs match the same file and both tasks edit files, they can write to it at once. The README's fix is a negation pattern plus the array syntax.
- Tasks can stage your unstaged edits: Since the latest release, lint-staged stages every tracked file a task modifies, including files you never staged. The release notes point to `--hide-unstaged` to avoid this.
- Some flags drop the safety stash: `--all` and `--diff` both imply `--no-stash`, so the automatic backup is off when you use them.
- Long file lists split into repeat runs: When the argument string would be too long for the shell, lint-staged splits the file list into chunks and runs the command once per chunk. This also applies to functions. `--max-arg-length=Infinity` turns chunking off.
- Nearest config wins, even with no match: In a multi-config setup, a staged file belongs to the closest config only. If that config has no glob for the file, no other config picks it up.

## Numbers (AgentGid data)
- Gid Score: 80.2 (#98 of all tools, 8 of 299 in its category)
- Used in 487 public projects set up for AI coding agents (7.8%)
- Downloads last week: 42,635,558 (as of 2026-11-24), +39.8% over 4 weeks
- GitHub stars: 14,767 (as of 2026-11-24)
- Last push: 2026-11-22

## Often used with
Husky 89.3%, Prettier 71.0%, ESLint 71.9%, TypeScript 82.3%, Vitest 46.0%, Playwright (JavaScript) 39.4%

## Checked alternatives (same job)
- Lefthook: https://agentgid.com/tools/lefthook/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/lint-staged/
- Homepage: https://github.com/lint-staged/lint-staged#readme
- Repository: https://github.com/lint-staged/lint-staged
- Source: https://github.com/lint-staged/lint-staged#readme
- Source: https://github.com/lint-staged/lint-staged
- Source: https://github.com/lint-staged/lint-staged/releases

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
