leetcode-cli talks to LeetCode as you, so it needs your session cookies. There are three ways to provide them.
If csrf and session are both empty in leetcode.toml, leetcode-cli reads the cookies straight from Chrome's cookie store for the configured site. Just sign in to LeetCode in Chrome and run any command β there is nothing else to set up.
This is the only automatic path, and it is Chrome-only. It works on macOS and Linux; on Windows Chrome's cookie encryption isn't read automatically yet, so use the manual setup below. The same applies if you use a different browser, or Chrome's cookie store can't be read.
If you see a "not logged in to Chrome" error, either sign in to LeetCode in Chrome or set the cookies manually.
Copy the two cookie values into leetcode.toml:
[cookies]
csrf = '<your-leetcode-csrf-token>'
session = '<your-leetcode-session-key>'
site = 'leetcode.com'To find them β for example in Firefox, after logging in to LeetCode:
- Press F12 and open the Storage tab.
- Expand Cookies and select
https://leetcode.com. - Copy the
ValueofcsrftokenintocsrfandLEETCODE_SESSIONintosession.
The same values are available under DevTools in any Chromium browser (Application β Cookies).
To keep secrets out of leetcode.toml, leave csrf and session empty and export them instead. Environment variables override whatever is in the file:
export LEETCODE_CSRF='<your-leetcode-csrf-token>'
export LEETCODE_SESSION='<your-leetcode-session-key>'
export LEETCODE_SITE='leetcode.com' # or 'leetcode.cn'cookies.site must still be present in leetcode.toml (otherwise config parsing fails), but LEETCODE_SITE overrides it at runtime.
site accepts exactly two values: leetcode.com or leetcode.cn (anything else is rejected). Choosing leetcode.cn switches every API endpoint to the China site β set it via the config field or LEETCODE_SITE.