Local utility to detect “trading-related” Telegram channels/groups and help you leave them.
- Runs locally on Windows (manual weekly run)
- Uses Telethon (Telegram user API)
- Generates a local HTML review report
- Leaves only what you explicitly select
- Install Docker Desktop (WSL2 backend).
- In PowerShell:
cd D:\Files\TelegramCleanup
docker compose run --rm telegram-cleanup python tg_cleanup.py scanThen open out\report.html.
To apply a selection:
docker compose run --rm telegram-cleanup python tg_cleanup.py apply out/selection.jsonInstall Python 3.11+ from https://www.python.org/downloads/
git clone https://github.com/CaptainVC/telegram-cleanup
cd telegram-cleanup
python -m pip install -r requirements.txtCopy .env.example → .env and fill:
TG_API_IDTG_API_HASH
Get them from: https://my.telegram.org/apps
python tg_cleanup.py scanFirst run will ask for OTP (and 2FA password if enabled). It stores a local session file so you won’t OTP every time.
Outputs:
out/report.htmlout/candidates.json
Open out/report.html, select chats to leave, export out/selection.json, then:
python tg_cleanup.py apply out/selection.json- No secrets are committed.
- Session files and outputs are ignored by git.
MIT
There are two different things involved:
- Telegram API app credentials (in
.env)
TG_API_IDandTG_API_HASHcome from https://my.telegram.org/apps- They identify your developer app so Telethon can connect.
- Your account login (entered interactively on first run)
- Phone number + OTP code (and 2FA password if enabled) are used to sign into your Telegram user account.
- After the first successful login, Telethon stores a local session file under:
out/session/telegram_cleanup.session
- Because the project directory is mounted into Docker, the session persists on your machine and future runs should not ask for OTP again.
.envdoes not replace OTP/2FA. It only provides the API app credentials.
You can safely stop/remove containers in Docker Desktop.
Your Telegram login persists because Telethon stores a session file on your machine:
out/session/telegram_cleanup.session
As long as that file remains, you generally won’t need OTP again even if you run the tool next month.
It will ask for OTP again if you delete the session file, revoke Telegram sessions (Settings → Devices), or Telegram invalidates the session.
List running containers:
docker psStop a running container:
docker stop <container_id>Remove a stopped container:
docker rm <container_id>