A modern LeetCode CLI built with TypeScript
npm install @night-slayer18/leetcode-cliA modern, feature-rich LeetCode CLI built with TypeScript.







- ๐ Cookie-based authentication - Secure login using browser cookies
- ๐ List problems - Filter by difficulty, status, tags, and search
- ๐ Beautiful problem display - Formatted output with examples and constraints
- ๐ Generate solution files - Auto-organized by difficulty and category
- ๐งช Test solutions - Run against sample test cases
- ๐ค Submit solutions - Submit directly to LeetCode
- ๐ View statistics - Track your progress
- ๐ฏ Daily challenge - Get today's problem
- โฑ๏ธ Interview timer - Timed practice with solve time tracking
- ๐ธ Solution snapshots - Save, restore, and compare solution versions
- ๐ฅ Collaborative coding - Solve problems with a partner
- ๐ Workspaces - Isolate contexts (interview prep, study, contests)
- โ๏ธ Configurable - Set language, editor, and working directory
- ๐ Smart file discovery - Use problem ID, filename, or full path
- ๐ Git Sync - Auto-sync solutions to GitHub/GitLab
- ๐ Auto-update notifications - Get notified when updates are available
``bash`
npm install -g @night-slayer18/leetcode-cli
`bashLogin with your LeetCode cookies
leetcode login
Commands
| Command | Description |
|---------|-------------|
|
login | Login with LeetCode browser cookies |
| logout | Clear stored credentials |
| whoami | Check login status |
| today | Show daily progress & challenge |
| list | List problems with filters |
| show | Display problem description |
| hint | Show hints for a problem |
| pick | Generate solution file |
| pick-batch | Pick multiple problems |
| bookmark | Manage problem bookmarks |
| note | Manage problem notes |
| daily | Show today's challenge |
| random | Get a random problem |
| test | Test solution against sample cases |
| submit | Submit solution to LeetCode |
| submissions | View past submissions |
| stat [username] | Show user statistics |
| timer | Interview mode with timer |
| snapshot | Save and restore solution versions |
| diff | Compare solution with past submissions |
| collab | Collaborative coding with a partner |
| workspace | Manage workspaces for different contexts |
| config | View or set configuration |
| sync | Sync solutions to Git repository |
| update | Check for CLI updates |
| changelog | View release notes and breaking changes |
Usage Examples
$3
`bash
List all problems
leetcode listFilter by difficulty
leetcode list -d easy
leetcode list -d medium
leetcode list -d hardPagination
leetcode list --page 2 -n 10Search by keyword
leetcode list -s "binary tree"
`$3
`bash
leetcode show 1
leetcode show two-sum
`$3
`bash
Show hints one at a time (press Enter for next)
leetcode hint 1
leetcode hint two-sumShow all hints at once
leetcode hint 1 --all
`$3
`bash
Generate solution file (uses default language)
leetcode pick 1Specify language
leetcode pick 1 --lang python3Skip opening in editor
leetcode pick 1 --no-open
`$3
All formats work for both
test and submit:`bash
Using problem ID (auto-finds the file)
leetcode test 20
leetcode submit 20Using filename
leetcode test 20.valid-parentheses.java
leetcode submit 20.valid-parentheses.javaUsing full path
leetcode test ./Easy/String/20.valid-parentheses.javaWith custom test case
leetcode test 20 -c "[1,2,3]\n4"Visual debugging (ASCII visualization for arrays, trees, etc.)
leetcode test 1 --visualize
`$3
Fetch and solve a random problem.
`bash
Get random problem
leetcode randomFilter by difficulty
leetcode random -d hardFilter by topic tag
leetcode random -t dpPick immediately
leetcode random -d medium --pick
`$3
View past submissions and download code.
`bash
List last 20 submissions
leetcode submissions 1View details of last accepted submission
leetcode submissions 1 --lastDownload last accepted solution
leetcode submissions 1 --download
`$3
`bash
# Show today's progress & challenge
leetcode today
# Pick multiple problems at once
leetcode pick-batch 1 2 3 -l python3
# Bookmark problems
leetcode bookmark add 1
leetcode bookmark list
# Keep personal notes
leetcode note 1 edit
`$3
`bash
Basic stats (solved count, rank, streak)
leetcode statWeekly activity table (last 12 weeks)
leetcode stat -cSkill breakdown by topic tags
leetcode stat -s7-day trend chart
leetcode stat -t
` ### Git Integration
`bash
# Sync all solutions to your configured git repo
leetcode sync
`$3
`bash
Start timer for a problem (default: Easy=20m, Medium=40m, Hard=60m)
leetcode timer 1Custom time limit
leetcode timer 1 -m 30View your solve time stats
leetcode timer --statsStop active timer
leetcode timer --stop
`$3
`bash
Host a collaboration session
leetcode collab host 1Share the room code with your partner
Partner joins with:
leetcode collab join ABC123Both solve the problem, then sync
leetcode collab syncCompare solutions
leetcode collab compareCheck session status
leetcode collab statusLeave session
leetcode collab leave
`$3
`bash
Save current approach
leetcode snapshot save 1 "brute-force"Try a new approach, then save
leetcode snapshot save 1 "hash-map"List all saved versions
leetcode snapshot list 1Compare approaches
leetcode snapshot diff 1 1 2Restore if needed
leetcode snapshot restore 1 brute-force
`$3
`bash
Compare with last accepted submission
leetcode diff 1Show unified diff (line-by-line changes)
leetcode diff 1 --unifiedCompare with specific submission
leetcode diff 1 --submission 12345Compare with local file
leetcode diff 1 --file other-solution.py
`$3
Isolate your problem-solving contexts (e.g., interview prep vs daily practice).
`bash
Show current workspace
leetcode workspace currentList all workspaces
leetcode workspace listCreate new workspace
leetcode workspace create interview -w ~/leetcode-interviewSwitch workspace
leetcode workspace use interviewDelete workspace (files not deleted)
leetcode workspace delete old-workspace
`Each workspace has its own config, timer history, and solution snapshots.
### Configuration
`bash
View current config
leetcode configInteractive setup
leetcode config -iSet specific options
leetcode config --lang python3
leetcode config --editor code
leetcode config --workdir ~/leetcode
leetcode config --repo https://github.com/username/leetcode-solutions.git
`Folder Structure
Solution files are automatically organized by difficulty and category:
`
leetcode/
โโโ Easy/
โ โโโ Array/
โ โ โโโ 1.two-sum.java
โ โโโ String/
โ โโโ 20.valid-parentheses.java
โโโ Medium/
โ โโโ Array/
โ โโโ 15.3sum.java
โโโ Hard/
โโโ Array/
โโโ 4.median-of-two-sorted-arrays.java
`Supported Languages
| Language | Extension |
|----------|-----------|
| TypeScript |
.ts |
| JavaScript | .js |
| Python3 | .py |
| Java | .java |
| C++ | .cpp |
| C | .c |
| C# | .cs |
| Go | .go |
| Rust | .rs |
| Kotlin | .kt |
| Swift | .swift |Authentication
This CLI uses cookie-based authentication. To login:
1. Open leetcode.com in your browser
2. Login to your account
3. Open DevTools (F12) โ Application โ Cookies โ leetcode.com
4. Run
leetcode login and paste your LEETCODE_SESSION and csrftoken valuesConfiguration File
Config is stored at
~/.leetcode/config.json:`json
{
"credentials": {
"session": "...",
"csrfToken": "..."
},
"config": {
"language": "java",
"editor": "code",
"workDir": "/path/to/leetcode",
"repo": "https://github.com/username/leetcode-solutions.git"
}
}
`Requirements
- Node.js >= 20.0.0
Development
`bash
Clone and install
git clone https://github.com/night-slayer18/leetcode-cli.git
cd leetcode-cli
npm installBuild
npm run buildRun tests
npm testRun with coverage
npm test -- --coverage
`See docs/testing.md for detailed testing documentation.
Docker Usage
You can run the CLI using Docker without installing Node.js.
$3
1. Pull the image:
`bash
docker pull nightslayer/leetcode-cli:latest
`2. Setup Shell Function (Add to your shell config):
Bash/Zsh (
~/.bashrc or ~/.zshrc):
`bash
leetcode() {
docker run -it --rm \
-w /root/leetcode \
-v "$(pwd)/leetcode:/root/leetcode" \
-v "$HOME/.leetcode:/root/.leetcode" \
nightslayer/leetcode-cli:latest "$@"
}
` Fish (
~/.config/fish/config.fish):
`fish
function leetcode
docker run -it --rm \
-w /root/leetcode \
-v (pwd)/leetcode:/root/leetcode \
-v $HOME/.leetcode:/root/.leetcode \
nightslayer/leetcode-cli:latest $argv
end
` PowerShell (
$PROFILE):
`powershell
function leetcode {
docker run -it --rm
-v "${PWD}/leetcode:/root/leetcode"
nightslayer/leetcode-cli:latest $args
}
`3. Usage:
`bash
leetcode list
leetcode pick 1
`$3
1. Build the image:
`bash
docker build -t leetcode-cli .
`2. Run commands:
`bash
docker run -it --rm \
-w /root/leetcode \
-v "$(pwd)/leetcode:/root/leetcode" \
-v "$HOME/.leetcode:/root/.leetcode" \
leetcode-cli list
`
Note: We mount ~/.leetcode to persist login credentials and leetcode` folder to save solution files.Apache-2.0 ยฉ night-slayer18