claude-telegram-bridge: Instructions file for Claude Code

CLAUDE.md

claude-telegram-bridge CLAUDE.md is an instructions file for Claude Code from uniatrix/claude-telegram-bridge. It costs 1,661 tokens per session, scanned A, original, MIT.

Instructions for a Python bridge that lets Claude Code work through Telegram, a messaging service, with separate ongoing sessions for projects.

In plain words
What is it for?
Use them when modifying, testing, or troubleshooting the Telegram bridge and its project sessions, downloads, configuration, or message delivery.
Why use it?
They explain where the bridge’s code and state live and record details that changes must preserve, such as message formatting and file handling.

Instructions file for Claude Code

Written for Claude Code: the file is CLAUDE.md. Also seen: reads .claude/ paths; mentions CLAUDE.md; mentions Claude Code.

This is uniatrix/claude-telegram-bridge's own configuration. It tells Claude Code how to work on claude-telegram-bridge itself, so it is not a mod to install elsewhere. Copy it as a starting point and replace the rules that are about this project. Everything claude-telegram-bridge configures →

Reuse

Borrowing it

Nothing to install: this file belongs to uniatrix/claude-telegram-bridge. Take a copy, put it at the same path in your own repository, and replace the rules that are about this project with yours.

Copy the file
curl -O https://raw.githubusercontent.com/uniatrix/claude-telegram-bridge/main/CLAUDE.md
Clone the repo
git clone --depth 1 https://github.com/uniatrix/claude-telegram-bridge

Made for: Claude Code.

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for claude-telegram-bridge CLAUDE.md

README.md
[![agentmods](https://agentmods.dev/badge/instructions/uniatrix/claude-telegram-bridge/claude-md/github.svg)](https://agentmods.dev/instructions/uniatrix/claude-telegram-bridge/claude-md)
Your own site
<a href="https://agentmods.dev/instructions/uniatrix/claude-telegram-bridge/claude-md"><img src="https://agentmods.dev/badge/instructions/uniatrix/claude-telegram-bridge/claude-md/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for claude-telegram-bridge CLAUDE.md

Your own site · 80×15
<a href="https://agentmods.dev/instructions/uniatrix/claude-telegram-bridge/claude-md"><img src="https://agentmods.dev/badge/instructions/uniatrix/claude-telegram-bridge/claude-md.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 1,661 This file is loaded in full into every session.
When invoked 1,661 The same file — it is already loaded in full.
Security scan A 1 finding. A grade says what 26 rules found in the file — not that it is safe.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5.1 $0.01661 $0.01661
Opus 5 $0.00830 $0.00830
Sonnet 5 $0.00332 $0.00332
Haiku 4.5 $0.00166 $0.00166

Measured 8d ago against content hash 268ab05d1e38, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-08, from the pricing page.

Security

Grade A, and why

claude-telegram-bridge CLAUDE.md scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 8d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

- `_transcribe_cloud` — hand-built multipart POST (stdlib `urllib`) to an
CLAUDE.md · 104 lines

How it starts

The opening of the file, as written. The whole thing — 104 lines — stays where its author put it; the contents beside it link to each section on GitHub.

CLAUDE.md

Guidance for Claude Code when working in this repo.

What this is

A single-file Python bridge (bridge.py, stdlib only) that exposes the full Claude Code agent over Telegram. It long-polls getUpdates and shells out to the claude CLI in headless stream-json mode, with persistent per-project sessions. Runs unchanged on Windows, Linux and WSL (branches on os.name).

Architecture (where things live in bridge.py)

  • load_env / CFG — config from bridge.env (see bridge.env.example).
  • STATE / save_state — persisted to state.json: Telegram offset, current cwd, model, per-cwd sessions map, and resume_page (pagination).
  • md_to_html — converts Claude's markdown to Telegram HTML.
  • send / tg / typing — Telegram transport; send chunks at 4000 chars and falls back to plain text on bad HTML.
  • tg_download_file(file_id, dest_dir, name_hint=None)getFile + download Telegram media into tmp/ (gitignored), returns the local path. name_hint (the original file name) only sets the extension so the agent's Read tool detects the type. Used for image input (photo / image document) and for any other document (PDF, text, code, spreadsheet…): the file's path is handed to the agent so its Read tool ingests it; the message caption becomes the prompt (no caption → "Analise esta imagem." / "Analise este documento."). Detection lives in main, after the owner gate, in order: image → audio → document.
  • transcribe_audio(path) — voice/audio path. The Read tool can't ingest sound, so audio is transcribed first. Dispatches between two backends: _transcribe_local (preferred, when STT_CMD is set) and _transcribe_cloud (fallback, when STT_API_KEY is set).
    • _transcribe_local — shells out to STT_CMD (a local command, e.g. the bundled stt_faster_whisper.py), appending the audio path as the last arg and reading the transcript from stdout. shlex.split(posix=False) keeps Windows backslashes; wrapping quotes are stripped per token. Fully offline.
    • _transcribe_cloud — hand-built multipart POST (stdlib urllib) to an OpenAI-compatible /audio/transcriptions endpoint (STT_API_URL, default Groq whisper-large-v3; switch to OpenAI via env). main handles voice / audio / video_note / audio documents after the image block, echoes the transcript back, and skips with a notice when neither STT_CMD nor STT_API_KEY is set. OGG is accepted directly (no ffmpeg). stt_faster_whisper.py is the only file with a third-party dep (faster-whisper); bridge.py stays stdlib-only.
  • run_claude(chat_id, cwd, prompt) — the agent core. Spawns claude -p with --permission-mode bypassPermissions --output-format stream-json --verbose and --resume <sid> when a session exists for that cwd. Parses the stream for the final result and tool-use names. Frontend-agnostic — reuse this to add a non-Telegram frontend.
  • list_sessions / session_preview / find_session — read past session transcripts from ~/.claude/projects/<slug>/*.jsonl, where <slug> is the cwd with every non-alphanumeric char replaced by -.
  • handle — command router (/cd /pwd /ls /new /resume /model /help); unknown slash commands fall through and are treated as prompts.
  • main — poll loop with the owner gate (OWNER_ID) enforced before any claude call. Each message and each callback tap runs on its own daemon thread (process_message / _run_callback) so a long turn never blocks the poll loop. On startup it resets cwd to home (DEFAULT_CWD), re-delivers any interrupted streaming run (_finalize_orphans), and sends the owner a "Bridge reiniciado" message so no reboot ever passes silently. If a restart note (tmp/restart_note.txt, or restart_pending.txt after a graceful restart) is present, its text is appended once and both markers are removed.
  • Restart workflow (_restart_watcher / os.execv). To reload code after a change, write tmp/restart_note.txt describing what changed and stop — do NOT run launchctl kickstart / kill the process yourself. A daemon watcher sees the note, sets RESTARTING (new prompts are deferred), drains in-flight runs (inflight_count() → 0, capped at RESTART_DRAIN_TIMEOUT) so each still delivers its final message, renames the note to restart_pending.txt, and re-execs in the same PID via os.execv. This replaces a hard kickstart that would kill the child claude mid-response and drop the final message.
  • Live streaming (LiveStream). A turn edits one message in place as a throttled "working" view; on completion it collapses to a trace and sends the full answer as a new message (edits don't notify, new messages do). run_claude owns delivery and returns (tools, None) on success. While a run streams, persist_live snapshots it into STATE["live_runs"] for crash recovery; clear_live removes the snapshot on delivery.

Read the full file on GitHub · 104 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 8d ago First seen · 104 lines · 1,661 tokens per session scan A 268ab05d1e38

Subscribe to this mod's changes

claude-telegram-bridge CLAUDE.md is an instructions file published in the GitHub repository uniatrix/claude-telegram-bridge (2 stars, last pushed yesterday), licensed MIT. It adds 1,661 tokens to every session, about $0.0083 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other instructions, from other repositories

next.js AGENTS.md

AGENTS.md instructions for vercel/next.js, covering next.js development guide, codebase structure, monorepo overview, core package: packages/next and other important packages.

vercel/next.js · 7,296 tokens

codex AGENTS.md

AGENTS.md instructions for openai/codex, covering rust/codex-rs, the codex-core crate, code review rules, crate api surface and model visible context.

openai/codex · 5,153 tokens

vscode buildNext.instructions.md

Working notes and architecture documentation for the new esbuild-based build system in build/next. Use when making changes to the new build pipeline (transpile/bundle commands, NLS plugin, source-map handling, resource copying, or self-hosting watch tasks).

microsoft/vscode · 6,785 tokens

vscode oss-third-party-notices.instructions.md

Instructions for microsoft/vscode, covering vs code oss third-party-notices pipeline, architecture, pipeline flow in ci, applying the notice (cutover) and fallback chain (never fail the build).

microsoft/vscode · 5,001 tokens

langchain AGENTS.md

AGENTS.md instructions for langchain-ai/langchain, covering global development guidelines for the langchain monorepo, corridor security analysis, project architecture and context, monorepo structure and development tools & commands.

langchain-ai/langchain · 4,469 tokens

spec-kit AGENTS.md

AGENTS.md instructions for github/spec-kit, covering agents.md, about spec kit and specify, quickstart — add a new integration in 5 steps, integration architecture and integrationmanifest — file tracking.

github/spec-kit · 7,104 tokens