Skip to content
Agents tracked: 506 Releases (7d): 634 Agent status: 3 with issuesSince last limit reset: Claude 15d · Codex 0d For AI agents: Markdown Updated Nov 26, 2026

chess.js

Chess move generation, validation and game state in JavaScript.

Game developmentNPM

GitHubWebsite

1. License

License from npm.

github.com/jhlywa/chess.js

From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error

What chess.js does

chess.js is a headless chess rules library: it generates and validates moves, reads and writes FEN and PGN, and detects check and game end, which the README sums up as "basically everything but the AI."

chess.js popularity

50 / 100
Gid Score, #1962 overall
473K
downloads a week, npm
4,461
GitHub stars
5
agent projects use it
chess.js: downloads per weeknpm, chess.js 473,327
chess.js: GitHub starsjhlywa/chess.js 4,461

Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated

How chess.js is used

  • chess.js joined the catalog on its public numbers (473,327 downloads a week on npm and 4,461 GitHub stars), not on our project count: it is a dependency in 17 public GitHub projects of our scan, 5 of them set up for AI coding agents.
  • Projects that use it most often also use Three.js (41.2%), React Three Fiber (29.4%), React (58.8%).

Often used with

In 41.2% of its projects
In 29.4% of its projects
In 58.8% of its projects
In 23.5% of its projects
In 70.6% of its projects
In 52.9% of its projects
In 17.6% of its projects
In 17.6% of its projects

chess.js in practice

Strengths

Permissive move parser is the default

Out of the box, <code>move()</code> notation is read by a permissive parser. It accepts plain SAN like <code>Nf3</code> and also variants such as <code>g1f3</code>, <code>g1-f3</code> and <code>Ng1xf3</code>.

Constructor validates FEN

<code>new Chess(fen)</code> throws if the FEN string is invalid. Setting <code>skipValidation</code> turns that off. The docs use it to load a position with the white king missing.

attackers() for square control

<code>attackers(square)</code> lists the squares whose pieces can attack a given square. It defaults to the side to move, and an optional color argument switches sides.

Position as a 2D array

<code>board()</code> returns the position as nested arrays of <code>{square, type, color}</code> objects, with <code>null</code> for empty squares. That shape maps directly onto a rendered grid.

Watch out for

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

Play a random game and print the PGN

import { Chess } from 'chess.js'

const chess = new Chess()

while (!chess.isGameOver()) {
  const moves = chess.moves()
  const move = moves[Math.floor(Math.random() * moves.length)]
  chess.move(move)
}
console.log(chess.pgn())

More about chess.js

Packages around it
  • three: 3D rendering
  • @react-three: React Three Fiber packages
  • better-sqlite3: SQLite driver
  • esbuild: Bundler
  • react-router-dom: React routing
  • ws: WebSocket library
More in Game development

Alternatives

chess.js This page

BSD-2-ClauseGid 50473K/wk

Compare chess.js with another tool

Get started

Install it.

npm install chess.js

Rules for your agent

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.