# How to Add a New LeetCode Problem Animation to the Repository: CLI Workflow Explained

> Easily add new LeetCode problem animations to MisterBooo/LeetCodeAnimation using the anima.py CLI. Generate new problem files efficiently with this quick guide.

- Repository: [吴师兄学算法/LeetCodeAnimation](https://github.com/MisterBooo/LeetCodeAnimation)
- Tags: how-to-guide
- Published: 2026-03-01

---

**Use the [`anima.py`](https://github.com/MisterBooo/LeetCodeAnimation/blob/main/anima.py) CLI manager to scaffold a new problem by running `python anima.py new <id> "<title>"`, which auto-generates the required folder structure and markdown template.**

The LeetCodeAnimation repository provides a Python-based automation tool that eliminates manual folder creation when contributing visual explanations. By using the built-in scaffolding system, contributors can add a new LeetCode problem animation in seconds while ensuring consistent directory layout across all submissions.

## Prerequisites and Setup

Before generating new problem skeletons, install the required Python dependency. The automation script relies on the `fire` library declared in [`requirements.txt`](https://github.com/MisterBooo/LeetCodeAnimation/blob/main/requirements.txt).

```bash
pip install -r requirements.txt

```

This single dependency powers the CLI interface defined in [`anima.py`](https://github.com/MisterBooo/LeetCodeAnimation/blob/main/anima.py), the repository's entry point.

## Scaffolding a New Problem with the CLI

The fastest way to add a new LeetCode problem animation is through the command-line interface. The `new` method in [`anima/__init__.py`](https://github.com/MisterBooo/LeetCodeAnimation/blob/main/anima/__init__.py) forwards arguments to the `create_solution` function implemented in [`anima/create.py`](https://github.com/MisterBooo/LeetCodeAnimation/blob/main/anima/create.py).

Run the following command, replacing `<id>` with the LeetCode problem number and `"<title>"` with the exact problem name:

```bash
python anima.py new 1 "Two Sum"

```

Upon execution, the console outputs the creation path:

```

题解框架创建完毕，位于文件夹 /path/to/repo/0001-Two-Sum

```

## How the Directory Structure Is Generated

The scaffolding process relies on deterministic path manipulation through two core classes defined in [`anima/model.py`](https://github.com/MisterBooo/LeetCodeAnimation/blob/main/anima/model.py).

**Slug Generation**: The `ProblemInfo.title_slug` property converts the numeric ID and title into a standardized directory name (e.g., `0001-Two-Sum`). This ensures every problem follows the same naming convention.

**Folder Creation**: The `Solution._create_dirs` method (also in [`anima/model.py`](https://github.com/MisterBooo/LeetCodeAnimation/blob/main/anima/model.py)) builds three subdirectories:

- `Animation/` – Stores visual assets (`Animation.m4v`, `Animation.gif`)
- `Article/` – Contains the markdown explanation
- `Code/` – Houses reference implementations in various languages

## Customizing the Generated Content

After scaffolding, you must populate the placeholder files. The system copies a boilerplate markdown template from [`template/template.md`](https://github.com/MisterBooo/LeetCodeAnimation/blob/main/template/template.md) via `get_md_template_path` in [`anima/base.py`](https://github.com/MisterBooo/LeetCodeAnimation/blob/main/anima/base.py) into `Article/<slug>.md`.

Open the generated markdown file and fill in the sections:

```markdown

# LeetCode 第 1 号问题：两数之和

## 题目描述

...

## 题目解析

...

## 动画理解

![](../Animation/Animation.gif)

## 参考代码

```cpp
class Solution { … }

```

```

Replace the placeholder `../Animation/Animation.gif` reference with your actual animation file. Place the final video or GIF into the `Animation/` folder, and add any reference implementations to the `Code/` directory.

## Programmatic Alternative

If you prefer calling the manager from Python scripts rather than the shell, import the `Anima` class directly:

```python
from anima import Anima

# Scaffold problem #42

Anima().new('42', 'Trapping Rain Water')

```

This programmatic approach executes the same `create_solution` logic found in [`anima/create.py`](https://github.com/MisterBooo/LeetCodeAnimation/blob/main/anima/create.py) without shell invocation.

## Key Source Files Reference

Understanding these files helps when debugging or extending the scaffolding behavior:

- **[`anima.py`](https://github.com/MisterBooo/LeetCodeAnimation/blob/main/anima.py)** – Entry point that wires the CLI with the `fire` library
- **[`anima/create.py`](https://github.com/MisterBooo/LeetCodeAnimation/blob/main/anima/create.py)** – Implements `create_solution`, the core scaffolding logic
- **[`anima/model.py`](https://github.com/MisterBooo/LeetCodeAnimation/blob/main/anima/model.py)** – Defines `ProblemInfo` (slug generation) and `Solution` (directory creation via `_create_dirs`)
- **[`anima/base.py`](https://github.com/MisterBooo/LeetCodeAnimation/blob/main/anima/base.py)** – Provides `get_md_template_path` for locating project resources
- **[`template/template.md`](https://github.com/MisterBooo/LeetCodeAnimation/blob/main/template/template.md)** – Boilerplate markdown inserted into every new article
- **[`Readme.md`](https://github.com/MisterBooo/LeetCodeAnimation/blob/main/Readme.md)** – Top-level summary that automatically indexes newly created problem folders

## Summary

- **Install dependencies** via `pip install -r requirements.txt` to access the `fire` CLI framework.
- **Run `python anima.py new <id> "<title>"`** to invoke `create_solution` in [`anima/create.py`](https://github.com/MisterBooo/LeetCodeAnimation/blob/main/anima/create.py) and generate the folder structure.
- **Edit the scaffolded files** in `Article/`, `Animation/`, and `Code/` directories to complete your contribution.
- **Rely on deterministic paths** – the `ProblemInfo.title_slug` logic ensures your submission integrates automatically with the repository's indexing system.

## Frequently Asked Questions

### What Python version is required to run the anima.py script?

The script uses standard Python 3 features and requires only the `fire` library listed in [`requirements.txt`](https://github.com/MisterBooo/LeetCodeAnimation/blob/main/requirements.txt). Any Python 3.6+ environment should execute the scaffolding commands without compatibility issues.

### Can I manually create the folder structure instead of using the CLI?

While possible, manual creation risks inconsistency with the `ProblemInfo.title_slug` format expected by the repository's indexing logic. The CLI ensures the `000X-Problem-Name` directory pattern and creates required placeholder files like `Animation.gif` that the [`Readme.md`](https://github.com/MisterBooo/LeetCodeAnimation/blob/main/Readme.md) summary tables reference.

### Where does the markdown template come from?

The template is stored at [`template/template.md`](https://github.com/MisterBooo/LeetCodeAnimation/blob/main/template/template.md) in the repository root. During execution, `get_md_template_path` in [`anima/base.py`](https://github.com/MisterBooo/LeetCodeAnimation/blob/main/anima/base.py) resolves this location and copies its contents into the new `Article/<slug>.md` file, providing consistent formatting for all problem explanations.

### Do I need to update the root Readme.md after adding a new problem?

No. Because the scaffolding creates folders following the deterministic `000X-Title` slug pattern, the repository's summary tables in [`Readme.md`](https://github.com/MisterBooo/LeetCodeAnimation/blob/main/Readme.md) automatically detect and display newly added problems without manual index updates.