Skip to content

rickytang666/leetrag

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

110 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LeetRAG

LeetCode + RAG = solve what actually matters.


LeetCode's search bar is useless.

Stop worrying about what to practice, just open LeetRAG in your terminal like Claude Code, except it has all of the LeetCode problems and learns from your history.

leetrag_demo.mp4

Watch it on YouTube.

Setup

1. Install Go

brew install go        # mac
sudo apt install go    # ubuntu/debian

or go.dev/dl.

2. Clone and build

git clone https://github.com/rickytang666/leetrag
cd leetrag
go build -o leetrag .

3. API key

Sign up at openrouter.ai and create a key for LLM, embeddings, and hints.

4. Config

./leetrag config

Follow the prompts to set your OpenRouter API key (required) and LeetCode session token (optional, enables personal history).

To get your LeetCode session token: log into leetcode.com, DevTools > Application > Cookies, copy LEETCODE_SESSION.

5. Ingest

./leetrag ingest

Scrapes problems, (optionally) generates retrieval hints, and embeds them.

First run takes time; subsequent runs are incremental.

To reset from scratch:

./leetrag ingest --reset

Note

By default, ingest asks if you want to generate "approach hints"—short algorithmic cues for every problem to improve semantic retrieval. These take a very long time:

  • Free tier model: ~15-20s hours to finish
  • Paid tier model: ~2-3 hours to finish

Hints are optional and not perfect (they only bridge keyword gaps in retrieval). Skip if you just want to start; generate later with ./leetrag hint.

Advanced: Run individual pipeline steps
./leetrag scrape        # scrape problems
./leetrag hint          # generate hints
./leetrag embed         # embed into vector store

Each step is resumable. Use --reset to wipe and restart a step.

Usage

./leetrag chat

Chat naturally:

> i keep failing sliding window, what should i practice?
> what's the difference between #3 and #76?
> give me a hard graph problem i haven't solved
> just solved #207

Keyboard Shortcuts:

  • Ctrl+C: Exit
  • ESC (while thinking): Cancel request
  • ESC twice: Clear input

Slash Commands:

Type / to see available:

  • /clear: Clear conversation
  • /history: Show solve/attempt counts
  • /refresh: Refetch LeetCode history
  • /debug: Show retrieved context + rewritten query
  • /exit: Exit

Warning

If you see "session expired" when running /refresh command in the chat, re-copy the LEETCODE_SESSION cookie and update your config.

Notes

  • Premium problems are labeled [premium]: need premium LeetCode account
  • History is cached 6 hours; use /refresh to force update

Tech Stack

Go, Cobra, Bubbletea, Lipgloss, Glamour, SQLite, chromem-go, OpenRouter.

License

MIT


views badge

About

🤖 CLI LeetCode agent. Semantic search + your history = personalized problem selection and guidance.

Topics

Resources

License

Stars

Watchers

Forks

Contributors

Languages