Claude-to-IM

作者 op7418

Host-agnostic bridge connecting Claude Code SDK to IM platforms (Telegram, Discord, Feishu)

471
Stars
105
Forks
TypeScript
语言
2026/8/23
添加时间

⚠️ 第三方软件声明

本 Skill 为第三方开源软件,独立托管于 GitHub。SkillTip 仅为信息目录,不控制或维护底层仓库。所显示的安全检查为自动化且范围有限,安装前请自行审查源码。

阅读服务条款

安装

添加到你的 Claude Code skills 目录:

# Add to your Claude Code skills
git clone https://github.com/op7418/Claude-to-IM

快速入门

使用 Claude-to-IM 等 Skills 的指南。

安全报告

已验证

上次扫描:—

{
  "status": "PASSED",
  "issues": []
}

README.md

Claude-to-IM

English | 中文

Claude-to-IM is a host-agnostic bridge library that connects Claude Code SDK to IM platforms, allowing users to interact with Claude through Telegram, Discord, and Feishu (Lark).

This library handles all IM-side complexity — message routing, streaming previews, permission approval flows, Markdown rendering, chunking, retry, rate limiting — while delegating persistence, LLM calls, and permission resolution to the host application through a set of dependency injection interfaces.

Out-of-the-Box Solution

If you want a ready-to-use desktop application without writing any integration code, check out CodePilot — a desktop GUI client for Claude Code with built-in IM bridge support. CodePilot implements all the host interfaces for you and provides a complete UI for managing sessions, settings, and bridge connections.

Claude-to-IM was extracted from CodePilot as a standalone library for developers who want to embed the IM bridge capability in their own applications.

Features

  • Multi-platform adapters: Telegram (long polling), Discord (Gateway WebSocket), Feishu/Lark (WSClient)
  • Streaming previews: Real-time response drafts via message editing, with per-platform throttling
  • Permission management: Interactive inline buttons for Claude Code tool approvals (allow / deny / allow for session)
  • Session binding: Each IM chat maps to a persistent conversation session with working directory and model settings
  • Markdown rendering: Platform-native formatting — HTML for Telegram, Discord-flavored Markdown, Feishu rich text cards
  • Reliable delivery: Auto-chunking at platform limits, retry with exponential backoff, HTML fallback on parse errors, message deduplication
  • Security: Input validation, token bucket rate limiting (20 msg/min per chat), user authorization whitelists, full audit logging
  • Host-agnostic: All host dependencies abstracted via 4 DI interfaces — no database driver, no LLM client, no framework lock-in

Architecture

IM Platform (Telegram / Discord / Feishu)
        |
        | InboundMessage
        v
   +-----------+     +------------------+
   |  Adapter   |---->| Bridge Manager   |  (orchestrator)
   +-----------+     |  |- Channel Router     -> session binding
                     |  |- Conversation Engine -> LLM streaming
                     |  |- Permission Broker   -> tool approval flow
                     |  |- Delivery Layer      -> chunking, retry, dedup
                     +------------------+
                            |
                            | Host Interfaces (DI)
                            v
                     +------------------+
                     | Host Application |  (implements BridgeStore,
                     |                  |   LLMProvider, etc.)
                     +------------------+

All bridge modules access host services through a DI context (getBridgeContext()), never through direct imports. This means you can plug the bridge into any Node.js application by implementing four interfaces.

Quick Start

1. Install

npm install claude-to-im

Or clone this repo and install dependencies:

git clone https://github.com/op7418/Claude-to-IM.git
cd Claude-to-IM
npm install

2. Implement Host Interfaces

The bridge requires four interfaces. See docs/development.md for the full specification of each interface.

import { initBridgeContext } from 'claude-to-im/context';
import type { BridgeStore, LLMProvider, PermissionGateway, LifecycleHooks } from 'claude-to-im/host';

const store: BridgeStore = { /* your persistence layer (~30 methods) */ };
const llm: LLMProvider = { /* wraps Claude Code SDK streamChat */ };
const permissions: PermissionGateway = { /* resolves pending tool permissions */ };
const lifecycle: LifecycleHooks = { /* optional start/stop callbacks */ };

initBridgeContext({ store, llm, permissions, lifecycle });

3. Start the Bridge

import * as bridgeManager from 'claude-to-im/bridge-manager';

await bridgeManager.start();

const status = bridgeManager.getStatus();
// { running: true, adapters: [{ channelType: 'telegram', running: true, ... }] }

4. Run the Example

A self-contained example with in-memory store and echo LLM is included:

npx tsx src/lib/bridge/examples/mock-host.ts

Configuration

All settings are read through BridgeStore.getSetting(key). Your host application decides how to store and surface these values (database, env vars, config file, UI settings panel, etc.).

Required Settings

KeyDescription
remote_bridge_enabledMaster switch — "true" to enable the bridge
bridge_{adapter}_bot_tokenBot token for the platform (e.g. bridge_telegram_bot_token)
bridge_{adapter}_allowed_usersComma-separated user IDs authorized to use the bridge

Optional Settings

KeyDescriptionDefault
bridge_auto_startAuto-start bridge on app launch"false"
bridge_{adapter}_enabledPer-adapter toggle"false"
bridge_{adapter}_stream_enabledEnable streaming previews"true"
bridge_default_cwdDefault working directory for new sessions$HOME
bridge_modelDefault Claude modelHost decides

Replace {adapter} with telegram, discord, or feishu.

Limitations

Before adopting this library, be aware of the following constraints:

You Must Implement the Host Interfaces

This is a library, not a standalone application. You need to provide:

  • BridgeStore — A persistence layer with ~30 methods covering settings, sessions, messages, channel bindings, audit logs, dedup tracking, permission links, and channel offsets. This is the largest integration surface. See the full interface definition in src/lib/bridge/host.ts.
  • LLMProvider — A wrapper around your LLM client that returns a ReadableStream<string> of SSE-formatted events. The stream format must match the Claude Code SDK's event protocol (text, tool_use, tool_result, permission_request, status, result events). See docs/development.md for the full event format spec.
  • PermissionGateway — A way to resolve pending tool permissions from the Claude Code SDK.
  • LifecycleHooks — Optional callbacks for bridge start/stop events.

LLM Stream Format

The LLMProvider.streamChat() must return SSE-formatted strings matching the Claude Code SDK's event protocol. If you are not using the Claude Code SDK, you need to adapt your LLM client's output to match this format. This is not a generic "chat completion" interface.

No Built-in Persistence

The bridge does not bundle any database driver. You provide all persistence through BridgeStore. This gives you full control but means you need to implement storage for sessions, messages, bindings, audit logs, dedup keys, permission links, and channel offsets.

Session Locking

The bridge uses a session lock mechanism (acquireSessionLock / renewSessionLock / releaseSessionLock) to serialize messages within the same session. Your BridgeStore implementation must provide atomic lock operations. For single-process deployments, in-memory locks work fine. For multi-process deployments, you need distributed locking (e.g., database-backed).

Platform Bot Setup

You still need to create bots on each platform and obtain tokens:

Documentation

DocumentDescription
Development GuideHost interface specs, SSE format, adapter development, step-by-step integration tutorial
ArchitectureModule dependency graph, message flows, design decisions
SecurityThreat model, mitigations, deployment recommendations
ContributingDev setup, code style, testing guide
MigrationBefore/after import patterns for migrating from direct imports

Project Structure

src/
  lib/bridge/
    context.ts              # DI container (initBridgeContext / getBridgeContext)
    host.ts                 # Host interface definitions (BridgeStore, LLMProvider, etc.)
    types.ts                # Shared type definitions (messages, bindings, status)
    bridge-manager.ts       # Orchestrator — start/stop, message dispatch, session locks
    channel-adapter.ts      # Abstract base class + adapter registry
    channel-router.ts       # ChannelAddress -> ChannelBinding resolution
    conversation-engine.ts  # LLM stream processing, SSE consumption
    delivery-layer.ts       # Reliable outbound delivery (chunk, retry, dedup, audit)
    permission-broker.ts    # Tool permission forwarding and callback handling
    adapters/
      telegram-adapter.ts   # Telegram Bot API long polling
      discord-adapter.ts    # Discord.js Gateway WebSocket
      feishu-adapter.ts     # Feishu/Lark WSClient
      telegram-media.ts     # Telegram file download/attachment handling
      telegram-utils.ts     # Telegram API helpers
      index.ts              # Side-effect imports for adapter self-registration
    markdown/
      ir.ts                 # Intermediate representation for Markdown AST
      render.ts             # Generic IR -> platform string renderer
      telegram.ts           # Markdown -> Telegram HTML
      discord.ts            # Markdown -> Discord-flavored Markdown
      feishu.ts             # Markdown -> Feishu rich text / cards
    security/
      validators.ts         # Input validation (path traversal, injection, sanitization)
      rate-limiter.ts       # Token bucket rate limiter (per chat)
    examples/
      mock-host.ts          # Runnable example with InMemoryStore + EchoLLM
  __tests__/unit/
    bridge-channel-router.test.ts
    bridge-delivery-layer.test.ts
    bridge-manager.test.ts
    bridge-permission-broker.test.ts

Testing

# Type checking
npm run typecheck

# Unit tests (28 tests)
npm run test:unit

# Both
npm run test

Tests use Node.js built-in test runner (node:test) with mock implementations of all host interfaces — no real database or LLM required.

License

MIT

常见问题

What is Claude-to-IM?

Claude-to-IM is an open-source ai agents skill for AI coding assistants such as Claude Code, Codex CLI, and ChatGPT, built by op7418. Host-agnostic bridge connecting Claude Code SDK to IM platforms (Telegram, Discord, Feishu). It has 471 GitHub stars.

Is Claude-to-IM safe to use?

Claude-to-IM failed SkillsLLM's automated security scan, which flagged one or more high-severity issues. Review the Security Report section carefully before using it.

How do I install Claude-to-IM?

Clone the repository with "git clone https://github.com/op7418/Claude-to-IM" and add it to your Claude Code skills directory (see the Installation section above).

What programming language is Claude-to-IM written in?

Claude-to-IM is primarily written in TypeScript. It is open-source under op7418 on GitHub, so you can review or fork the full source.

Are there alternatives to Claude-to-IM?

Yes. SkillsLLM lists many other AI Agents skills you can browse and compare side by side. Open the AI Agents category from the badge at the top of this page, or use the Related Skills and comparison links further down to weigh Claude-to-IM against similar tools.

评论 (0)

暂无评论,成为第一个分享想法的人!

ECC

by affaan-m

10

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

242,21936,702JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情
15

An agentic skills framework & software development methodology that works.

234,96620,863Shell
AI 智能体ai-agentsbrainstorming
查看详情

hermes-agent

by NousResearch

10

The agent that grows with you

234,43747,175Python
AI 智能体ai-agentsagent-orchestration
查看详情

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

185,94028,768JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情

cc-switch

by farion1231

3

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io

128,8688,826Rust
AI 智能体claude-codeai-tools
查看详情

claude-code

by anthropics

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

120,03119,897Shell
AI 智能体
查看详情

开发者还喜欢

基于喜欢此 Skill 的开发者投票和收藏

ECC

by affaan-m

10

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

242,21936,702JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情
15

An agentic skills framework & software development methodology that works.

234,96620,863Shell
AI 智能体ai-agentsbrainstorming
查看详情

hermes-agent

by NousResearch

10

The agent that grows with you

234,43747,175Python
AI 智能体ai-agentsagent-orchestration
查看详情

n8n

by n8n-io

12

Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.

201,88160,308TypeScript
MCP 服务器apisai-tools
查看详情

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

185,94028,768JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情

cc-switch

by farion1231

3

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io

128,8688,826Rust
AI 智能体claude-codeai-tools
查看详情