A highly customizable command-line interface for seamless interaction with Leetcode. Manage problems, test solutions, and track progress - all from your terminal!
-
Comprehensive Problem Management
- List problems with filters (difficulty, tags, pagination)
- View detailed problem statements with examples and constraints
- Random problem selection with custom filters
-
Solution Development
- Auto-generated solution files with official code snippets
- Local testing against Leetcode's example cases
- Direct solution submission to Leetcode
-
User Analytics
- Submission statistics and acceptance rates
- Daily submission calendar visualization
-
Customization
- Theme support for output styling
- Configurable default language and user preferences
- Python 3.7+
- pip package manager
# Clone repository
git clone https://github.com/michal-pielka/leetcode_cli
cd leetcode-cli
# Install as global package
pip install .
- Initialize Configuration
leetcode config cookie YOUR_LEETCODE_SESSION_COOKIE
leetcode config username YOUR_LEETCODE_USERNAME
leetcode config language python
- Basic Workflow
# Find a medium difficulty array problem
leetcode list --difficulty MEDIUM --tag array
# View problem details
leetcode show 15 # Using ID
leetcode show two-sum # Using title slug
# Create solution file
leetcode create # Creates last seen problem solution file for default language
leetcode create 1 # Creates two-sum [1] problem solution file for default language
leetcode create two-sum # Creates two-sum [1] problem solution file for default language
leetcode create .cpp # Creates last seen problem solution file for C++
# Test solution
leetcode test 1.two-sum.py
# Submit solution
leetcode submit 1.two-sum.py
Configuration files are stored in ~/.leetcode/
(Linux/macOS) or %APPDATA%/.leetcode
(Windows).
Key | Description | Example Value |
---|---|---|
cookie | Leetcode session cookie (required) | abc123def456ghi789jkl0 |
username | Leetcode username for stats | sample_username |
language | Default programming language | python |
theme | Output color theme | gruvbox |
Security Note: Never share your Leetcode session cookie.
This CLI allows you to control what information is displayed when you show, test, or submit problems. You can enable or disable specific sections of the output by editing the formatting_config.yaml
file found in your ~/.leetcode/
folder. The file is split into top-level keys (interpretation
, submission
, problem_show
) corresponding to different CLI actions.
For example, when you test your solution (leetcode test <FILEPATH>
), the CLI references the interpretation
section to decide whether to display the language, testcases, or error messages. Similarly, when you submit a solution (leetcode submit <FILEPATH>
), it looks at the submission
section. When you show or random a problem, it uses the problem_show
section to determine which parts of the problem statement to display (title, tags, examples, etc.).
Here’s a simplified preview of some of the available options:
Category | Option | Default Value | Description |
---|---|---|---|
interpretation | show_language |
true | Show the programming language used in test results. |
show_testcases |
true | Show the testcases used for the test code action. | |
... |
... | ... | |
submission | show_language |
true | Show the programming language in submission results. |
show_testcases |
true | If submission fails, display the testcases that caused the error. | |
... |
... | ... | |
problem_show | show_title |
true | Display the problem’s title and difficulty. |
show_tags |
true | Show the problem’s topic tags. | |
... |
... | ... |
You can edit these defaults to tailor your experience. For example, if you find the error messages too verbose, set show_detailed_error_messages: false
in the interpretation
or submission
sections.
FORMATTING_CONFIG.CONFIGURATION.mov
The CLI uses a theming system to style its output with colors, symbols, and prefixes/suffixes. A theme is comprised of three YAML files:
- ansi_codes.yaml – Defines your ANSI color codes and text styles (e.g.,
bold
,italic
,underline
, or RGB color codes). - symbols.yaml – Defines textual symbols (e.g., checkmarks, crosses, squares) used in CLI outputs.
- mappings.yaml – Maps each CLI “key” or “status” (e.g.,
status_accepted
,difficulty_easy
) to a combination of styles and symbols.
To create your own theme:
-
Create a folder under
~/.leetcode/themes/
named after your theme. For example:~/.leetcode/themes/mycooltheme
. -
Add your YAML files inside that folder:
ansi_codes.yaml
symbols.yaml
mappings.yaml
-
Define your styles in
ansi_codes.yaml
. For example:ANSI_CODES: green: "\u001b[38;2;80;250;123m" red: "\u001b[38;2;255;85;85m" bold: "\u001b[1m" # etc...
-
Define your symbols in
symbols.yaml
. For example:SYMBOLS: checkmark: "✔" cross: "✘" dot: "•" # etc...
-
Map them in
mappings.yaml
to CLI concepts, for example:INTERPRETATION: status_accepted: style: "green,bold" prefix: "checkmark,space" suffix: "" # more mappings... SUBMISSION: # define how you want accepted/wrong-answer to look status_accepted: style: "green,bold" prefix: "checkmark,space" suffix: "" status_wrong_answer: style: "red,bold" prefix: "cross,space" suffix: "" # etc...
-
Set your theme by running:
leetcode theme mycooltheme
and the CLI will re-load all YAML files from your new theme folder.
- Be sure to define all keys in
mappings.yaml
. If you omit something likestatus_accepted
, it will throw an error when encountered. - If you only want to override a few symbols, you still must define or copy the required sections (
INTERPRETATION
,SUBMISSION
,PROBLEMSET
, etc.) so the CLI can find every key it needs. - The
ansi_codes.yaml
must have anANSI_CODES
top-level key. Similarly,symbols.yaml
must have aSYMBOLS
top-level key. - You can always revert to the built-in
default
theme using:leetcode theme default
THEME.CONFIGURATION.mov
Command | Description |
---|---|
list |
Display a paginated list of problems, optionally filtered. |
show |
Show details for a specific problem by ID or slug. |
random |
Show a random problem, optionally filtered by difficulty and tags. |
create |
Create a new solution file from a given ID/slug with starter code. |
test |
Test your local solution file against example testcases. |
submit |
Submit your local solution file to LeetCode. |
stats |
View your LeetCode stats and calendar. |
config |
Set or display configuration options (cookie, username, language). |
theme |
Switch or list available color-symbol themes. |
download-problems |
Cache entire problem metadata locally. |
|
Use leetcode <COMMAND> --help
for more details or additional flags on each command.
leetcode list [--difficulty DIFFICULTY] [--tag TAG] [--limit LIMIT] [--page PAGE]
- Description: Lists problems from the Leetcode problemset.
- Options:
--difficulty
(optional): Filter byEASY
,MEDIUM
, orHARD
.--tag
(optional, repeatable): Filter by specific tag(s) likearray
,binary-search
.--limit
(default: 50): Number of problems per page.--page
(default: 1): Page number to display.
LIST.COMMAND.mov
leetcode show <IDENTIFIER> [--include SECTIONS...]
- Description: Displays detailed information for a specific problem.
- Parameters:
<IDENTIFIER>
: Either a numeric ID (frontend ID) or a title slug.
- Options:
--include
(optional, repeatable): Override default display sections (e.g.,title
,tags
,langs
,description
,examples
,constraints
).
SHOW.COMMAND.mov
leetcode random [--difficulty DIFFICULTY] [--tag TAG] [--include SECTIONS...]
- Description: Shows a random problem, optionally filtered by difficulty and/or tag(s).
- Options:
--difficulty
(optional): Filter byEASY
,MEDIUM
, orHARD
.--tag
(optional, repeatable): Filter by specific tag(s).--include
(optional, repeatable): Override default display sections (as inshow
).
RANDOM.COMMAND.mov
leetcode create <IDENTIFIER>
- Description: Creates a local solution file with a starter code snippet for a given problem.
- Parameters:
<IDENTIFIER>
can be:- Omitted (uses last shown problem + default language).
- A numeric ID (e.g.,
1
). - A slug (e.g.,
two-sum
). - Any of the above plus a file extension (e.g.,
two-sum.cpp
).
- Usage Examples:
leetcode create
leetcode create 1
leetcode create two-sum.cpp
leetcode create 1.two-sum.py
CREATE.COMMAND.mov
leetcode test <FILEPATH>
- Description: Tests a local solution file against the problem’s built-in example testcases.
- Parameters:
<FILEPATH>
: Must follow the formatid.title_slug.file_extension
, for example1.two-sum.py
.
- Notes: Displays test results (passed/failed testcases, output, errors, etc.) according to your formatting config.
TEST.COMMAND.mov
leetcode submit <FILEPATH>
- Description: Submits a local solution file to LeetCode and shows the real-time result.
- Parameters:
<FILEPATH>
: Must follow the formatid.title_slug.file_extension
, for example15.3sum.cpp
.
SUBMIT.COMMAND.mov
leetcode stats [USERNAME] [--include SECTIONS...]
- Description: Fetches and displays your LeetCode profile statistics (e.g., number of solved problems) and optional submission calendar.
- Parameters:
[USERNAME]
: If omitted, uses the username from config.
- Options:
--include
(optional, repeatable): Choose sections to display (e.g.,stats
,calendar
).
STATS.COMMAND.mov
leetcode config [KEY] [VALUE]
- Description: Manages global CLI settings such as your LeetCode session cookie, default username, or default language.
- Usage Examples:
leetcode config
— lists all current config values.leetcode config cookie <SESSION_COOKIE>
leetcode config username <USERNAME>
leetcode config language python
CONFIG.COMMAND.mov
leetcode theme [THEME_NAME]
- Description: Lists available themes or sets a new theme for colored output and symbols.
- Parameters:
[THEME_NAME]
: Name of the theme folder under~/.leetcode/themes
.
THEME.COMMAND.mov
leetcode download-problems
- Description: Caches problem metadata locally (IDs, slugs, etc.) so that commands like
show
orcreate
work offline or faster. - Notes: The metadata is stored in
~/.leetcode/problems_metadata.json
.
DOWNLOAD-PROBLEMS.COMMAND.mov
We welcome contributions! Please follow these steps:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Note: This is an unofficial tool not affiliated with LeetCode. Use at your own discretion.