# chess.js — card for AI agents

Chess move generation, validation and game state in JavaScript.

Category: Game development · npm package `chess.js` · latest version 1.4.0 (checked 2026-11-01)
Install: `npm install chess.js`
License: BSD-2-Clause (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)

## chess.js
- Install with `npm install chess.js`. Import with `import { Chess } from 'chess.js'`, or `const { Chess } = require('chess.js')` in CommonJS.
- chess.js covers "everything but the AI" and has no UI. Do not look in it for move evaluation or rendering code.
- `new Chess(fen)` throws on an invalid FEN, so catch errors when the FEN comes from outside. Pass `{ skipValidation: true }` only when you mean to load an invalid position.
- Drive a game with `isGameOver()`, `moves()` and `move()`. Serialize with `fen()` or `pgn()`.
- The default move parser is permissive. The strict parser accepts only spec-compliant SAN.
- Do not read `getCastlingRights()` as "castling is legal now". The docs say checks and other factors also apply.
- Pass `forceEnpassantSquare` to `fen()` when the output must always include the en passant square.

## What it is
- chess.js is a TypeScript library for chess move generation and validation, piece placement and movement, and check, checkmate and stalemate detection. The GitHub repository also lists draw detection, gives BSD-2-Clause as the license, and was created on 2008-12-29. The README describes its scope as "basically everything but the AI." You install it from npm as `chess.js`.
- Everything goes through one `Chess` object. It starts at the initial position, or you pass it a FEN string. From there you list legal moves, make moves, and read the position back as FEN, PGN, a 2D array or an ASCII diagram. The docs show three ways to import it: as ESM, as an ES module directly in a browser `<script type="module">`, and through CommonJS `require`.
- There is no board to look at. The docs say chess.js is headless "by design" and point to chessboard.js as a library many developers have paired it with.

## Caveats
- No AI: The README lists what the library covers and ends with "basically everything but the AI." Its own example game picks moves at random.
- Headless, bring your own board: The library includes no user interface elements. The docs mention chessboard.js as the library many developers have integrated it with.
- Strict parser rejects variants: The second parser accepts only Standard Algebraic Notation that "strictly adhere[s] to the specification." The docs say it "runs slightly faster but will not parse any non-standard notation."
- Castling rights are not castling legality: `getCastlingRights()` reports only whether the kingside and queenside rights exist. The docs note that this does not tell you whether castling is legal in the current position.
- fen() can omit the en passant square: `fen()` includes the en passant square only when the side to move can legally capture en passant. To always include it, pass `forceEnpassantSquare`.

## Numbers (AgentGid data)
- Gid Score: 50.1 (#1962 of all tools, 4 of 8 in its category)
- Used in 5 public projects set up for AI coding agents (0.1%)
- Downloads last week: 473,327 (as of 2026-11-24), +96.7% over 4 weeks
- GitHub stars: 4,461 (as of 2026-11-24)
- Last push: 2026-08-11

## Often used with
Three.js 41.2%, React Three Fiber 29.4%, React 58.8%, ws 23.5%, TypeScript 70.6%, ESLint 52.9%

## Links
- AgentGid page: https://agentgid.com/tools/chess-js/
- Homepage: https://github.com/jhlywa/chess.js
- Repository: https://github.com/jhlywa/chess.js
- Source: https://github.com/jhlywa/chess.js#readme
- Source: https://github.com/jhlywa/chess.js
- Source: https://github.com/jhlywa/chess.js/releases
- Source: http://jhlywa.github.io/chess.js/

---
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.
