Guides through first-time setup, authentication, and re-authentication of a Telegram CLI using GramJS. Handles session storage, 1Password credential retrieval, and profile configuration.
Ships in tlg. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Prerequisite —
cc-plugin-root. This skill resolves its scripts withcc-plugin-root <plugin>(theCLAUDE_PLUGIN_ROOTplaceholder is not a shell variable and expands to empty). If the command is missing, run/itp:setup(its first step installs it), or link it directly:~/.claude/plugins/marketplaces/cc-skills/scripts/cc-plugin-root ~/.local/bin/cc-plugin-root ```
One-time (or re-)authentication of a personal Telegram account for the GramJS CLI.
Self-Evolving Skill: This skill improves through use. If instructions are wrong, parameters drifted, or a workaround was needed — fix this file immediately, don't defer. Only update for real, reproducible issues.
The CLI uses GramJS (MTProto). Each profile's login is a GramJS StringSession stored at ~/.local/share/gramjs/<profile>.session. The Telegram API id/hash come from 1Password at runtime. (Historical note: this replaced the Telethon/uv implementation in 2026-06; old ~/.local/share/telethon/*.session files are not reused — accounts log in once more here.)
ROOT="$(cc-plugin-root tlg)"
SCRIPT="$ROOT/scripts/tg-cli.ts"
| Profile | 1Password Item | Item UUID | Phone |
|---|---|---|---|
work | Telegram API - ExampleOpsAccount | <1password-item-id> | +15559876543 |
personal | Telegram API - personal account | <1password-item-id> |
bun available. Nothing to install: telegram (GramJS) is vendored in scripts/vendor/.op) signed in; the item above present in the Claude Automation vault.There op needs a service-account token or a manual sign-in, so pick one of:
OP_SERVICE_ACCOUNT_TOKEN, or set OP_SA_TOKEN_CMD to a command that prints it, or OP_SA_TOKEN_FILE to a chmod-600 file holding it. The token goes into op's environment, never its argv.op account add once, then eval "$(op signin)" in the shell that runs tlg; tlg hands op its environment, so the session reaches it. 1Password warns that on some platforms any process of the same user can then use the account (sign in manually), so on a shared host prefer the token.TELEGRAM_API_ID and TELEGRAM_API_HASH. That is enough for every command on an account that is already signed in; send-code and sign-in still read the phone number from the 1Password item.On a shared host each person has their own profile file (~/.config/cc-skills/tlg-profiles.json, below) and their own session (~/.local/share/gramjs/<profile>.session, chmod 600); never copy another user's. A fresh user without the profile file gets unknown profile 'default' with these same options in the message.
The footer's time zone is the machine's: set TZ on a host kept on UTC if messages should show local time.
The Bash tool has no stdin, so the CLI never prompts. Authentication is split into send-code (requests the code) and sign-in (submits it). Get the code from the user with AskUserQuestion between the two steps.
bun "$SCRIPT" check-auth eon # exit 0 + JSON if authorized; exit 1 if not
If it reports authorized: true, you're done. Otherwise continue.
bun "$SCRIPT" send-code eon
# → JSON: { "status": "code_sent", "phone": "...", "phone_code_hash": "<HASH>", ... }
Telegram delivers the code to the account's Telegram app first, then SMS. The code expires within a couple of minutes — move straight to Step 2.
Ask the user for the digits (they type them in the "Other" box). Also ask whether they have two-factor (cloud password) enabled.
bun "$SCRIPT" sign-in eon --code <CODE> --hash <HASH>
# 2FA enabled? add: --password '<cloud password>'
# → JSON: { "authorized": true, "user_id": ..., "username": ..., "session_file": ... }
Run sign-in once per code — a failed/duplicate attempt invalidates the code (PHONE_CODE_EXPIRED); if that happens, redo Step 1 for a fresh code.
bun "$SCRIPT" whoami -p work
| Anti-Pattern | Why It Fails |
|---|---|
| Expecting an interactive login prompt | The CLI never reads stdin; use send-code + sign-in |
Running sign-in twice with the same code | The first attempt consumes it → PHONE_CODE_EXPIRED; request anew |
Dawdling between send-code and sign-in | Codes expire in ~minutes; collect the code immediately and sign in |
Reusing an old ~/.local/share/telethon session | Wrong format/engine — GramJS sessions live under ~/.local/share/gramjs |
| Checking only file existence for "is it authorized?" | A session file can exist but be expired — use check-auth |
| File | Purpose |
|---|---|
~/.local/share/gramjs/work.session | ExampleOpsAccount StringSession |
~/.local/share/gramjs/personal.session | personal StringSession |
Sessions expire when revoked in Telegram → Settings → Devices, or after prolonged inactivity. When expired, check-auth reports authorized: false; rerun the 3-step flow.
Add the profile to ~/.config/cc-skills/tlg-profiles.json ({"default": "<profile>", "profiles": {"<profile>": "<1password-item-id>"}}; machine-local, never committed) and store credentials in the Claude Automation 1Password vault with fields App ID, App API Hash, and Phone Number. (Override per-invocation with TELEGRAM_API_ID/TELEGRAM_API_HASH env vars to skip 1Password.)
After this skill completes, check before closing:
check-auth confirm an authorized session? If not, fix the step/error that blocked it.send-code/sign-in flags changed, update the commands above.Only update if the issue is real and reproducible — not speculative.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
telegram-cli, gramjs, authentication, 1password, session-management
/tlg:setupfrom tlg
npx claudepluginhub terrylica/cc-skills --plugin tlg16 skills in this plugin
/cleanup-deleteduser wants to clean up Telegram by purging deleted or ghost accounts from their dialog list and contacts, or removing spam ghosts that clutter./create-groupUse when user wants to create a new Telegram group, supergroup, or channel, optionally inviting members on creation./delete-messagesUse when user wants to delete, remove, or unsend Telegram messages from a chat, either for everyone or just for themselves./download-mediaUse when user wants to download, save, or extract media files such as photos, videos, and documents from Telegram messages.Other plugins' skills for the same job