telegram-multi-thread-router: Instructions file for Claude Code

CLAUDE.md

telegram-multi-thread-router CLAUDE.md is an instructions file for Claude Code from knyazev741/telegram-multi-thread-router. It costs 1,146 tokens per session, scanned B, original, MIT.

Project instructions for a Telegram bot that gives each conversation thread its own AI-provider session. They explain the bot's architecture, setup commands, and safe restart process.

In plain words
What is it for?
They cover local setup, running the bot, restarting it while resuming sessions, and understanding its Python modules, database, permissions, and configuration.
Why use it?
They help an agent preserve conversation sessions and avoid unsafe restarts that could interrupt the bot or lose session state.

Instructions file for Claude Code

Written for Claude Code: the file is CLAUDE.md. Also seen: mentions Codex.

This is knyazev741/telegram-multi-thread-router's own configuration. It tells Claude Code how to work on telegram-multi-thread-router 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 telegram-multi-thread-router configures →

Reuse

Borrowing it

Nothing to install: this file belongs to knyazev741/telegram-multi-thread-router. 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/knyazev741/telegram-multi-thread-router/main/CLAUDE.md
Clone the repo
git clone --depth 1 https://github.com/knyazev741/telegram-multi-thread-router

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 telegram-multi-thread-router CLAUDE.md

README.md
[![agentmods](https://agentmods.dev/badge/instructions/knyazev741/telegram-multi-thread-router/claude-md.svg)](https://agentmods.dev/instructions/knyazev741/telegram-multi-thread-router/claude-md)
Your own site
<a href="https://agentmods.dev/instructions/knyazev741/telegram-multi-thread-router/claude-md"><img src="https://agentmods.dev/badge/instructions/knyazev741/telegram-multi-thread-router/claude-md.svg" alt="Measured on agentmods" height="20"></a>
Per session 1,146 This file is loaded in full into every session.
When invoked 1,146 The same file — it is already loaded in full.
Security scan B 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.01146 $0.01146
Opus 5 $0.00573 $0.00573
Sonnet 5 $0.00229 $0.00229
Haiku 4.5 $0.00115 $0.00115

Measured 7d ago against content hash ad3d4bec7f9a, method: parsed. Prices are Anthropic first-party input rates as of 2026-09-06, from the pricing page.

Security

Grade B, and why

telegram-multi-thread-router CLAUDE.md scanned grade B 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 7d 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.

Asks for rootmediumPrivilege escalation

A mod that escalates privileges can change anything on the machine, not only the project.

- All secrets in `.env` (gitignored), chmod 600
CLAUDE.md · 110 lines

How it starts

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

Telegram Multi-Thread Router

Architecture

Python asyncio bot using aiogram 3 + provider backends. Each Telegram bot thread = one provider session.

  • Bot: aiogram 3 Dispatcher with Router-per-concern pattern
  • Sessions: local Claude/Codex runners per thread, managed by SessionManager
  • Orchestrator: Auto-created provider session with MCP tools for managing other sessions
  • Permissions: can_use_tool callback → asyncio.Future → Telegram inline buttons
  • DB: aiosqlite with WAL mode for session/topic persistence
  • Config: pydantic-settings loading from .env

Quick Start

python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
cp .env.example .env  # fill in values
python -m src

Restart (pick up new code)

Two ways to restart:

  1. From any existing bot topic: /restart
  2. Manual: kill $(pgrep -f 'python -m src') && python -m src

On restart, all sessions resume automatically via resume_all() — sessions stay as idle in DB during graceful shutdown and are re-created with their session_id on next startup.

CRITICAL — DO NOT restart the bot from sessions:

  • NEVER run os.execv, kill, pkill, or any command that restarts/kills the bot process from within a provider session running inside this bot.
  • You ARE running inside this bot. Restarting it kills YOUR OWN process and causes infinite restart loops.
  • If code changes need a restart, tell the user to run /restart from any existing bot topic manually.
  • This applies to ALL sessions, including the orchestrator.

IMPORTANT: Never kill -9 the bot — use SIGTERM so on_shutdown runs and preserves session state.

Project Structure

src/
  __main__.py          - Entry point (asyncio.Runner + uvloop)
  config.py            - pydantic-settings BaseSettings
  bot/
    dispatcher.py      - Dispatcher factory, startup/shutdown lifecycle
    middlewares.py      - OwnerAuthMiddleware
    routers/
      general.py       - General topic fallback (minimal, rarely fires)
      session.py       - All commands (/new, /list, /restart, /stop, /close) + message forwarding
    status.py          - StatusUpdater (editable status message per turn)
    output.py          - split_message, TypingIndicator
  sessions/
    runner.py          - SessionRunner (ClaudeSDKClient wrapper, state machine)
    manager.py         - SessionManager (thread_id → runner mapping)
    permissions.py     - PermissionManager (asyncio.Future bridge to Telegram buttons)
    orchestrator.py    - Auto-created orchestrator session with management MCP tools
    mcp_tools.py       - Telegram output MCP tools (reply, send_file, react, edit_message)
    voice.py           - faster-whisper transcription
    health.py          - Zombie session detection
    state.py           - SessionState enum
    remote.py          - RemoteSession proxy for TCP workers
  db/
    schema.py          - SQLite schema + migrations
    connection.py      - aiosqlite connection helper
    queries.py         - Named SQL query functions
  ipc/
    protocol.py        - msgspec Struct message types for TCP
    server.py          - Bot-side TCP server for remote workers
  worker/
    __main__.py        - Worker entry point (python -m src.worker)
    client.py          - TCP client with reconnection
    output_channel.py  - Bot adapter for worker side

Read the full file on GitHub · 110 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. 7d ago First seen · 110 lines · 1,146 tokens per session scan B ad3d4bec7f9a

Subscribe to this mod's changes

telegram-multi-thread-router CLAUDE.md is an instructions file published in the GitHub repository knyazev741/telegram-multi-thread-router (11 stars, last pushed 5mo ago), licensed MIT. It adds 1,146 tokens to every session, about $0.0057 per session on Opus 5. A static security scan graded it B with 1 finding (asks for root). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.

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,182 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