Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
git clone --depth 1 https://github.com/alexeyleshchenko/fast-mcp-telegramWrote 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/rules/alexeyleshchenko/fast-mcp-telegram/code-optimization)<a href="https://agentmods.dev/rules/alexeyleshchenko/fast-mcp-telegram/code-optimization"><img src="https://agentmods.dev/badge/rules/alexeyleshchenko/fast-mcp-telegram/code-optimization/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.
<a href="https://agentmods.dev/rules/alexeyleshchenko/fast-mcp-telegram/code-optimization"><img src="https://agentmods.dev/badge/rules/alexeyleshchenko/fast-mcp-telegram/code-optimization.svg" alt="Reviewed on agentmods" width="80" 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.00000 | $0.01404 |
| Opus 5.5 | $0.00000 | $0.00562 |
| Sonnet 5.5 | $0.00000 | $0.00281 |
| Haiku 4.5 | $0.00000 | $0.00140 |
Grade A, and why
code-optimization scanned grade A with 0 findings 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 1mo 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.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
This is a copy
100% identical to code-optimization — 0 lines differ, which has more behind it and is treated as the original. This page carries a canonical link to it rather than competing with it.
How it starts
The opening of the file, as written. The whole thing — 239 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Code Optimization Guidelines
🎯 Core Principles
1. DRY (Don't Repeat Yourself)
- Eliminate code duplication across files and functions
- Extract shared logic into reusable functions/classes
- Centralize constants and configuration
- Use composition over duplication
2. Single Responsibility Principle
- One function = One purpose
- Separate concerns clearly (validation, processing, I/O)
- Avoid functions that do too much
- Group related functionality logically
🔍 Identifying Problems
Red Flags to Watch For:
- Duplicate constants across multiple files
- Similar function logic in different modules
- Functions with multiple responsibilities
- Artificial function boundaries that don't add value
- Mixed abstraction levels in the same function
- Redundant parameter processing
🛠️ Optimization Strategies
1. Function Consolidation
# ❌ BAD: Two functions doing similar things
def invoke_mtproto_method(method, params, params_json=""):
# Does preprocessing + Telethon interaction
def invoke_mtproto_impl(method, params_json, allow_dangerous=False):
# Does preprocessing + calls invoke_mtproto_method
# ✅ GOOD: Single function with clear purpose
def invoke_mtproto_impl(method, params_json, allow_dangerous=False, resolve=True):
# Does everything in one logical flow
2. Constant Extraction
# ❌ BAD: Duplicate constants across files
# In file1.py
DANGEROUS_METHODS = {"messages.DeleteMessages", ...}
# In file2.py
DANGEROUS_METHODS = {"messages.DeleteMessages", ...}
# ✅ GOOD: Centralized constants
# In constants.py
DANGEROUS_METHODS = {
"account.DeleteAccount",
"messages.DeleteHistory",
"messages.DeleteMessages",
# ...
}
3. Helper Function Extraction
# ❌ BAD: Logic scattered in main function
def main_function():
# 50 lines of mixed logic
if "." not in method_name:
raise ValueError("Invalid format")
module_name, class_name = method_name.rsplit(".", 1)
# ... more mixed logic
# ✅ GOOD: Clear separation with helpers
def _resolve_method_class(method_name):
"""Resolve method name to Telethon class"""
if "." not in method_name:
raise ValueError("Invalid format")
# ... focused logic
def main_function():
method_cls = _resolve_method_class(method_name)
# ... clean main logic
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.
- 1mo ago First seen · 239 lines · 0 tokens per session scan A 20c4279f8806
code-optimization is a cursor rule published in the GitHub repository alexeyleshchenko/fast-mcp-telegram (2 stars, last pushed 1mo ago), licensed MIT. It costs nothing until one of its globs matches a file; then it loads 1,404 tokens. A static security scan graded it A with 0 findings. It is 100% identical to code-optimization, differing in 0 lines, and is treated as a copy.
Other cursor rules, from other repositories
contributing
Cursor rule "contributing" from groupultra/telegram-search, covering contribution & refactor guidelines, 1. before large changes (refactors, new infra, new domains), 2. backend mindset, 3. typescript style and 4. pr hygiene.
code-optimization
Guidelines for optimizing duplicate and poorly structured code.
50-pr-and-git
Use when committing, opening or updating a pull request, writing a PR description, or preparing a release.
pr-automation
Cursor rule "pr-automation" from floriscornel/todo-mcp, covering pull request guidelines, pre-pr checklist, pr description template, summary and changes.
ponytail
Ponytail, lazy senior dev mode. Always pick the simplest solution that works.
angular-20
This rule provides comprehensive best practices and coding standards for Angular development, focusing on modern TypeScript, standalone components, signals, and performance optimizations.