Skip to content

How to Give Claude Code Context from Your Slack, Telegram, and Email

Problem

I asked Claude Code to write an email to Alex about our project timeline. It produced a generic draft that could have been written by anyone. No reference to our Tuesday discussion. No mention of the API migration concerns Alex raised. Nothing specific.

The issue? Claude Code has no idea what I discussed on Slack last week, what decisions were made in Telegram DMs, or what stakeholders emailed me about. All that context lives in separate apps, locked away from my AI assistant.

Every time I start a Claude Code session, it’s a blank slate. I end up manually copying context from Slack threads, searching through Telegram history, digging up old emails. By the time I’ve assembled the relevant context, I’ve lost momentum.

What I Tried First

My first thought was to copy-paste relevant messages into Claude Code context files. I created a context/ directory and started saving important conversations there.

This worked for a day. Then I realized:

Problems with manual context files
- Forgot to update context files regularly
- Messages scattered across 4+ platforms
- Couldn't find the right thread when I needed it
- Context files grew stale within hours
- No way to search across all channels at once

I needed something automatic. Something that would sync all my messaging channels into one searchable place.

The Solution

The breakthrough came from a Reddit thread where someone described exactly this problem and solution:

“I asked my agent to prepare for a call with someone, and it pulled context from a Telegram conversation three months ago, cross-referenced with a Slack thread from last week, and gave me a briefing I couldn’t have assembled myself in under 20 minutes.”

The approach uses a local message indexing tool (like traul) that syncs messaging channels into SQLite, then exposes this to Claude Code via CLI or MCP tools.

Here’s the architecture:

Messaging Context Architecture
┌──────────────────────────────────────────────────────────────┐
│ Your Messaging Channels │
│ ┌─────────┐ ┌──────────┐ ┌─────────┐ ┌─────────┐ │
│ │ Slack │ │ Telegram │ │ Discord │ │ Gmail │ ... │
│ └────┬────┘ └────┬─────┘ └────┬────┘ └────┬────┘ │
└───────┼────────────┼─────────────┼────────────┼──────────────┘
│ │ │ │
▼ ▼ ▼ ▼
┌───────────────────────────────────────────────────────────────┐
│ Sync CLI (traul, cerebellum) │
│ - Authenticate with each platform │
│ - Pull message history with pagination │
│ - Normalize to unified schema │
└───────────────────────────────┬───────────────────────────────┘
┌───────────────────────────────────────────────────────────────┐
│ Local SQLite Database │
│ ┌─────────────────┐ ┌─────────────────────────────────────┐│
│ │ FTS5 Index │ │ Vector Embeddings (Ollama) ││
│ │ Keyword search │ │ Semantic search ││
│ └─────────────────┘ └─────────────────────────────────────┘│
└───────────────────────────────┬───────────────────────────────┘
┌───────────────────────────────────────────────────────────────┐
│ Claude Code Access │
│ Option 1: CLI tool → Claude runs commands │
│ Option 2: MCP server → Claude queries directly │
└───────────────────────────────┘

Implementation: Two Paths

There are two ways to expose this data to Claude Code.

Option 1: CLI Tool

Claude Code can run shell commands. If your message search tool has a CLI, you can let Claude execute searches during sessions.

Example CLI usage
# Claude Code runs this during your session
traul search "what did Alex say about API migration"
# Returns results from all channels
# [2024-03-10 Slack #engineering] Alex: "The API migration needs to handle backward compatibility..."
# [2024-03-08 Telegram DM] Alex: "Can we push the migration to Q2? The team is stretched thin."

The advantage is simplicity. No MCP setup required. Just add the CLI tool to Claude Code’s allowed commands.

The downside is you need to explicitly ask Claude to search. It won’t automatically know when to query.

Option 2: MCP Server

The better approach is exposing the search as an MCP (Model Context Protocol) tool. Claude can then call it directly when it needs context.

message_search_mcp.py
from mcp.server import Server
from mcp.types import Tool, TextContent
import sqlite3
server = Server("message-search")
db_path = "~/.traul/messages.db"
@server.list_tools()
async def list_tools():
return [
Tool(
name="search_messages",
description="Search across Slack, Telegram, Discord, Gmail",
inputSchema={
"type": "object",
"properties": {
"query": {"type": "string"},
"platforms": {
"type": "array",
"items": {"type": "string"}
},
"days": {"type": "integer", "default": 30}
},
"required": ["query"]
}
)
]
@server.call_tool()
async def call_tool(name: str, arguments: dict):
if name == "search_messages":
results = search_all_channels(
query=arguments["query"],
platforms=arguments.get("platforms"),
days=arguments.get("days", 30)
)
return [TextContent(type="text", text=format_results(results))]
def search_all_channels(query: str, platforms: list, days: int):
conn = sqlite3.connect(db_path)
cursor = conn.execute("""
SELECT platform, channel, sender, content, timestamp
FROM messages
WHERE messages MATCH ?
AND date(timestamp) >= date('now', ?)
ORDER BY timestamp DESC
LIMIT 20
""", (query, f"-{days} days"))
return cursor.fetchall()

With this MCP server running, Claude Code can search your messages automatically when context is needed.

Setup Steps

Here’s how I set this up:

Step 1: Install Message Sync Tool

Installing traul
pip install traul
# or clone from source
git clone https://github.com/dandaka/traul
cd traul && pip install -e .

Step 2: Configure Platform Credentials

config.yaml
slack:
bot_token: ${SLACK_BOT_TOKEN}
# Get from Slack App OAuth & Permissions
telegram:
api_id: ${TELEGRAM_API_ID}
api_hash: ${TELEGRAM_API_HASH}
# Get from my.telegram.org
gmail:
credentials_file: ~/.config/gmail/credentials.json
# Download from Google Cloud Console

Store tokens in environment variables, never in the config file itself.

Step 3: Run Initial Sync

Initial message sync
# Sync all configured platforms
traul sync --all
# Or sync specific platforms
traul sync slack telegram

This pulls your message history. First sync takes a while depending on how much history you have.

Step 4: Expose to Claude Code

For CLI access, add to your Claude Code settings:

claude_desktop_config.json
{
"allowedTools": ["Bash"],
"allowedCommands": ["traul search"]
}

For MCP access, add the server:

claude_desktop_config.json
{
"mcpServers": {
"message-search": {
"command": "python",
"args": ["/path/to/message_search_mcp.py"]
}
}
}

The Difference It Makes

Here’s what changed after I set this up:

ScenarioBeforeAfter
”Write an email to Alex”Generic draft with no contextReferences Tuesday’s timeline, mentions API migration concerns
Finding a specific thread15-20 minutes across 4 appsOne query returns consolidated results
Preparing for a callManually assembling contextClaude cross-references Telegram + Slack + email

The most useful scenario is call preparation. Before a meeting, I can ask Claude:

“What did I discuss with Sarah in the last month? Include Slack, Telegram, and email.”

Claude pulls context from all channels and produces a briefing I couldn’t assemble manually in under 20 minutes.

Privacy and Security Considerations

Syncing all your messages to a local database raises some questions:

Security checklist
- [ ] Database stored locally, not cloud
- [ ] Tokens stored in environment variables
- [ ] Database file encrypted at rest (optional)
- [ ] MCP server only accessible from Claude
- [ ] Consider what NOT to sync (DMs with sensitive info)

One user on Reddit raised a valid concern:

“AI acts up so much I just end up not trusting its work.”

The solution is to use the search for retrieval only. Claude finds the messages, but you validate the content before acting on it. Don’t let Claude automatically send emails or make decisions based on retrieved context without your review.

Another point: context quality matters more than context quantity. Don’t bulk-index everything. Selectively tag what’s agent-relevant.

Common Issues

Issue 1: Rate Limits During Initial Sync

Slack and Telegram both have API rate limits. The first sync hit these repeatedly.

Sync errors
Slack API rate limit exceeded. Retrying in 60 seconds...
Telegram API flood wait: 300 seconds

The fix was running the initial sync overnight with retry logic built into the sync tool.

Issue 2: Message Formatting Inconsistency

Different platforms format messages differently. Slack has threads, Telegram has replies, Discord has embeds.

I had to normalize all messages to a unified schema:

Unified message schema
{
"id": "unique_id",
"platform": "slack|telegram|discord|gmail",
"channel": "channel_name_or_email_thread",
"sender": "display_name",
"content": "plain_text_content",
"timestamp": "ISO_8601",
"thread_id": "parent_message_id_or_null",
"reactions": ["emoji1", "emoji2"]
}

Issue 3: Semantic Search Quality

Keyword search (FTS5) works well for exact terms. But semantic search - finding “API migration” when you search “backend changes” - required embedding support.

I added Ollama for local embeddings:

Adding embedding support
ollama pull nomic-embed-text
traul embed --model nomic-embed-text

This improved search recall significantly, especially for conceptually related but differently-worded discussions.

When This Works (And When It Doesn’t)

This approach works well when:

  • You have conversations scattered across multiple platforms
  • Claude Code is your primary coding assistant
  • You need historical context during sessions
  • Your work involves coordination with multiple people

It doesn’t work as well when:

  • All your context is already in one place (just use that)
  • You have strict data residency requirements
  • Your messages contain highly sensitive information
  • You don’t want your AI assistant accessing personal conversations

Summary

Giving Claude Code access to your messaging context requires three steps:

  1. Sync: Use a tool like traul to pull messages from Slack, Telegram, Discord, Gmail into local SQLite
  2. Index: Enable FTS5 for keyword search, optionally add embeddings for semantic search
  3. Expose: Connect via CLI commands or MCP server so Claude can query during sessions

The result: Claude references real conversations instead of making generic suggestions. “Write an email to Alex” now includes context from your Tuesday discussion, the API migration concerns, and the timeline agreement.

The setup takes an afternoon. The productivity gain is ongoing.

If your context lives scattered across messaging apps, this is the bridge that connects everything to your AI assistant.

Final Words + More Resources

My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments