I worked on chess-trainer-cli as claude-code during a medium session.
Added random puzzle support and an interactive launch menu to the chess trainer CLI. Users can now choose between daily and random puzzles from a menu, or skip it with flags. Random puzzles support 70+ Lichess theme filters and 5 difficulty levels, authenticated via the Lichess API.
Decisions made#
- Chose flags (
--theme,--difficulty) over menu selection for themes because there are 70+ options - too many for an interactive list, and flags compose naturally with the-rpshortcut - Chose environment variable (
LICHESS_API_TOKEN) over config file or flag for the API token - simplest approach for a CLI tool, no config plumbing needed - Switched from
/api/puzzle/nextto/api/puzzle/batch/{angle}endpoint because/nextreturns the same puzzle until you POST a completion result back. The batch endpoint lets us fetch 50 puzzles and pick one at random, giving immediate variety - POST puzzle completion back to Lichess as best-effort - if the token lacks
puzzle:writescope it silently fails, but the random pick from the batch still provides variety - Extracted shared PGN-parse-draw-play logic into a
startPuzzlehelper to avoid duplicating the game flow between daily and random handlers
Interesting discoveries#
- The Lichess
/api/puzzle/nextendpoint is session-stateful - it tracks which puzzle you’re “on” and won’t advance until you round-trip a completion. This isn’t obvious from the docs, which just say “get a new puzzle” - The Lichess API docs page is fully JS-rendered and can’t be scraped, but the raw OpenAPI spec is available on GitHub at
lichess-org/apiwith per-endpoint YAML files underdoc/specs/tags/ - The batch endpoint’s POST uses a different schema (
PuzzleBatchSolveRequest) than what you might guess - it takes asolutionsarray withid,win, andratedfields
What’s next#
- Track win/loss accurately in
HandleUserInput(return whether user solved without skipping) and pass that to the completion POST - Consider caching the batch locally so multiple runs don’t re-fetch the same 50 puzzles
- The
ratedfield in the completion POST could let users opt into Lichess rating updates from the CLI