tg-cli is an open-source Telegram client that runs in your terminal. It's built for Windows Terminal, driven entirely from the keyboard with Vim-style motions, and handles 10,000+ chats without lag. Written in Python on Textual (TUI) and Telethon (Telegram MTProto API).
Use it if you live in the terminal and want Telegram there too: read and reply to chats, bulk-archive, mute or mark read with undo, forward messages, and transcribe voice messages with Google Gemini, all without touching the mouse.
- Platform: Windows 10/11, Windows Terminal, Python 3.12+
- Login: phone code or QR code, multiple accounts
- Network: SOCKS5, HTTP and MTProto proxy support
- Storage: local SQLite (WAL); secrets stay in
%APPDATA% g-cli - Try it offline:
py -m tg_cli --fakeopens a demo with 10,000 fake chats - License: MIT
tg-cli gives Telegram power users an efficient, keyboard-driven interface. Built on Textual 8.2+ and Telethon 1.42+, it keeps the UI responsive during network delays by running Telegram on a dedicated background worker thread and storing data in SQLite with WAL.
git clone https://github.com/JavohirX/tg-cli.git
cd tg-cli
py -3.12 -m pip install -e .
py -m tg_cli --fake # demo with fake data, no account needed
py -m tg_cli # real Telegram: asks for api_id / api_hash on first runOn Windows you can also double-click run.bat. It installs the package the first time (and again whenever pyproject.toml changes), then starts the client. You need your own Telegram API credentials, see Telegram API Credentials.
- Windowed Virtual Viewport: Navigates 10,000+ chats and extensive message histories smoothly without creating per-row widgets.
- Two-Thread Architecture: Textual runs the async UI event loop on the main thread; Telethon runs its own loop on a background thread. Screens communicate with SQLite and thread-safe queues—never importing Telethon directly.
- Vim-Inspired Motions:
j/k, count prefixes like5jor12k, half-page jumps (d/u),g/G, and visual selection (v,space,V). - Bulk Actions with 5-Second Undo: Multi-select chats to archive (
a), mute (m), mark read/unread (r/R), or delete (d) with an inline 5-second countdown toast (Press 'u' to undo). - Voice Transcription with Gemini: Press
ton voice messages to transcribe using Google Gemini. Transcriptions are cached in SQLite; pressTto force re-transcription. Temp audio files are automatically wiped. - Command Palette & Contextual Help:
Ctrl+Kopens a searchable command palette showing all actions. Destructive actions require inliney/nconfirmation. Press?orF1for contextual cheat sheets. - Multi-Account Support: Switch accounts seamlessly with
F2/Shift+F2. Sessions persist authenticated between restarts.
tg-cli is tuned for Windows Terminal on Windows 10/11.
- Font: Use a font with full Unicode glyph and emoji coverage, such as:
- Cascadia Code / Cascadia Mono
- JetBrains Mono Nerd Font
- Keybindings: Windows Terminal defaults
Ctrl+Shift+Tto new tab andAlt+Arrowto pane focus.tg-clideliberately avoids colliding with these. - Paging:
PageUpandPageDownscroll the chat/message list inside the client rather than the Windows Terminal terminal scrollback buffer. - Tab title: the tab shows the unread count across all accounts, such as
(4) tg-cli. Muted and archived chats do not count.
To connect to Telegram, obtain an api_id and api_hash:
- Sign in with your phone number at https://my.telegram.org.
- Go to API development tools.
- Create a new application (e.g. app name:
tg-cli, platform:Desktop). - Note your numeric
api_idand 32-character hexapi_hash.
You can provide credentials via environment variables:
$env:TG_API_ID = "1234567"
$env:TG_API_HASH = "0123456789abcdef0123456789abcdef"
$env:GEMINI_API_KEY = "AIzaSy..." # Optional, for voice transcriptionOr run tg-cli directly—it will prompt for your credentials on first launch and store them safely in %APPDATA%\tg-cli\config.json.
Secrets, database files, and logs live strictly inside the user's roaming AppData directory and are never written to the git repository:
%APPDATA%\tg-cli\
├── config.json # api_id, api_hash, gemini_api_key, and user preferences
├── app.db # SQLite database in WAL mode (chats, messages, drafts, transcripts)
├── app.db-wal # SQLite write-ahead log
├── tg-cli.log # Application logs (scrubbed of codes and message text)
└── sessions/ # Telethon SQLite session files (one per user_id)
└── 123456789.session
| Key | Action |
|---|---|
Ctrl+K |
Open Command Palette |
? or F1 |
Show keyboard help for current screen |
F2 / Shift+F2 |
Switch to next / previous authenticated account |
Esc |
Back, clear selection, dismiss popup, or defocus |
Ctrl+C |
Cancel in-flight action; double-tap within 1s to quit |
| Key | Action |
|---|---|
j / ↓ |
Move cursor down |
k / ↑ |
Move cursor up |
Ctrl+D / Ctrl+U |
Half-page down / up |
PageDown / PageUp |
Full-page down / up |
Home |
Jump to top (triggers older history load in chat) |
End |
Jump to bottom |
v |
Start visual range selection anchor (j/k extend it) |
Shift+↑ / Shift+↓ |
Select a range from the cursor; Shift+PgUp/PgDn/Home/End extend by page or to the end. The next plain move stops extending and keeps the selection |
Space |
Toggle selection of current item. Ranges add to what Space picked |
Ctrl+click |
Toggle the clicked item (Shift+click extends a range in terminals that pass it; Windows Terminal keeps it for its own text selection) |
V |
Select all items in view (confirms if > 50) |
| Key | Action |
|---|---|
Enter |
Open selected chat |
/ |
Filter chats by name or preview |
[ / ] |
Switch folder tabs (All, Personal, Work, Archive) |
a |
Toggle Archive (undoable 5s). A mixed selection is all archived |
m |
Toggle Mute (undoable 5s). A mixed selection is all muted |
r |
Mark as read (undoable 5s) |
R / Shift+R |
Mark as unread (undoable 5s) |
d |
Delete chat for me (confirms if > 10, undoable 5s) |
u |
Undo last action within 5 seconds |
| Key | Action |
|---|---|
Tab |
Toggle focus between Message List [LIST] and Composer [WRITE] |
Enter |
Send message (when in composer) or retry failed message (when on list) |
Ctrl+J / \+Enter |
Insert newline in composer |
r |
Reply to focused message |
e |
Edit focused message (if sent by me) |
d |
Delete focused or selected messages for me (undoable 5s). Supergroups and channels have no delete-for-me, so it asks first |
D |
Delete for everyone (asks y/n, then undoable 5s) |
u |
Undo the last delete within 5 seconds |
t |
Transcribe voice message with Gemini (cached) |
T |
Force re-transcribe voice message (bypasses cache) |
y |
Copy message text to system clipboard; with a selection, copy it as [time] Sender: text lines |
o |
Open the link in the focused message; o again opens the next one |
f |
Forward focused or selected messages: type to find a chat, Enter sends, Tab hides the original sender |
z |
Toggle message clamping (expand/collapse > 4 lines) |
/ |
Search loaded messages or query older history from Telegram |
Esc |
Clear reply/edit context, defocus composer, or return to chat list |
py -m tg_cliRuns immediately without network access or Telegram credentials:
py -m tg_cli --fakeRaises log level to DEBUG and streams detailed output to %APPDATA%\tg-cli\tg-cli.log:
py -m tg_cli --debugRun the complete test suite:
py -m pytestYes, tg-cli. It's a full-screen terminal UI (TUI) for Telegram, made for Windows Terminal on Windows 10 and 11. It uses Telegram's own MTProto API through Telethon, so it works with a normal user account, not a bot.
It's a regular Telegram client, like Telegram Desktop, that logs in with your own account using api_id and api_hash from my.telegram.org. Telegram lets developers build third-party clients with these credentials.
No. py -m tg_cli --fake starts an in-memory demo with 10,000 chats and no network access, so you can learn the keys first.
Yes. Besides the phone-number code, the login screen can show a QR code to scan from the Telegram app on your phone.
Yes. It supports SOCKS5, HTTP and MTProto proxies, set in config.json or with the TG_PROXY_ENABLED, TG_PROXY_TYPE, TG_PROXY_ADDR and TG_PROXY_PORT environment variables.
Press t on a voice message. tg-cli downloads the audio, sends it to Google Gemini with your own GEMINI_API_KEY, caches the text in SQLite and deletes the temporary audio file. T forces a fresh transcription. Without a key, everything else still works.
Only on your machine, in %APPDATA% g-cli: Telethon session files, the SQLite database and a log scrubbed of login codes and message text. Nothing is written to the repository folder. See Filesystem Layout.
It's built and tested for Windows Terminal. Textual and Telethon are cross-platform, but paths, key bindings and run.bat assume Windows.
To ensure terminal reliability and high performance, v1 focuses strictly on text and voice workflows:
- No Voice/Video Calls: Telegram calls require WebRTC codecs outside the terminal scope.
- No Secret Chats: MTProto end-to-end encrypted secret chats are device-specific and not supported by Telethon.
- No Animated Sticker/Video Playback: Media renders as contextual placeholders (e.g.
[sticker],[photo],[video]). - Text & Voice Only: Sending media attachments (photos, videos, arbitrary files) is deferred to future releases.
MIT © 2026 JavohirX
Made by JavohirX.