AI for Automation
πŸ’¬ Telegram Integration

Step 11 / 22

πŸ’¬ Telegram Integration

Remote-control AI from anywhere

Prerequisites β€” You Already Have Everything

Want to use AI from anywhere? On the subway to work, at a cafe, before bedβ€”control Claude Code on your home PC remotely with just your smartphone. The solution is Telegram bot integration.

βœ… Already installed

  • βœ… Windows PC
  • βœ… Claude Code (CLI)
  • βœ… Claude Pro subscription & logged in

πŸ“‹ Today’s tasks

  • 1️⃣ Get a Telegram bot token
  • 2️⃣ Download cokacdir
  • 3️⃣ Run the bot server β†’ Done!

Why Telegram?

Unlike other messaging apps, Telegram provides a free bot API officially. Creating and integrating a bot requires no fees or business registration.

STEP 1: Get a Telegram Bot Token

πŸ“ Create a workspace folder

First, create a folder where cokacdir files and AI conversation logs will be stored.

1Create a folder anywhere in File Explorer (e.g., my-ai-bot)
2Click the address bar inside the folder β†’ type powershell β†’ press Enter
3In the opened PowerShell, type claude β†’ Claude Code starts!

πŸ“± Install Telegram

  1. Install "Telegram" from your phone’s app store
  2. PC: Download the desktop app from telegram.org
  3. Sign up with your phone number

πŸ€– Get a bot token

  1. Search for @BotFather β†’ START BOT
  2. Type /newbot
  3. Set bot name (e.g., My AI Assistant)
  4. Set username (e.g., myai_helper_bot) β€” must end with _bot
  5. Copy the issued token!
Running /newbot in BotFather
Type /newbot to @BotFather and it asks for the bot name

The token is a password

The bot token is a long string like 7123456789:AAH.... Anyone with this token can control the bot, so never share it publicly.

STEP 2: Download cokacdir

Just have Claude Code do it. Enter the following in the Claude Code session from STEP 1.

Type in Claude Code
Download cokacdir.
The official repo is https://github.com/kstost/cokacdir.
Save to the current folder,
and also open a new PowerShell window at this path.

When Claude Code asks for approval, just press Y. Download + opening a new PowerShell window completes automatically.

STEP 3: Run the Bot Server

This is the only thing you run manually. In the new PowerShell window Claude Code opened, enter:

PowerShell
.\cokacdir.exe --ccserver <paste-your-bot-token-here>

# Example:
.\cokacdir.exe --ccserver 7123456789:AAH_abcdefg...

On first run, select β€œOpen in Terminal (app).” Your Claude Pro account from the previous session connects automatically.

Why run this manually?

Cokacdir uses a terminal UI (TUI) which can’t run inside Claude Code. It must be run directly in a separate PowerShell window.

Test It Out

Once the bot server is running, send a message to the bot you created in Telegram.

Messages to try in Telegram
Hello! Who are you?
What's the weather like today?
Show me the list of files in the current folder

When Claude Code on your PC receives the message, it performs web searches, file read/write, code execution, report generation, and sends the results back via Telegram.

Understanding: What Is cokacdir?

Now that you’ve confirmed the bot works, let’s understand how it works.

Cokacdir is a Telegram integration tool that calls the Claude CLI. It runs on your PC using your own Claude account login, so it’s 100% policy compliant.

Core principle

Cokacdir logs in directly with your Pro subscription on your PC. Login credentials exist only on your PC and are never shared with third parties.

How It Works

It runs directly on your Windows PC. No WSL needed.

1
πŸ“±Send message from Telegram
2
πŸ–₯️Cokacdir server receives message (running in PowerShell on your PC)
3
πŸ”Calls AI via Claude CLI (your Pro subscription login)
4
βš™οΈAI performs file reading, code execution, web search
5
πŸ’¬Sends results back to Telegram

Windows native!

Cokacdir runs as a single Windows exe file. No additional installs like WSL or Tailscale needed.

OpenClaw vs cokacdir

There are two main ways to connect Telegram with Claude Code.

🐾 OpenClawπŸ€– cokacdir
DescriptionOpen-source messenger AI agentClaude Agent SDK-based Telegram integration
Auth methodSends your login credentials to a third partyLogs in directly on your PC
Execution locationThird-party server uses your accountCalls Claude CLI directly on your PC
Anthropic policy⚠️ Violation (officially prohibited)βœ… Compliant (uses official CLI)
SecurityRisk of credential leak & runawayLogin credentials exist only on your PC
Account safetyPossible banSafe

OpenClaw’s Critical Problem

OpenClaw’s core issue is handing your Claude Pro subscription credentials to a third-party program. It’s like lending your credit card to a stranger.

🚫Account ban

Anthropic has officially prohibited using Free, Pro, and Max account OAuth tokens in third-party tools.

πŸ”“Security risk

Others can make API calls with your account. File system browsing cases have been reported on public Discord servers.

πŸ’ΈCost runaway

An actual incident occurred where an agent went haywire, sending 500+ messages indiscriminately.

Bottom line

OpenClaw is convenient but can lead to account bans due to policy violations. This guide uses the safe cokacdir.

Key Difference: Authentication Method

An analogy makes this easy to understand.

🐾 OpenClaw

πŸ’³ Lending your credit card to a stranger and saying "go shopping for me"

  • Don’t know how much they’ll spend
  • Don’t know where they’ll use it
  • Outside your control

πŸ€– cokacdir

🏠 Taking money from your own safe at home, "I hold the key"

  • Token exists only on your PC
  • You have complete control
  • No additional costs

Error: Invalid API key

You successfully logged in with claude auth login via OAuth, but running cokacdir gives this error.

Error message
Error: Invalid API key Β· Fix external API key

Cause: API key takes priority over OAuth

Claude CLI checks authentication in this order:

  1. Environment variable ANTHROPIC_API_KEY β€” if present, always uses this
  2. OAuth token (.credentials.json) β€” only when env var is absent

If an old invalid/expired API key remains, it overrides your working OAuth login.

Solution

Step 1: Check the environment variable

PowerShell
echo $env:ANTHROPIC_API_KEY

If a value is printed β†’ that’s the culprit. If nothing appears, go to step 2.

Step 2: Remove the environment variable

PowerShell β€” remove from current session
$env:ANTHROPIC_API_KEY = ""
PowerShell β€” permanently remove (system-wide)
[System.Environment]::SetEnvironmentVariable("ANTHROPIC_API_KEY", $null, "User")

Or go to System Properties β†’ Environment Variables and delete ANTHROPIC_API_KEY directly.

Step 3: Verification test

PowerShell
claude -p "hello"

If you get a normal response, OAuth auth is working. Re-run cokacdir.

Additional places to check

API keys can hide in other places besides environment variables:

  • A set ANTHROPIC_API_KEY=... line inside the cokacdir launch BAT file
  • A .env file in the workspace folder
  • An apiKey setting in %USERPROFILE%\.claude\settings.json

Check all of these and delete any API key entries.

Error: OS error 193

Running cokacdir produces this error.

Error message
OS error 193: %1 is not a valid Win32 application

Cause: claude.cmd β‰  claude.exe

Cokacdir (a Rust binary) internally runs claude -p "message". However, installing via npm install -g @anthropic-ai/claude-code on Windows creates claude.cmd (a batch file), not claude.exe.

Rust programs cannot execute .cmd files directly. It’s like being told β€œthis file is not a program.”

Understanding the Issue

πŸ“¦
What npm installsclaude.cmd (batch file β€” a text script)
βš™οΈ
What cokacdir looks forclaude.exe (native executable)
❌
Result.cmd is not .exe β†’ OS error 193

Solution: Create an EXE shim

You need to create a real .exe file that wraps claude.cmd. Let Claude Code handle it.

Type in Claude Code
When cokacdir tries to run claude, I get "OS error 193".
The issue is npm's claude.cmd can't be recognized as .exe by the Rust binary.
Fix this so claude.cmd can be executed properly.

Claude Code will automatically perform these steps:

1Locate claude.cmd (where claude)
2Write a wrapper script that calls claude.cmd via Node.js
3Compile wrapper to .exe or adjust PATH priority
4Test that the claude command works correctly

Want to fix it manually?

Find the folder containing claude.cmd (usually %APPDATA%\npm\), and place a wrapper EXE in the same path that runs claude.cmd via cmd.exe /c.

PowerShell β€” find claude.cmd location
where.exe claude

This involves manual work, so we recommend letting Claude Code handle it. AI does it in 30 seconds.

Creating an Auto-Start BAT File

Instead of opening PowerShell and typing commands each time, create a BAT file that starts cokacdir with a single double-click.

start-bot.bat β€” create in Notepad and save
@echo off
cd /d "C:\Users\YourUser\my-ai-bot"
set CLAUDE_CODE_BUBBLEWRAP=1
start "MyBot" cokacdir.exe --ccserver paste-your-bot-token-here
πŸ“

cd /d path

The workspace folder containing CLAUDE.md. The bot's role/rules are determined by this file.

πŸ”’

CLAUDE_CODE_BUBBLEWRAP=1

Sandbox mode. Prevents the bot from making system changes.

🚫

No ANTHROPIC_API_KEY

We use OAuth authentication, so don't add an API key. Adding one causes Invalid API key errors!

Auto-start on Windows boot

Win + R β†’ type shell:startup β†’ place a shortcut to the BAT file in the opened folder. The bot starts automatically every time you turn on your PC.

If it still doesn't work, check these

Check these 5 things and you can diagnose most issues:

  1. claude --version β€” Verify CLI version
  2. echo $env:ANTHROPIC_API_KEY β€” Check API key env var
  3. where.exe claude β€” Check claude executable path
  4. Full contents of the launch BAT file
  5. Complete error log from cokacdir execution

Use Case 1: Send & Receive Files

In Telegram
[Attach Excel file]

Analyze this sales data,
create a monthly trend chart,
and send me the report

What AI does:

  1. Saves the attached file to your PC
  2. Analyzes data with Python
  3. Generates chart images
  4. Compiles into a report file
  5. Sends the result file back via Telegram

Complete a report on the subway

Send Excel from the subway β†’ your home PC analyzes it β†’ the report arrives in Telegram.

Use Case 2: 24/7 Auto Assistant

Conversation example
πŸ‘€ "Every morning at 8am, send me the weather and news summary"

πŸ€– Schedule registered! Will run daily at 08:00.

─────── Next morning 8:00 ───────

πŸ€– Good morning!
🌀️ New York: Sunny, 54°F
πŸ“° 3 news summaries sent

Just keep your PC on and the bot works while you sleep, sending results to you.

Use Case 3: One-Line Command β†’ Complete Report

In Telegram
"Research the 2026 AI market trends and create a report"

πŸ€– Web search β†’ Analysis β†’ Chart generation...

πŸ€– Done! πŸ“Ž AI_Market_Trends_2026.html (with charts)
πŸ”

Web search

Collects latest data in real-time

πŸ“

Analysis & organization

AI extracts and organizes key points

πŸ“Š

Report generation

Sends as a complete file with charts

Advanced prompt: Report hub

"Create a report archiving web page. Scan .html files in the current folder, auto-extract title, date, and category, and build a card list with category filters. Serve on port 5321 so phones on the same Wi-Fi can access it." β€” Long, detailed instructions like this are handled in one shot.

Use Case 4: Receipts β†’ Auto Expense Tracker

Whenever you have a moment
πŸ‘€ [Receipt photo πŸ“Έ]
πŸ€– Saved! Starbucks $6.50 (Cafe)

πŸ‘€ [Receipt photo πŸ“Έ]
πŸ€– Saved! Convenience store $12.30 (Food)

πŸ‘€ [Card notification screenshot πŸ“±]
πŸ€– Saved! Amazon $45.90 (Online shopping)
At month end
πŸ‘€ "Create this month's expense report"

πŸ€– March expense report complete!
πŸ“Ž March_Expense_Report.html
Β· Total $1,842.50
Β· Category chart included

No expense tracking app needed. Just snap receipts and send to Telegram. AI manages the cumulative data, and one sentence at month-end produces a chart-included report.

Use Case 5: Multi-Bot by Project

Create additional bots with BotFather and run another cokacdir instance. Switch between purpose-specific AI assistants like switching Telegram chats.

πŸ’Ό

Work bot

  • Β· Report writing
  • Β· Email drafts
  • Β· Data analysis
πŸ“š

Study bot

  • Β· Language practice
  • Β· Exam prep
  • Β· Paper summaries
🏠

Life bot

  • Β· Recipe suggestions
  • Β· Expense tracking
  • Β· Schedule reminders

Each bot has independent conversations & memory

Each bot has its own conversation context. What you tell the work bot, the study bot doesn’t know.

Use Case 6: AI That Remembers You

Conversation example
── March 3 ──

πŸ‘€ "I can't eat spicy food. Remember that."
πŸ€– Noted! I'll exclude spicy food from now on.

── One week later ──

πŸ‘€ "What should I have for lunch?"
πŸ€– Excluding spicy food, here are my suggestions!
🍝 Cream pasta β€” "Pasta Place" near downtown (5 min walk)
🍱 Salmon poke β€” "Poke Salad" (8 min walk)

Conversation history is saved on your PC. The longer you use it, the better AI knows you. Unlike ChatGPT, data exists only on your computer, so your privacy is protected.

Key Takeaways

1Cokacdir runs on your Windows PC with your own Pro subscription β†’ policy compliant
2Setup is 3 steps β€” create bot β†’ install cokacdir β†’ run β†’ done!
3OpenClaw is convenient but violates policy β†’ account ban risk
4Key difference is auth method β€” credentials to third party vs. directly on your PC
5One Telegram bot lets you remote-control AI from anywhere

Your AI, safely, from anywhere

Take the AI that used to be stuck at your terminal and carry it in your pocket. With Telegram, file analysis, auto-scheduling, web research, report generation, code execution, translation, and more β€” all from your phone.