Automatically save your LeetCode submissions to GitHub — from any device, without keeping a computer on.
LeetCode Cloud Sync is not affiliated with or endorsed by LeetCode.
- What it does
- Architecture and event-driven flow
- Repository architecture: one repo vs. two repos
- Technology stack
- Supported configuration options
- Prerequisites
- Fork or clone the project
- Configure your LeetCode account
- Configure the destination repository
- Add GitHub Actions secrets and variables
- Enable the workflow and run a manual sync
- Inspect workflow logs safely
- Cloudflare Worker setup (optional event-driven architecture)
- Difficulty folders and timestamped files
- How duplicate submissions are handled
- Run tests locally
- Troubleshooting
- Security and privacy
- Contributing and reporting vulnerabilities
- Disable scheduled synchronization
- Running locally with Windows Task Scheduler
- License and related project
LeetCode Cloud Sync is an automated synchronization system that detects accepted LeetCode submissions and commits them directly into a GitHub repository as clean Markdown files.
Because it runs in the cloud (via GitHub Actions and Cloudflare Workers), synchronization works regardless of which device you submitted from — phone, laptop, or tablet. No browser extension required. No local machine needed to stay online.
| Feature | Browser Extension | LeetCode Cloud Sync |
|---|---|---|
| Requires your device to be on | Yes | No |
| Works from any device (phone/tablet) | No | Yes |
| Runs unattended | No | Yes |
| Stores solutions in GitHub | Varies | Yes |
| Open source and auditable | Varies | Yes |
graph TD
A[LeetCode API] -->|Polls every 2m| B[Cloudflare Worker]
B -->|Check Seen KV| C{New Submission?}
C -->|Yes| D[Cloudflare Queue]
C -->|No| E[Skip]
D -->|Consume Batch| F[GitHub Actions workflow_dispatch]
D -->|Failure / Retry| G[Dead-Letter Queue DLQ]
F -->|Target SUBMISSION_ID| H[Python Sync Engine]
H -->|Render Markdown & Deduplicate| I[Submission Archive GitHub Repo]
- Cloudflare Worker: Polling engine running on Cron triggers (
*/2 * * * *). - Cloudflare KV: Durable store tracking seen submission IDs (
seen:<submissionId>). - Cloudflare Queues & DLQ: Reliable message queue with exponential backoff retries and Dead-Letter Queue fallback.
- GitHub Actions: Automated runner triggered via
workflow_dispatchwith targetSUBMISSION_ID. - Python Sync Engine: Fetches submission details, renders structured Markdown, and commits to kaviyack/LEETCODE-SUBMISSIONS.
- Language: Python 3.11+, TypeScript
- Cloudflare: Cloudflare Workers, Cloudflare KV, Cloudflare Queues, Cron Triggers
- CI/CD: GitHub Actions (
workflow_dispatch, scheduled cron) - APIs: LeetCode GraphQL API, GitHub REST API (Contents & Actions)
- Testing: Pytest (Python), Vitest (TypeScript)
You can choose either setup:
Everything lives in one repository: the application source code and your solutions.
- No extra token required (
GITHUB_TOKENis automatically available). - Solutions are committed alongside the application code.
| Repository | Contents |
|---|---|
YOUR_USERNAME/leetcode-cloud-sync |
Application source, tests, CI, documentation |
YOUR_USERNAME/leetcode-submissions |
Your generated solution Markdown files only |
Benefits:
- Clean separation between tool source code and personal solutions.
- Contributors to the tool do not see your solutions.
- You can make the submissions repo public or private independently.
Public repository warning: Any solution committed to a public GitHub repository is visible to everyone, including future employers and other LeetCode users. If you want privacy, make your submissions repository private.
| Variable | Type | Required | Purpose |
|---|---|---|---|
LEETCODE_USERNAME |
Variable | Yes | Your LeetCode username |
LEETCODE_SESSION |
Secret | Yes | Browser session cookie (LEETCODE_SESSION) |
LEETCODE_CSRF_TOKEN |
Secret | Yes | CSRF token cookie (csrftoken) |
GITHUB_TOKEN |
Secret | Yes | GitHub token with Contents write permission |
SUBMISSIONS_TOKEN |
Secret | Mode B only | Fine-grained PAT for cross-repo writes |
DESTINATION_REPO |
Variable | Yes | Destination repo (owner/repo) |
GITHUB_BRANCH |
Variable | No | Target branch (default: main) |
SOLUTIONS_ROOT |
Variable | No | Solutions directory (default: solutions) |
SYNC_MODE |
Variable | No | accepted or all (default: accepted) |
FETCH_LIMIT |
Variable | No | Max submissions per run (default: 20) |
LOG_LEVEL |
Variable | No | Log level (INFO, DEBUG, etc.) |
| Variable | GitHub Actions secrets | GitHub Actions variables | Local .env |
|---|---|---|---|
LEETCODE_SESSION |
Yes | No | Yes (never commit) |
LEETCODE_CSRF_TOKEN |
Yes | No | Yes (never commit) |
SUBMISSIONS_TOKEN |
Yes | No | Yes (never commit) |
GITHUB_TOKEN |
Auto-provided | No | Yes (fine-grained PAT) |
LEETCODE_USERNAME |
No | Yes | Yes |
DESTINATION_REPO |
No | Yes | Yes |
GITHUB_BRANCH |
No | Yes | Yes |
SOLUTIONS_ROOT |
No | Yes | Yes |
SYNC_MODE |
No | Yes | Yes |
FETCH_LIMIT |
No | Yes | Yes |
LOG_LEVEL |
No | Yes | Yes |
- A GitHub account.
- A LeetCode account.
- Python 3.11+ (for local development).
- Node.js & Wrangler CLI (optional, for Cloudflare Worker deployment).
Click Fork on github.com/kaviyack/leetcode-cloud-sync.
git clone https://github.com/kaviyack/leetcode-cloud-sync.git
cd leetcode-cloud-sync
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txtCopy the example environment file and fill in your values:
cp .env.example .env
# Edit .env — do NOT commit itThe tool accesses LeetCode's GraphQL API using your browser session cookies. These are required to retrieve submission source code.
- Log in to leetcode.com in your browser.
- Open DevTools:
- Chrome/Edge:
F12→ Application tab → Storage → Cookies →leetcode.com - Firefox:
F12→ Storage tab → Cookies →https://leetcode.com
- Chrome/Edge:
- Find the cookie named
LEETCODE_SESSIONand copy its value. - Find the cookie named
csrftokenand copy its value.
These cookies are equivalent to your LeetCode password. Anyone with these values can access your account. Treat them as secrets. Do not paste them into source files, README files, issue comments, or any public place.
Session cookies typically last weeks but expire when you log out, change your password, or LeetCode invalidates them.
No extra steps needed. The built-in GITHUB_TOKEN has write access to the current repository automatically. Set DESTINATION_REPO to your repository name (e.g., YOUR_USERNAME/leetcode-cloud-sync) or leave it unset — the workflow defaults to the current repository.
- Go to github.com/new.
- Create a repository named
leetcode-submissions(or any name you prefer). - Set visibility: Public or Private.
- Initialize it with a README so the
mainbranch exists.
The built-in GITHUB_TOKEN cannot write to a different repository. You need a PAT:
- Go to GitHub → Settings → Developer settings → Personal access tokens → Fine-grained tokens.
- Click Generate new token.
- Set:
- Token name:
leetcode-submissions-write - Repository access: Only select repositories → select
leetcode-submissions
- Token name:
- Under Permissions → Repository permissions:
- Contents: Read and write
- Click Generate token and copy the value immediately.
In YOUR_USERNAME/leetcode-cloud-sync:
Settings → Secrets and variables → Actions → New repository secret
SUBMISSIONS_TOKEN: The fine-grained PAT from Step 2.
In YOUR_USERNAME/leetcode-cloud-sync:
Settings → Secrets and variables → Actions → Secrets → New repository secret
LEETCODE_SESSION: YourLEETCODE_SESSIONcookie valueLEETCODE_CSRF_TOKEN: Yourcsrftokencookie valueSUBMISSIONS_TOKEN: Your fine-grained PAT (Mode B only)
Settings → Secrets and variables → Actions → Variables → New repository variable
LEETCODE_USERNAME: Your LeetCode usernameDESTINATION_REPO: Destination repo inowner/repoformatSYNC_MODE:acceptedorall(default:accepted)GITHUB_BRANCH:main(optional)SOLUTIONS_ROOT:solutions(optional)FETCH_LIMIT:20(optional)LOG_LEVEL:INFO(optional)
If writing to the same repository: Settings → Actions → General → Workflow permissions → Read and write permissions → Save.
- Go to the Actions tab of
YOUR_USERNAME/leetcode-cloud-sync. - If prompted, click I understand my workflows, go ahead and enable them.
- Select LeetCode Cloud Sync from the left sidebar.
- Click Run workflow → Run workflow to trigger a one-time manual sync.
- Go to the Actions tab.
- Click the most recent workflow run.
- Click the Sync LeetCode Submissions job and expand Run synchronization.
The application never logs session cookies, CSRF tokens, or tokens.
To achieve automatic cloud synchronization with scheduled polling approximately every two minutes:
- Install Wrangler CLI:
npm install -g wrangler wrangler login
- Configure
worker/wrangler.tomlwith your KV Namespace ID (d2fc1d81ecbb48afba1f145a56feaecf) and non-secretGITHUB_REPOvariable (owner/repo) under[vars]. - Set required worker secrets (sensitive credentials):
wrangler secret put LEETCODE_USERNAME wrangler secret put LEETCODE_SESSION wrangler secret put LEETCODE_CSRF_TOKEN wrangler secret put GITHUB_TOKEN
- Create both the main queue and dead-letter queue (DLQ):
wrangler queues create leetcode-submission-events wrangler queues create leetcode-submission-events-dlq
- Deploy the worker and verify:
cd worker npm install wrangler deploy # Verify health endpoint: curl https://leetcode-cloud-sync-worker.<your-subdomain>.workers.dev/health
Solutions are stored under the solutions/ directory in the destination repository:
solutions/
├── easy/
│ └── 0001-two-sum/
│ └── 20261031_1200_python3_12345678.md
├── medium/
├── hard/
└── unknown/
Filename format: <YYYYMMDD>_<HHMM>_<language>_<submission_id>.md
Each file contains problem number, title, difficulty, topic tags, language, submission ID, UTC timestamp, status, runtime, memory usage, and full source code.
The deduplication state (.leetcode_sync_state.json) tracks synced submission IDs. Multiple attempts, different languages, or resubmissions are preserved without overwriting existing files.
# Python tests (138 tests)
python -m pytest tests/ -v
# TypeScript worker tests (5 tests)
cd worker && npm install && npx vitest run- Authentication failed / 403:
LEETCODE_SESSIONhas expired. Re-login and update the secret. - 403 when writing to repo: Ensure
SUBMISSIONS_TOKENhas ContentsRead and writepermission on the destination repository. - No new files appear: Check if submissions were already synced or increase
FETCH_LIMIT. - submissionList returned null: Refresh both
LEETCODE_SESSIONandLEETCODE_CSRF_TOKEN. - Rate limited (HTTP 429): Reduce
FETCH_LIMIT.
- Public repository = public solutions. Use a private submissions repository if you want privacy.
- Secrets are encrypted at rest in GitHub Actions and never printed in logs.
- Session cookies expire periodically and require manual refresh.
See CONTRIBUTING.md for contribution guidelines. For security vulnerabilities, see SECURITY.md.
To pause syncing: go to Actions → LeetCode Cloud Sync → ... → Disable workflow.
To stop permanently: delete .github/workflows/leetcode-sync.yml.
If you prefer running the background watcher locally on Windows:
- Configure your credentials securely in a local
.envfile. - Register the scheduled task at logon by running:
.\scripts\setup-task.ps1 - View logs at
logs/watcher.log. - To uninstall:
.\scripts\uninstall-task.ps1
See docs/windows-task-scheduler.md for details.
Distributed under the MIT License. See LICENSE for details.
- Main Sync Engine: kaviyack/leetcode-cloud-sync
- Submission Archive: kaviyack/LEETCODE-SUBMISSIONS