Skip to content
JavohirXPublic

About

Keyboard-first terminal Telegram client for Windows Terminal. Python TUI (Textual + Telethon) with Vim keys, 10,000+ chats, bulk actions with undo, multi-account, proxies and Gemini voice transcription.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

tg-cli: Keyboard-First Terminal Telegram Client for Windows

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 --fake opens 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.


Quick Start

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 run

On 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.


Key Highlights

  • 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 like 5j or 12k, 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 t on voice messages to transcribe using Google Gemini. Transcriptions are cached in SQLite; press T to force re-transcription. Temp audio files are automatically wiped.
  • Command Palette & Contextual Help: Ctrl+K opens a searchable command palette showing all actions. Destructive actions require inline y/n confirmation. Press ? or F1 for contextual cheat sheets.
  • Multi-Account Support: Switch accounts seamlessly with F2 / Shift+F2. Sessions persist authenticated between restarts.

Windows Terminal Setup

tg-cli is tuned for Windows Terminal on Windows 10/11.

Recommended Settings

  1. Font: Use a font with full Unicode glyph and emoji coverage, such as:
    • Cascadia Code / Cascadia Mono
    • JetBrains Mono Nerd Font
  2. Keybindings: Windows Terminal defaults Ctrl+Shift+T to new tab and Alt+Arrow to pane focus. tg-cli deliberately avoids colliding with these.
  3. Paging: PageUp and PageDown scroll the chat/message list inside the client rather than the Windows Terminal terminal scrollback buffer.
  4. Tab title: the tab shows the unread count across all accounts, such as (4) tg-cli. Muted and archived chats do not count.

Telegram API Credentials

To connect to Telegram, obtain an api_id and api_hash:

  1. Sign in with your phone number at https://my.telegram.org.
  2. Go to API development tools.
  3. Create a new application (e.g. app name: tg-cli, platform: Desktop).
  4. Note your numeric api_id and 32-character hex api_hash.

Configuration

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 transcription

Or run tg-cli directly—it will prompt for your credentials on first launch and store them safely in %APPDATA%\tg-cli\config.json.


Filesystem Layout

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

Keyboard Shortcuts

Global

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

List Navigation (Chats & Messages)

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)

Chat List Actions

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

Messages & Composer

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

Running tg-cli

Standard Run

py -m tg_cli

In-Memory Demo Mode (10,000 Chats)

Runs immediately without network access or Telegram credentials:

py -m tg_cli --fake

Debug Logging

Raises log level to DEBUG and streams detailed output to %APPDATA%\tg-cli\tg-cli.log:

py -m tg_cli --debug

Running Tests

Run the complete test suite:

py -m pytest

FAQ

Is there a Telegram client for the terminal on Windows?

Yes, 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.

Is it a bot or a userbot? Is it allowed by Telegram?

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.

Do I need a Telegram account to try it?

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.

Can I log in with a QR code?

Yes. Besides the phone-number code, the login screen can show a QR code to scan from the Telegram app on your phone.

Does it work through a proxy?

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.

How does voice message transcription work?

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.

Where are my session and messages stored?

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.

Does it work on Linux or macOS?

It's built and tested for Windows Terminal. Textual and Telethon are cross-platform, but paths, key bindings and run.bat assume Windows.


Scope & Limitations (What v1 Does Not Do)

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.

License

MIT © 2026 JavohirX

Author

Made by JavohirX.

About

Keyboard-first terminal Telegram client for Windows Terminal. Python TUI (Textual + Telethon) with Vim keys, 10,000+ chats, bulk actions with undo, multi-account, proxies and Gemini voice transcription.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages