@gonzih/cc-tg 0.2.21 → 0.2.23
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +27 -6
- package/package.json +1 -1
- package/dist/bot.d.ts +0 -50
- package/dist/bot.js +0 -1100
- package/dist/claude.d.ts +0 -54
- package/dist/claude.js +0 -208
- package/dist/cron.d.ts +0 -33
- package/dist/cron.js +0 -127
- package/dist/index.d.ts +0 -16
- package/dist/index.js +0 -94
- package/dist/voice.d.ts +0 -13
- package/dist/voice.js +0 -124
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# cc-tg
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@gonzih/cc-tg)
|
|
4
|
+
|
|
3
5
|
Claude Code Telegram bot. Chat with Claude Code from Telegram — text, voice, images, files, scheduled prompts, and bot management commands.
|
|
4
6
|
|
|
5
7
|
Built by [@Gonzih](https://github.com/Gonzih).
|
|
@@ -11,7 +13,7 @@ Built by [@Gonzih](https://github.com/Gonzih).
|
|
|
11
13
|
**Step 2** — run:
|
|
12
14
|
|
|
13
15
|
```bash
|
|
14
|
-
TELEGRAM_BOT_TOKEN=your_bot_token
|
|
16
|
+
TELEGRAM_BOT_TOKEN=your_bot_token CLAUDE_CODE_TOKEN=your_claude_token npx @gonzih/cc-tg
|
|
15
17
|
```
|
|
16
18
|
|
|
17
19
|
Open your bot in Telegram and start chatting.
|
|
@@ -21,12 +23,13 @@ Open your bot in Telegram and start chatting.
|
|
|
21
23
|
| Variable | Required | Description |
|
|
22
24
|
|----------|----------|-------------|
|
|
23
25
|
| `TELEGRAM_BOT_TOKEN` | yes | From @BotFather |
|
|
24
|
-
| `
|
|
26
|
+
| `CLAUDE_CODE_TOKEN` | yes* | Claude Code OAuth token (starts with `sk-ant-oat`) |
|
|
27
|
+
| `CLAUDE_CODE_OAUTH_TOKEN` | yes* | Alias for `CLAUDE_CODE_TOKEN` |
|
|
25
28
|
| `ANTHROPIC_API_KEY` | yes* | Alternative — API key from console.anthropic.com |
|
|
26
29
|
| `ALLOWED_USER_IDS` | no | Comma-separated Telegram user IDs. Leave empty to allow anyone |
|
|
27
30
|
| `CWD` | no | Working directory for Claude Code. Defaults to current directory |
|
|
28
31
|
|
|
29
|
-
*One of `CLAUDE_CODE_OAUTH_TOKEN
|
|
32
|
+
*One of `CLAUDE_CODE_TOKEN`, `CLAUDE_CODE_OAUTH_TOKEN`, or `ANTHROPIC_API_KEY` required.
|
|
30
33
|
|
|
31
34
|
## Get your Claude Code token
|
|
32
35
|
|
|
@@ -47,15 +50,18 @@ Message [@userinfobot](https://t.me/userinfobot) — it replies with your numeri
|
|
|
47
50
|
| `/start` or `/reset` | Kill current Claude session and start fresh |
|
|
48
51
|
| `/stop` | Interrupt the running Claude task |
|
|
49
52
|
| `/status` | Check if a session is active |
|
|
53
|
+
| `/cost` | Show session token usage and cost |
|
|
50
54
|
| `/help` | Show all available commands |
|
|
51
55
|
| `/cron every 1h <prompt>` | Schedule a recurring prompt |
|
|
52
56
|
| `/cron list` | Show active cron jobs (numbered) |
|
|
53
57
|
| `/cron edit <#> [schedule/prompt] <value>` | Edit a cron job in place |
|
|
54
58
|
| `/cron remove <id>` | Remove a specific cron job |
|
|
55
59
|
| `/cron clear` | Remove all cron jobs |
|
|
56
|
-
| `/reload_mcp` |
|
|
60
|
+
| `/reload_mcp` | Restart the cc-agent MCP server process |
|
|
61
|
+
| `/mcp_status` | Check MCP server connection status |
|
|
57
62
|
| `/mcp_version` | Show latest published cc-agent npm version and current cache |
|
|
58
63
|
| `/clear_npx_cache` | Clear npx cache and reload cc-agent (upgrades to latest version) |
|
|
64
|
+
| `/get_file <path>` | Send a file from the server to this chat |
|
|
59
65
|
| `/restart` | Self-restart the cc-tg bot process (no SSH needed) |
|
|
60
66
|
| Any text | Sent directly to Claude Code |
|
|
61
67
|
| Voice message | Transcribed via whisper.cpp and sent to Claude |
|
|
@@ -79,6 +85,9 @@ Send any file → downloaded to `<CWD>/.cc-tg/uploads/<filename>` → Claude rec
|
|
|
79
85
|
### File delivery
|
|
80
86
|
When Claude writes a file and mentions it in the response, the bot automatically uploads it to Telegram. Tracks `Write`/`Edit` tool calls during the session, cross-references with filenames in the final response.
|
|
81
87
|
|
|
88
|
+
### Cost tracking
|
|
89
|
+
`/cost` shows total input/output tokens and estimated USD cost for the current session.
|
|
90
|
+
|
|
82
91
|
### Cron jobs
|
|
83
92
|
Schedule recurring prompts on a timer:
|
|
84
93
|
|
|
@@ -101,6 +110,7 @@ Cron jobs persist to `<CWD>/.cc-tg/crons.json` and restore on restart. Output is
|
|
|
101
110
|
Manage the cc-agent MCP server from Telegram without SSH:
|
|
102
111
|
|
|
103
112
|
- `/reload_mcp` — sends SIGTERM to the cc-agent process; Claude Code auto-restarts it on next tool call. Useful after updating cc-agent config.
|
|
113
|
+
- `/mcp_status` — runs `claude mcp list` and shows the current connection status of all MCP servers.
|
|
104
114
|
- `/mcp_version` — shows the latest `@gonzih/cc-agent` version on npm and what's in your local npx cache.
|
|
105
115
|
- `/clear_npx_cache` — deletes `~/.npm/_npx/` and kills cc-agent, forcing a fresh download of the latest version on next use.
|
|
106
116
|
|
|
@@ -113,6 +123,17 @@ While Claude is working, the bot sends a continuous typing indicator. Works for
|
|
|
113
123
|
### Bot command menu
|
|
114
124
|
All commands are registered with Telegram's `/` menu via `setMyCommands` on startup — no need to remember commands.
|
|
115
125
|
|
|
126
|
+
## Architecture
|
|
127
|
+
|
|
128
|
+
cc-tg is a thin Telegram adapter over Claude Code:
|
|
129
|
+
|
|
130
|
+
1. **Bot layer** (`src/bot.ts`) — handles Telegram updates, routes commands, manages per-chat Claude subprocesses.
|
|
131
|
+
2. **Claude runner** (`src/claude.ts`) — spawns `claude` CLI as a subprocess per chat, streams output back, tracks token costs.
|
|
132
|
+
3. **Cron manager** (`src/cron.ts`) — persistent cron scheduler that fires prompts at configured intervals and delivers results to Telegram.
|
|
133
|
+
4. **Voice handler** (`src/voice.ts`) — downloads Telegram voice messages, converts via ffmpeg, transcribes with whisper.cpp.
|
|
134
|
+
|
|
135
|
+
cc-tg works with the [cc-agent](https://github.com/Gonzih/cc-agent) MCP server to enable Claude Code subagent spawning. When cc-agent is configured as an MCP server in your Claude Code setup, `/reload_mcp` and `/mcp_status` let you manage it remotely without SSH.
|
|
136
|
+
|
|
116
137
|
## Run persistently
|
|
117
138
|
|
|
118
139
|
### macOS launchd
|
|
@@ -134,7 +155,7 @@ All commands are registered with Telegram's `/` menu via `setMyCommands` on star
|
|
|
134
155
|
<dict>
|
|
135
156
|
<key>TELEGRAM_BOT_TOKEN</key>
|
|
136
157
|
<string>your_token</string>
|
|
137
|
-
<key>
|
|
158
|
+
<key>CLAUDE_CODE_TOKEN</key>
|
|
138
159
|
<string>your_claude_token</string>
|
|
139
160
|
<key>ALLOWED_USER_IDS</key>
|
|
140
161
|
<string>your_telegram_id</string>
|
|
@@ -171,7 +192,7 @@ Description=cc-tg Claude Code Telegram bot
|
|
|
171
192
|
|
|
172
193
|
[Service]
|
|
173
194
|
Environment=TELEGRAM_BOT_TOKEN=xxx
|
|
174
|
-
Environment=
|
|
195
|
+
Environment=CLAUDE_CODE_TOKEN=yyy
|
|
175
196
|
Environment=ALLOWED_USER_IDS=123456789
|
|
176
197
|
Environment=CWD=/home/you/your-project
|
|
177
198
|
WorkingDirectory=/home/you/your-project
|
package/package.json
CHANGED
package/dist/bot.d.ts
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Telegram bot that routes messages to/from a Claude Code subprocess.
|
|
3
|
-
* One ClaudeProcess per chat_id — sessions are isolated per user.
|
|
4
|
-
*/
|
|
5
|
-
export interface BotOptions {
|
|
6
|
-
telegramToken: string;
|
|
7
|
-
claudeToken?: string;
|
|
8
|
-
cwd?: string;
|
|
9
|
-
allowedUserIds?: number[];
|
|
10
|
-
}
|
|
11
|
-
export declare class CcTgBot {
|
|
12
|
-
private bot;
|
|
13
|
-
private sessions;
|
|
14
|
-
private opts;
|
|
15
|
-
private cron;
|
|
16
|
-
private costStore;
|
|
17
|
-
constructor(opts: BotOptions);
|
|
18
|
-
private registerBotCommands;
|
|
19
|
-
private isAllowed;
|
|
20
|
-
private handleTelegram;
|
|
21
|
-
private handleVoice;
|
|
22
|
-
private handlePhoto;
|
|
23
|
-
private handleDocument;
|
|
24
|
-
private getOrCreateSession;
|
|
25
|
-
private handleClaudeMessage;
|
|
26
|
-
private startTyping;
|
|
27
|
-
private stopTyping;
|
|
28
|
-
private flushPending;
|
|
29
|
-
private trackWrittenFiles;
|
|
30
|
-
private isSensitiveFile;
|
|
31
|
-
private uploadMentionedFiles;
|
|
32
|
-
private extractToolName;
|
|
33
|
-
private runCronTask;
|
|
34
|
-
private handleCron;
|
|
35
|
-
private handleCronEdit;
|
|
36
|
-
/** Find cc-agent PIDs via pgrep. Returns array of numeric PIDs. */
|
|
37
|
-
private findCcAgentPids;
|
|
38
|
-
/** Kill cc-agent PIDs with SIGTERM. Returns the list of killed PIDs. */
|
|
39
|
-
private killCcAgent;
|
|
40
|
-
private handleReloadMcp;
|
|
41
|
-
private handleMcpStatus;
|
|
42
|
-
private handleMcpVersion;
|
|
43
|
-
private handleClearNpxCache;
|
|
44
|
-
private handleRestart;
|
|
45
|
-
private handleGetFile;
|
|
46
|
-
private callCcAgentTool;
|
|
47
|
-
private killSession;
|
|
48
|
-
stop(): void;
|
|
49
|
-
}
|
|
50
|
-
export declare function splitMessage(text: string, maxLen?: number): string[];
|