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 with separate color, symbol, and style definitions
- Configurable section spacing and layout via theme files
- Raw style mode (
-r) to reveal theme keys for easy customization - Configurable default language and user preferences
-
Developer Experience
- Verbose logging (
-v) for debugging API calls and internal state - Pre-commit hooks with Ruff linting/formatting and conventional commits
- Verbose logging (
- Python 3.11+
- pip package manager
# Clone repository
git clone https://github.com/michal-pielka/leetcode_cli
cd leetcode-cli
# Install as global package
pip install .list-show-test-submit.mp4
- Initialize Configuration
To authenticate, paste your full cookie string from the LeetCode website. Open your browser's DevTools (F12) β Application β Cookies β https://leetcode.com, then copy the entire cookie header value (it starts with csrftoken=...;LEETCODE_SESSION=...).
leetcode config cookie "csrftoken=abc123;LEETCODE_SESSION=xyz789..."
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.pyConfiguration 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.
These flags are available on every command:
| Flag | Description |
|---|---|
-v, --verbose |
Enable verbose logging (debug-level) to stderr. |
-h, --help |
Show help for any command. |
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.
theming.mp4
The CLI uses a theming system built around three YAML files per theme:
- ansi_codes.yaml β Defines named ANSI escape codes (colors and text styles like
bold,italic, or RGB values). - symbols.yaml β Defines named symbols (e.g.,
checkmark,cross,square) used as icons. - styles.yaml β Maps semantic elements to a
style(comma-separated names fromansi_codes.yaml) and anicon(a name fromsymbols.yaml). Also contains alayoutsection for output formatting options likesection_spacing.
Every command that produces styled output supports -r/--raw-style. Instead of applying colors, it prints the theme key that controls each element:
leetcode show two-sum -rThis outputs labels like [text.title], [difficulty.easy], [status.accepted] inline with the content, so you know exactly which entry in styles.yaml to edit.
-
Create a folder under
~/.leetcode/themes/named after your theme, e.g.~/.leetcode/themes/mycooltheme. -
Add the three YAML files inside it:
ansi_codes.yaml,symbols.yaml,styles.yaml. -
Define colors in
ansi_codes.yaml:
ANSI_CODES:
green: "\u001b[38;2;80;250;123m"
red: "\u001b[38;2;255;85;85m"
bold: "\u001b[1m"- Define symbols in
symbols.yaml:
SYMBOLS:
checkmark: "β"
cross: "β"
dot: "β’"- Define styles in
styles.yaml, mapping semantic elements to colors and icons:
status:
accepted: { style: "green,bold", icon: "checkmark" }
wrong_answer: { style: "red,bold", icon: "cross" }
difficulty:
easy: { style: "green,bold", icon: "" }
medium: { style: "yellow,bold", icon: "" }
hard: { style: "red,bold", icon: "" }
text:
title: { style: "white,bold", icon: "" }
description: { style: "white", icon: "" }
layout:
section_spacing: 2The layout.section_spacing value controls the number of blank lines between sections in commands like show and random.
- Activate your theme:
leetcode theme mycooltheme- All keys referenced by the CLI must be defined in
styles.yaml. Missing keys will raise an error at render time. ansi_codes.yamlmust have anANSI_CODEStop-level key;symbols.yamlmust have aSYMBOLStop-level key.- Revert to the built-in theme at any time:
leetcode theme default| 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] [-r]- 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.-r,--raw-style: Show theme style keys instead of colors.
leetcode show <IDENTIFIER> [--include SECTIONS...] [-r]- 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).-r,--raw-style: Show theme style keys instead of colors.
leetcode random [--difficulty DIFFICULTY] [--tag TAG] [--include SECTIONS...] [-r]- 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).-r,--raw-style: Show theme style keys instead of colors.
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 createleetcode create 1leetcode create two-sum.cppleetcode create 1.two-sum.py
leetcode test <FILEPATH> [--include SECTIONS...] [-r]- 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.
- Options:
--include(optional, repeatable): Override default display sections.-r,--raw-style: Show theme style keys instead of colors.
- Notes: Displays test results (passed/failed testcases, output, errors, etc.) according to your formatting config.
leetcode submit <FILEPATH> [--include SECTIONS...] [-r]- 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.
- Options:
--include(optional, repeatable): Override default display sections.-r,--raw-style: Show theme style keys instead of colors.
leetcode stats [USERNAME] [--include SECTIONS...] [-r]- 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).-r,--raw-style: Show theme style keys instead of colors.
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
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.
leetcode download-problems- Description: Caches problem metadata locally (IDs, slugs, etc.) so that commands like
showorcreatework offline or faster. - Notes: The metadata is stored in
~/.leetcode/problems_metadata.json.
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.