DEV Community

Nathanael FETUE
Nathanael FETUE

Posted on

I built a tool that auto-pushes your accepted LeetCode solutions to GitHub with AI-generated commit messages

The problem

Every time I solved a LeetCode problem, I had to manually copy the solution to GitHub. Boring, repetitive, easy to forget. So I automated it.

What it does

leetcode-sync is a self-hosted tool that detects when you submit an accepted solution on LeetCode and automatically:

  • Generates a file header with algorithm explanation + time/space complexity (via Claude AI)
  • Creates a descriptive git commit message
  • Pushes the file to a structured GitHub repo organized by year and month
  • Updates a README with your Easy/Medium/Hard stats

The result

Your GitHub repo ends up looking like this:

2026/
  04-april/
    20260403_two-sum_easy.py
    20260403_add-two-numbers_medium.cpp
Enter fullscreen mode Exit fullscreen mode

With commit messages like:

solve(easy): two-sum - hash map, time O(n), space O(n)
solve(medium): longest-substring - sliding window, time O(n), space O(k)
Enter fullscreen mode Exit fullscreen mode

And each file has an auto-generated header:

"""
Problem    : Two Sum
Difficulty : Easy
URL        : https://leetcode.com/problems/two-sum/
Approach   : Hash map to store complements. For each number, check if its complement exists. If yes, return indices.
Time       : O(n)
Space      : O(n)
Runtime    : 0 ms
Memory     : 13.4 MB
"""
Enter fullscreen mode Exit fullscreen mode

How it works

LeetCode submit (Accepted)
    → Tampermonkey userscript (intercepts the request in your browser)
    → POST https://your-server.com/leetcode-sync/submit
    → FastAPI server (running in Docker)
        → Claude API (generates header + commit message)
        → GitHub API (pushes file + updates README)
Enter fullscreen mode Exit fullscreen mode

The interesting technical challenge was intercepting LeetCode's network requests. Chrome's Manifest V3 blocks Tampermonkey from hooking window.fetch directly — the fix was using unsafeWindow to access the page's actual fetch and XMLHttpRequest before LeetCode's code runs.

Stack

  • FastAPI — lightweight Python server
  • Tampermonkey — browser userscript to intercept submissions
  • Claude API — generates the file headers and commit messages
  • GitHub API — pushes files directly without needing git locally

Try it

The project is fully open source and self-hosted — your code never goes through any third-party service except the Claude API for generation.

GitHub: NathanaelFetue/leetcode-sync

Happy to answer questions in the comments.

Top comments (1)

Collapse
 
nathanff profile image
Nathanael FETUE

Good