Delete your old messages from Telegram groups
tgsweep finds your messages, comments on posts and reactions in groups. You select the chats, and the program deletes only what is yours.
Everything runs on your computer: the program talks only to Telegram and sends nothing anywhere else.
Free and open source. For Windows, macOS and Linux.
? Which of your messages to delete? Older than 7 days Looking for your messages in groups and your comments on posts. In large chats this can take a few minutes. Search took 50 s, 21 chats checked. Left alone: private chats and bots (never opened): 3 chats you created (skipped so your own group is not emptied): 1 channels (delete your own posts in Telegram itself, comments on posts are searched separately): 1 ? Select the chats to delete your messages from: (arrows move, space selects, a selects all, Enter continues)
How to install and run
You will need a computer, a phone with Telegram and about fifteen minutes the first time. After that, one command and a QR code are enough.
Once: installation
-
Open a terminal
Windows
Press the Windows key, type PowerShell and open “Windows PowerShell”. On Windows 11 the Terminal app works too.
This is a window for commands. Paste a command from this page into it with Ctrl+V or a right click, then press Enter.
macOS
Press Cmd+Space, type Terminal and press Enter.
This is a window for commands. Paste a command from this page into it with Cmd+V, then press Enter.
Linux
Open a terminal, on many systems it is Ctrl+Alt+T. To paste: Ctrl+Shift+V.
-
Install uv
uv installs Python programs, it is made by Astral. You do not need to install Python separately: uv downloads it by itself.
Windows
powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/ install.ps1 | iex" At the end you will see the line everything's installed!
macOS and Linux
curl -LsSf https://astral.sh/uv/install.sh | shmaria@MacBook ~ % curl -LsSf https://astral.sh/uv/install.sh | sh downloading uv 0.13.10 aarch64-apple-darwin installing to /Users/maria/.local/bin uv uvx everything's installed! To add $HOME/.local/bin to your PATH, either restart your shell or run: source $HOME/.local/bin/env (sh, bash, zsh) source $HOME/.local/bin/env.fish (fish)This is how it looks on a Mac. What matters is the end: everything's installed! The source line is the next step. -
Make uv available in this window
The installer set up uv for new terminal windows. In this window, enable it with one command:
Windows
$env:Path = "$HOME\.local\bin;$env:Path"If the command does not work, open a new PowerShell window as in step 1 and continue there.
macOS and Linux
source $HOME/.local/bin/envIf the terminal says there is no such file, open a new terminal window and continue there.
-
Install tgsweep
uv tool install tgsweepuv downloads the program from PyPI, the public catalog of Python programs, together with everything it needs.
maria@MacBook ~ % uv tool install tgsweep Downloading cpython-3.15.2-macos-aarch64-none (download) (26.6MiB) Downloaded cpython-3.15.2-macos-aarch64-none (download) Resolved 16 packages in 9.38s … 22 more lines: what was downloaded and installed Installed 1 executable: tgsweep
The last line Installed 1 executable: tgsweep means everything is ready. On Windows the output is almost the same. If the terminal says it does not know the uv command (command not found or “is not recognized as the name of a cmdlet”), most likely step 3 was skipped. Do it, and if that does not help, repeat step 2.
Once: a key for Telegram
-
Get an api_id and api_hash
Third-party Telegram programs need their own key. It is free, and Telegram itself issues it in a couple of minutes.
- Open my.telegram.org and enter your phone number in international format, for example +15551234567. The code comes to Telegram itself, not by SMS.
- Choose API development tools.
- Fill in the form. App title and Short name can be anything in Latin letters, for example mysweep. Platform: Desktop. Click Create application.
- The page shows App api_id (a number) and App api_hash (32 characters). Keep the tab open, you will need them in step 6.
Do not show or publish your api_hash: it is your personal key.
Every time: cleanup
-
Run tgsweep
tgsweepThe first time, the program asks for the api_id and api_hash. Paste them one by one and press Enter after each. The api_hash stays hidden as you type, that is intended. The key is saved on this computer, and the program will not ask for it again.
maria@MacBook ~ % tgsweep tgsweep needs an api_id and api_hash. Telegram issues them for free: 1. Open https://my.telegram.org and sign in with your phone number. 2. Choose API development tools and create an application, any name will do. 3. Copy App api_id and App api_hash here. They are saved only on this computer. api_id: 12345678 api_hash (hidden while typing): -
Sign in with a QR code
A QR code appears in the terminal. On your phone, open Telegram: Settings > Devices > Link Desktop Device, and point the camera at the code.
Signing in to Telegram. tgsweep works only with groups and channels and never opens private chats. Scan the code with your phone: Telegram > Settings > Devices > Link Desktop Device. The code changes about every 30 seconds, a new one appears here.
The code here is covered with a label: the real one appears only in your terminal. Once you are signed in, it disappears from the screen. If you have Two-Step Verification turned on, the program asks for that password too. If scanning does not work, run
tgsweep --code: the program asks for your phone number, and the sign-in code usually comes to Telegram on your other device.Scan only the code from your own terminal. If you scan a QR code that someone sent you, you give that person access to your account.
-
Choose which messages to delete
Pick the age with the arrows and press Enter. For example, “Older than 7 days” keeps the last week of conversation.
Account: Maria (@maria_demo) ? Which of your messages to delete? (arrows and Enter) All, including today's Older than 1 day Older than 2 days » Older than 7 days Older than 30 days
Then the program searches for your messages. In large chats the search takes a few minutes. At the bottom you can see which chat it is checking. The next search is faster.
? Which of your messages to delete? Older than 7 days Looking for your messages in groups and your comments on posts. In large chats this can take a few minutes. / 0:19 Chat 9 of 21 · looking for your messages, 60 found so far · Spanish club
-
Select the chats
Space selects a chat, a selects all, Enter continues. At first no chat is selected. Above the list, the program tells you what it skipped: private chats, bots, groups you created, and channels.
Search took 50 s, 21 chats checked. Left alone: private chats and bots (never opened): 3 chats you created (skipped so your own group is not emptied): 1 channels (delete your own posts in Telegram itself, comments on posts are searched separately): 1 ? Select the chats to delete your messages from: (arrows move, space selects, a selects all, Enter continues) ● Building neighbors: 37 messages » ● Book club: 12 messages, 4 reactions ○ Morning runs: 8 messages ○ Neighborhood notices: 3 messages, 2 reactions
-
Confirm with the number
The program shows how much it will delete in total and asks you to type that number. Deleted messages cannot be restored, so without the number it touches nothing.
To be deleted: 49 messages, 4 reactions in 2 chats. This cannot be undone. It will take about 1 minute. ? To confirm, type the number 53: 53
Deletion runs with pauses so that Telegram does not limit your account. If Telegram asks to wait, the program waits and says so. To stop, press Ctrl+C (on a Mac it is also Ctrl, not Cmd): the program finishes the current request and finds the rest on the next run.
? To confirm, type the number 53: 53 | 0:04 Deleting: 37 of 53 (69%) · Building neighbors
-
Sign out on this computer
At the end the program asks whether to sign out on this computer. Press Enter, which means “yes”. It is safer: the session file opens your whole account. Next time you will need the QR code again, but not the key.
Done. Messages deleted: 49, comments deleted: 0, reactions removed: 4. Log without message texts: ~/Library/Application Support/tgsweep/logs/actions.jsonl ? Sign out on this computer? Next time you will need the QR code again. Yes You are signed out on this computer.
Update, sign out, uninstall
Update the program
One command downloads and installs the latest version:
uv tool upgrade tgsweepIf you installed tgsweep earlier from the GitHub archive link, switch to the PyPI version once:
uv tool install --force tgsweepSign out later
If you answered “no” at the end, sign out like this:
tgsweep --logoutOr on your phone: Settings > Devices > the tgsweep session > Terminate Session.
Uninstall
Sign out and remove the program:
tgsweep --logoutuv tool uninstall tgsweepThen delete the folder with the key and the log:
Windows
Remove-Item -Recurse -Force "$env:LOCALAPPDATA\tgsweep"macOS
rm -rf "$HOME/Library/Application Support/tgsweep" Linux
rm -rf "$HOME/.local/share/tgsweep"You can keep uv: it does not run anything by itself. To remove it too, see the uv documentation.
What tgsweep never does
- never opens private chats, bots, Saved Messages or the Telegram service chat;
- never touches other people’s messages, even if you are a group admin;
- never touches groups you created or your posts in channels;
- deletes nothing until you select chats and confirm;
- sends nothing anywhere except requests to Telegram: the program has no server and no analytics.
Why your own key
The key, the session file and the log stay only on your computer. The program has no server of its own, and the author has no access to your account. A shared key cannot be hidden in open source code, and Telegram blocks keys that are published or abused, so the program would stop working for everyone at once. With your own key, that cannot happen.
Everything is in the folder %LOCALAPPDATA%\tgsweep.
Everything is in the folder ~/Library/Application Support/tgsweep.
Everything is in the folder ~/.local/share/tgsweep.
Check it yourself
The code is open: github.com/umbrella-at/tgsweep. If you do not read code, give the link to any AI chat and ask what the program sends and what it deletes. The repository has tests that keep the program from gaining extra abilities: writing messages, leaving groups, deleting other people’s messages. PyPI shows which repository and which build each version came from.
FAQ
Will my account get banned?
Deleting your own messages is a normal thing to do in Telegram. The program deletes with pauses and waits whenever Telegram asks it to. But it is unofficial, and nobody can give guarantees on Telegram’s behalf.
Does the program see my private chats?
Telegram sends the list of all chats, private ones included, with the last message of each chat. The program skips private chats right away: it does not read their history, delete anything in them or save anything about them. The same goes for bots, Saved Messages and the Telegram service chat.
What about other people’s messages? I am an admin in a couple of groups.
Only yours, even if you are an admin. Groups you created yourself are skipped entirely, so that you do not empty your own group.
Will the messages disappear for everyone?
Yes, as if you deleted them yourself in Telegram. They cannot be restored, so before deleting the program asks you to type the number. The log keeps only chat and message numbers, no texts.
How long does it take?
The search in large chats takes a few minutes. Before deleting, the program tells you roughly how many minutes it will take. It deletes messages in batches of 100 with a 4 second pause and removes reactions one by one: a thousand messages take less than a minute, a hundred reactions about seven minutes. If Telegram asks to wait, it takes longer.
Will it find my old reactions?
It looks for reactions only in messages from the last 90 days: to find your reaction, it has to go through the chat message by message, and that is slow. Your own messages and comments it finds from any time.
What if I close the window in the middle of deleting?
What was deleted stays deleted, and the program finds the rest on the next run. It is better to press Ctrl+C: it finishes the current request and stops.
my.telegram.org shows ERROR when I create the application
It happens. Usually it helps to turn off your VPN and ad blocker, fill in the fields in Latin letters and try again later or in another browser.
Why a terminal and not a regular app?
The program is small, and this way it is easier to check: it installs with one command from PyPI, where an open build script on GitHub publishes it. No installer with who knows what inside.
The program speaks Russian
tgsweep uses your system language: Russian on a Russian system, English otherwise. To switch to English: tgsweep --lang en. The choice is remembered, you do not need to repeat it.
Is this a Telegram program?
No. tgsweep is made by an independent developer and is not affiliated with Telegram.