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.
curl -O https://raw.githubusercontent.com/knyazev741/telegram-multi-thread-router/main/CLAUDE.mdgit clone --depth 1 https://github.com/knyazev741/telegram-multi-thread-routerWrote 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.
[](https://agentmods.dev/instructions/knyazev741/telegram-multi-thread-router/claude-md)<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>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.
| Model | Per session | Once 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 |
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 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:
- From any existing bot topic:
/restart - 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
/restartfrom 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
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.
- 7d ago First seen · 110 lines · 1,146 tokens per session scan B ad3d4bec7f9a
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.
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.
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.
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).
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).
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.
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.