leetcli is a powerful and intuitive command-line tool built in C++17 that allows you to interact with LeetCode directly from your terminal. Whether you're preparing for interviews or grinding through problems, leetcli makes the process faster and more developer-friendly.
- C++17 — fast, efficient, and portable
- cpr — a modern C++ HTTP client library used for interacting with LeetCode's REST and GraphQL APIs
- nlohmann/json — easy-to-use JSON parsing for handling API data
- Google Gemini API — used for AI-powered features like runtime analysis and intelligent hints
- 📝 Fetch problems (including the daily question)
- 🧠 AI-powered analysis (runtime complexity + hints via Gemini)
- 💻 Edit solutions in your preferred language (C++, Python, Java)
- ✅ Run solutions remotely on LeetCode with real test cases
- 📤 Submit solutions directly from the CLI
- 📂 Organized project structure with per-problem folders
- 🔑 Session management for authenticated actions
For macOS and Linux users:
curl -fsSL https://raw.githubusercontent.com/d3kanesa/leetcli/main/install-leetcli.sh | bash-
Install prerequisites:
# Install Homebrew if you don't have it /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" # Install CMake brew install cmake
-
Set up vcpkg from GitHub:
# Clone vcpkg to a permanent location git clone https://github.com/Microsoft/vcpkg.git ~/vcpkg # Set the VCPKG_ROOT environment variable echo 'export VCPKG_ROOT="$HOME/vcpkg"' >> ~/.zshrc source ~/.zshrc # Bootstrap vcpkg cd ~/vcpkg ./bootstrap-vcpkg.sh
-
Clone the repository:
git clone https://github.com/d3kanesa/leetcli.git cd leetcli -
Install dependencies:
vcpkg install cpr nlohmann-json
-
Build and install:
cmake -S . -B build -DCMAKE_TOOLCHAIN_FILE=$VCPKG_ROOT/scripts/buildsystems/vcpkg.cmake cmake --build build --target install
Alternative installation to user directory:
cmake --install build --prefix ~/.local echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc source ~/.zshrc
-
Test the installation:
leetcli --help
-
Install prerequisites:
# Install Chocolatey if you don't have it (run in PowerShell as Administrator) Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1')) # Install Git, CMake, and Visual Studio Build Tools choco install git cmake visualstudio2022buildtools
-
Set up vcpkg from GitHub:
# Clone vcpkg to a permanent location (e.g., C:\vcpkg) git clone https://github.com/Microsoft/vcpkg.git C:\vcpkg # Set the VCPKG_ROOT environment variable setx VCPKG_ROOT "C:\vcpkg" # Bootstrap vcpkg cd C:\vcpkg .\bootstrap-vcpkg.bat
-
Clone the repository (in a directory of your choice):
git clone https://github.com/d3kanesa/leetcli.git cd leetcli -
Generate a build folder
mkdir build cd build
-
Install dependencies:
vcpkg install cpr nlohmann-json
-
Build and install:
cmake -S .. -B . ` -DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake ` -DVCPKG_TARGET_TRIPLET=x64-windows ` -DVCPKG_APPLOCAL_DEPS=ON cmake --build . --config Release -
Test the installation:
cd releases leetcli help
Run init once at the root of your development folder:
leetcli initThis command sets up your leetcli workspace:
- Creates a
problems/folder in the current directory to store fetched problems. - Asks you to choose your preferred programming language (
cpp,python,java), which is used as the default when fetching problems. - Saves configuration in a
.leetcli_config.jsonfile.
Additionally, you'll want to authorize your LeetCode session to enable features like problem submission and test running:
- Run the login command:
leetcli login
- You'll be prompted to enter your LeetCode session token and CSRF token, which are stored securely for future use.
To set your Gemini API key:
leetcli config set-gemini-key <your-gemini-key>leetcli init Initialize the problems directory in your current directory
leetcli fetch slug [--lang=...] Fetch a problem by slug or use 'daily' for the daily question
leetcli solve slug [--lang=...] Open the solution file in your default editor
leetcli list List all fetched problems
leetcli login Set your LEETCODE_SESSION and CSRF token
leetcli run slug [--lang=...] Run your solution against LeetCode testcases
leetcli submit slug [--lang=...] Submit your solution to LeetCode
leetcli runtime slug [--lang=...] Analyze time/space complexity using Gemini
leetcli hint slug [--lang=...] Ask Gemini for a helpful hint based on your solution progress
leetcli hints slug Gets the hints for the given problem in leetcode
leetcli topics slug Gets the topics for the given problem in leetcode
leetcli config set-gemini-key key Set your Gemini API key
leetcli help Show this help messageleetcli runtime two-sum🧠 Gemini Runtime Analysis:
Time: O(n)
Space: O(n)
Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.
MIT License
