In shortAn agent can answer from my chat history without the whole archive going to the cloud: the model only sees what it asks for, from allowed chats, each message with a tg:// link. In 0.7.0 I cut it down to four commands on purpose.

tg-recall keeps my Telegram chats on my own disk, in SQLite with FTS5 full-text search. I search it from the CLI. AI agents (Claude Code, Codex, any MCP client) use the same archive through an MCP server. Results are compact, one line per message, followed by a list of tg:// links. Each link opens the exact message, so I can check any claim an agent makes in a couple of seconds.

The need is plain. An agent often needs context that only exists in my chats: what was agreed, what was already tried, which config we used. I don’t want to upload all of that anywhere, and I don’t want to paste it in by hand.

The boundary for agents

This is the part I care about most. The MCP server cannot send, edit, delete or mark messages as read. There is no such Telethon call anywhere in src/, and a test checks that the server rejects a write tool and exposes only a small read surface. One caveat: the sync tool downloads new messages from Telegram, so it is not flagged read-only. It is off unless I set ai_access.allow_sync, it never sends anything, and each call is time-boxed.

On top of that sits the ai_access policy. Agents see only the chats on an allowlist. Whether a call comes from an agent or from me is decided by the environment: CLAUDECODE, AI_AGENT, CODEX_* without a TTY, TG_RECALL_AI_MODE=1, CI. That way the policy also applies when an agent shells out to the CLI instead of going through MCP. Every agent call is logged with the tool, client, arguments, tokens and latency, never the message text. Voice transcription for agents stays off until I turn it on.

The MCP server is hand-written, no SDK. The only runtime dependencies are telethon and platformdirs.

Answers sized to a token budget

Agents pay for every token they get back, so search and read trim their output to a budget. Early on, tokens were estimated as one per UTF-8 byte, which made Russian text look about twice as expensive as it really is. Now the estimate goes by character class (Cyrillic, Latin, digits, emoji), and the same budget fits roughly twice as much Russian.

For long periods there is stats, which counts messages per day, week or month for a few hundred tokens instead of reading thousands of messages, and export, which writes a period to a file the agent reads in chunks. To see whether changes like these actually help, I wrote scripts/agent_bench.py. It runs a real agent (headless Claude Code with only the tg-recall tools) through my own questions and records turns, tool calls, tokens, cost and time. --compare diffs two runs.

A fix from 0.8.1: sync started from an agent’s shell now runs for 90 seconds by default instead of an hour, because the agent harness was killing the command halfway. The next call resumes where it stopped. My own terminal still gets 3600 seconds.

What I removed in 0.7.0

Before 0.7.0, tg-recall had semantic and hybrid search over embeddings, answers from a built-in LLM, research sessions, a wiki memory, installers for different agent harnesses and a self-updater. I removed all of it in one breaking release. What is left is search, read, chats and sync, and search is FTS5 only. Agent-facing stats and export came later, in 0.8.0, so big periods stay cheap to look at.

The reasoning: the agent calling the tool is already better at rephrasing a query, trying synonyms and putting an answer together. Doing that again inside the tool just adds complexity for something the caller already has. Synonyms and other languages now go straight into the query as a | b, exact phrases in quotes, exclusions as -word.

Old archives migrate on first run. Embedding tables are dropped, chats, messages, media and transcripts are kept, and the file is compacted with VACUUM when that frees a lot of space. The release notes put a backup as step one.

How it is built and tested

Python 3.13, about 11.3k lines on main: roughly 8.0k in src and 3.3k in tests. There are 149 test functions in 17 files, and pytest collects 199 tests once parameters are expanded. CI runs them on Ubuntu and Windows. Windows took extra work: CLI and MCP output had to be written as UTF-8 explicitly, regardless of the console code page. Docs exist in English and Russian, and a test checks that both are there.

Part of the code was written by Claude Code, and the commit history shows it. The scope, the access boundaries and the review are mine.

Seven releases went out between August 3 and October 3, 2026, from v0.1.0 to v0.8.1. The repo has 3 stars. It is a tool I built for myself first. The next version sits in an open PR and is not merged yet.