claude-notification-plugin 1.0.6 → 1.0.13

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/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Michael Makarov
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Michael Makarov
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,113 +1,116 @@
1
- # claude-notification-plugin
2
-
3
- Notifications for Claude Code task completion. Sends alerts to Telegram and Windows when Claude finishes working.
4
-
5
- ## Features
6
-
7
- - Windows desktop notifications (toast)
8
- - Telegram bot messages
9
- - Sound alert
10
- - Voice announcement (TTS)
11
- - Skips short tasks (< 15s by default)
12
- - Granular per-channel enable/disable (globally and per-project)
13
-
14
- ## Install
15
-
16
- ```bash
17
- npm install -g claude-notification-plugin
18
- claude-notify-install
19
- ```
20
-
21
- The installer will:
22
- 1. Ask for Telegram bot credentials (optional)
23
- 2. Create config at `~/.claude/notifier.config.json`
24
- 3. Register hooks in `~/.claude/settings.json`
25
-
26
- ## Configuration
27
-
28
- Config file: `~/.claude/notifier.config.json`
29
-
30
- ```json
31
- {
32
- "telegram": {
33
- "enabled": true,
34
- "token": "YOUR_BOT_TOKEN",
35
- "chatId": "YOUR_CHAT_ID"
36
- },
37
- "windowsNotification": {
38
- "enabled": true
39
- },
40
- "sound": {
41
- "enabled": true,
42
- "file": "C:/Windows/Media/notify.wav"
43
- },
44
- "voice": {
45
- "enabled": true
46
- },
47
- "minSeconds": 15
48
- }
49
- ```
50
-
51
- Each channel has an `enabled` flag (`true`/`false`) for global control.
52
-
53
- Environment variables `TELEGRAM_TOKEN` and `TELEGRAM_CHAT_ID` override config file values.
54
-
55
- ### Per-channel environment variables
56
-
57
- These env vars override the global config per channel (`"1"` = on, `"0"` = off):
58
-
59
- | Variable | Channel |
60
- |--------------------------|----------------------------|
61
- | `CLAUDE_NOTIFY_TELEGRAM` | Telegram messages |
62
- | `CLAUDE_NOTIFY_WINDOWS` | Windows toast notifications|
63
- | `CLAUDE_NOTIFY_SOUND` | Sound alert |
64
- | `CLAUDE_NOTIFY_VOICE` | Voice announcement (TTS) |
65
-
66
- ### Per-project configuration
67
-
68
- Add to `.claude/settings.local.json` in the project root to control channels per project:
69
-
70
- ```json
71
- {
72
- "env": {
73
- "DISABLE_CLAUDE_NOTIFIER": 0,
74
- "CLAUDE_NOTIFY_TELEGRAM": 1,
75
- "CLAUDE_NOTIFY_WINDOWS": 1,
76
- "CLAUDE_NOTIFY_SOUND": 1,
77
- "CLAUDE_NOTIFY_VOICE": 1
78
- }
79
- }
80
- ```
81
-
82
- To disable all notifications for a project:
83
-
84
- ```json
85
- {
86
- "env": {
87
- "DISABLE_CLAUDE_NOTIFIER": "1"
88
- }
89
- }
90
- ```
91
-
92
- ## Telegram Setup
93
-
94
- 1. Open Telegram, find **@BotFather**
95
- 2. Send `/newbot`, follow prompts, pick a name
96
- 3. Copy the bot token (format: `123456789:ABCdef...`)
97
- 4. **Send any message to your new bot**
98
- 5. Open `https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates`
99
- 6. Find `"chat":{"id":123456789}` in the response that's your Chat ID
100
- 7. Run `claude-notify-install` and enter the token and chat ID
101
-
102
- Alternative for Chat ID: add **@userinfobot** to a chat and it will reply with the ID.
103
-
104
- ## Uninstall
105
-
106
- ```bash
107
- claude-notify-uninstall
108
- npm uninstall -g claude-notification-plugin
109
- ```
110
-
111
- ## License
112
-
113
- MIT
1
+ # claude-notification-plugin
2
+
3
+ Notifications for Claude Code task completion. Sends alerts to Telegram and Windows when Claude finishes working.
4
+
5
+ ## Features
6
+
7
+ - Windows desktop notifications (toast)
8
+ - Telegram bot messages
9
+ - Sound alert
10
+ - Voice announcement (TTS)
11
+ - Skips short tasks (< 15s by default)
12
+ - Granular per-channel enable/disable (globally and per-project)
13
+
14
+ ## Install
15
+
16
+ ```bash
17
+ npm install -g claude-notification-plugin
18
+ claude-notify-install
19
+ ```
20
+
21
+ The installer will:
22
+ 1. Ask for Telegram bot credentials (optional)
23
+ 2. Create config at `~/.claude/notifier.config.json`
24
+ 3. Register hooks in `~/.claude/settings.json`
25
+
26
+ ## Configuration
27
+
28
+ Config file: `~/.claude/notifier.config.json`
29
+
30
+ ```json
31
+ {
32
+ "telegram": {
33
+ "enabled": true,
34
+ "token": "YOUR_BOT_TOKEN",
35
+ "chatId": "YOUR_CHAT_ID",
36
+ "deleteAfterHours": 24
37
+ },
38
+ "windowsNotification": {
39
+ "enabled": true
40
+ },
41
+ "sound": {
42
+ "enabled": true,
43
+ "file": "C:/Windows/Media/notify.wav"
44
+ },
45
+ "voice": {
46
+ "enabled": true
47
+ },
48
+ "minSeconds": 15
49
+ }
50
+ ```
51
+
52
+ Each channel has an `enabled` flag (`true`/`false`) for global control.
53
+
54
+ `deleteAfterHours` — auto-delete old Telegram messages after the specified number of hours (default: `24`, set `0` to disable).
55
+
56
+ Environment variables `TELEGRAM_TOKEN` and `TELEGRAM_CHAT_ID` override config file values.
57
+
58
+ ### Per-channel environment variables
59
+
60
+ These env vars override the global config per channel (`"1"` = on, `"0"` = off):
61
+
62
+ | Variable | Channel |
63
+ |--------------------------|----------------------------|
64
+ | `CLAUDE_NOTIFY_TELEGRAM` | Telegram messages |
65
+ | `CLAUDE_NOTIFY_WINDOWS` | Windows toast notifications|
66
+ | `CLAUDE_NOTIFY_SOUND` | Sound alert |
67
+ | `CLAUDE_NOTIFY_VOICE` | Voice announcement (TTS) |
68
+
69
+ ### Per-project configuration
70
+
71
+ Add to `.claude/settings.local.json` in the project root to control channels per project:
72
+
73
+ ```json
74
+ {
75
+ "env": {
76
+ "DISABLE_CLAUDE_NOTIFIER": 0,
77
+ "CLAUDE_NOTIFY_TELEGRAM": 1,
78
+ "CLAUDE_NOTIFY_WINDOWS": 1,
79
+ "CLAUDE_NOTIFY_SOUND": 1,
80
+ "CLAUDE_NOTIFY_VOICE": 1
81
+ }
82
+ }
83
+ ```
84
+
85
+ To disable all notifications for a project:
86
+
87
+ ```json
88
+ {
89
+ "env": {
90
+ "DISABLE_CLAUDE_NOTIFIER": "1"
91
+ }
92
+ }
93
+ ```
94
+
95
+ ## Telegram Setup
96
+
97
+ 1. Open Telegram, find **@BotFather**
98
+ 2. Send `/newbot`, follow prompts, pick a name
99
+ 3. Copy the bot token (format: `123456789:ABCdef...`)
100
+ 4. **Send any message to your new bot**
101
+ 5. Open `https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates`
102
+ 6. Find `"chat":{"id":123456789}` in the response that's your Chat ID
103
+ 7. Run `claude-notify-install` and enter the token and chat ID
104
+
105
+ Alternative for Chat ID: add **@userinfobot** to a chat and it will reply with the ID.
106
+
107
+ ## Uninstall
108
+
109
+ ```bash
110
+ claude-notify-uninstall
111
+ npm uninstall -g claude-notification-plugin
112
+ ```
113
+
114
+ ## License
115
+
116
+ MIT
package/bin/install.js CHANGED
@@ -1,166 +1,178 @@
1
- #!/usr/bin/env node
2
-
3
- import fs from 'fs';
4
- import os from 'os';
5
- import path from 'path';
6
- import readline from 'readline';
7
-
8
- const home = os.homedir();
9
- const claudeDir = path.join(home, '.claude');
10
- const configPath = path.join(claudeDir, 'notifier.config.json');
11
- const settingsPath = path.join(claudeDir, 'settings.json');
12
-
13
- const HOOK_COMMAND = 'claude-notifier';
14
-
15
- // ----------------------
16
- // HELPERS
17
- // ----------------------
18
-
19
- function ask (rl, question) {
20
- return new Promise((resolve) => {
21
- rl.question(question, (answer) => resolve(answer.trim()));
22
- });
23
- }
24
-
25
- async function fetchChatId (token) {
26
- const url = `https://api.telegram.org/bot${token}/getUpdates`;
27
-
28
- try {
29
- const res = await fetch(url);
30
- const data = await res.json();
31
-
32
- if (!data.ok || !data.result?.length) {
33
- return null;
34
- }
35
-
36
- const msg = data.result[data.result.length - 1].message;
37
- if (msg?.chat?.id) {
38
- return String(msg.chat.id);
39
- }
40
- } catch {
41
- // silent fail
42
- }
43
-
44
- return null;
45
- }
46
-
47
- function addHook (settings, event) {
48
- if (!settings.hooks[event]) {
49
- settings.hooks[event] = [];
50
- }
51
-
52
- const exists = settings.hooks[event].some((matcher) =>
53
- matcher.hooks?.some((h) => h.command?.includes(HOOK_COMMAND)),
54
- );
55
-
56
- if (!exists) {
57
- settings.hooks[event].push({
58
- hooks: [
59
- {
60
- type: 'command',
61
- command: HOOK_COMMAND,
62
- },
63
- ],
64
- });
65
- }
66
- }
67
-
68
- // ----------------------
69
- // MAIN
70
- // ----------------------
71
-
72
- async function main () {
73
- const rl = readline.createInterface({
74
- input: process.stdin,
75
- output: process.stdout,
76
- });
77
-
78
- console.log('');
79
- console.log('Claude Notification Plugin - Setup');
80
- console.log('==================================');
81
- console.log('');
82
-
83
- // Telegram setup
84
- let token = '';
85
- let chatId = '';
86
-
87
- const useTelegram = await ask(rl, 'Configure Telegram? (y/N): ');
88
-
89
- if (useTelegram.toLowerCase() === 'y') {
90
- token = await ask(rl, 'Bot Token: ');
91
-
92
- if (token) {
93
- console.log('');
94
- console.log('Send any message to your bot in Telegram, then press Enter.');
95
- await ask(rl, '');
96
-
97
- console.log('Fetching Chat ID...');
98
- chatId = await fetchChatId(token);
99
-
100
- if (chatId) {
101
- console.log('Chat ID detected: ' + chatId);
102
- } else {
103
- console.log('Could not detect Chat ID automatically.');
104
- chatId = await ask(rl, 'Enter Chat ID manually: ');
105
- }
106
- }
107
- }
108
-
109
- rl.close();
110
-
111
- // Create config
112
- fs.mkdirSync(claudeDir, { recursive: true });
113
-
114
- const config = {
115
- telegram: { enabled: true, token, chatId },
116
- windowsNotification: { enabled: true },
117
- sound: { enabled: true, file: 'C:/Windows/Media/notify.wav' },
118
- voice: { enabled: true },
119
- minSeconds: 15,
120
- };
121
-
122
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
123
-
124
- // Patch settings.json
125
- let settings = {};
126
-
127
- if (fs.existsSync(settingsPath)) {
128
- try {
129
- settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
130
- } catch {
131
- settings = {};
132
- }
133
- }
134
-
135
- settings.hooks = settings.hooks || {};
136
-
137
- addHook(settings, 'UserPromptSubmit');
138
- addHook(settings, 'Stop');
139
- addHook(settings, 'Notification');
140
-
141
- fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
142
-
143
- // Output
144
- console.log('');
145
- console.log('Installed!');
146
- console.log('');
147
- console.log('Hooks registered:');
148
- console.log(' - UserPromptSubmit (start timer)');
149
- console.log(' - Stop (task finished)');
150
- console.log(' - Notification (waiting for input)');
151
- console.log('');
152
- console.log('Config: ' + configPath);
153
-
154
- if (token) {
155
- console.log('Telegram: configured');
156
- } else {
157
- console.log('Telegram: skipped (edit config later)');
158
- }
159
-
160
- console.log('');
161
- console.log('To disable per project, add to .claude/settings.local.json:');
162
- console.log(' { "env": { "DISABLE_CLAUDE_NOTIFIER": "1" } }');
163
- console.log('');
164
- }
165
-
166
- main().then(() => 0);
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'fs';
4
+ import os from 'os';
5
+ import path from 'path';
6
+ import readline from 'readline';
7
+
8
+ const home = os.homedir();
9
+ const claudeDir = path.join(home, '.claude');
10
+ const configPath = path.join(claudeDir, 'notifier.config.json');
11
+ const settingsPath = path.join(claudeDir, 'settings.json');
12
+
13
+ const HOOK_COMMAND = 'claude-notifier';
14
+
15
+ // ----------------------
16
+ // HELPERS
17
+ // ----------------------
18
+
19
+ function ask (rl, question) {
20
+ return new Promise((resolve) => {
21
+ rl.question(question, (answer) => resolve(answer.trim()));
22
+ });
23
+ }
24
+
25
+ async function fetchChatId (token) {
26
+ const url = `https://api.telegram.org/bot${token}/getUpdates`;
27
+
28
+ try {
29
+ const res = await fetch(url);
30
+ const data = await res.json();
31
+
32
+ if (!data.ok || !data.result?.length) {
33
+ return null;
34
+ }
35
+
36
+ const msg = data.result[data.result.length - 1].message;
37
+ if (msg?.chat?.id) {
38
+ return String(msg.chat.id);
39
+ }
40
+ } catch {
41
+ // silent fail
42
+ }
43
+
44
+ return null;
45
+ }
46
+
47
+ function addHook (settings, event) {
48
+ if (!settings.hooks[event]) {
49
+ settings.hooks[event] = [];
50
+ }
51
+
52
+ const exists = settings.hooks[event].some((matcher) =>
53
+ matcher.hooks?.some((h) => h.command?.includes(HOOK_COMMAND)),
54
+ );
55
+
56
+ if (!exists) {
57
+ settings.hooks[event].push({
58
+ hooks: [
59
+ {
60
+ type: 'command',
61
+ command: HOOK_COMMAND,
62
+ },
63
+ ],
64
+ });
65
+ }
66
+ }
67
+
68
+ // ----------------------
69
+ // MAIN
70
+ // ----------------------
71
+
72
+ async function main () {
73
+ const rl = readline.createInterface({
74
+ input: process.stdin,
75
+ output: process.stdout,
76
+ });
77
+
78
+ console.log('');
79
+ console.log('Claude Notification Plugin - Setup');
80
+ console.log('==================================');
81
+ console.log('');
82
+
83
+ // Telegram setup
84
+ let token = '';
85
+ let chatId = '';
86
+
87
+ const useTelegram = await ask(rl, 'Configure Telegram? (y/N): ');
88
+
89
+ if (useTelegram.toLowerCase() === 'y') {
90
+ token = await ask(rl, 'Bot Token: ');
91
+
92
+ if (token) {
93
+ console.log('');
94
+ console.log('Send any message to your bot in Telegram, then press Enter.');
95
+ await ask(rl, '');
96
+
97
+ console.log('Fetching Chat ID...');
98
+ chatId = await fetchChatId(token);
99
+
100
+ if (chatId) {
101
+ console.log('Chat ID detected: ' + chatId);
102
+ } else {
103
+ console.log('Could not detect Chat ID automatically.');
104
+ chatId = await ask(rl, 'Enter Chat ID manually: ');
105
+ }
106
+ }
107
+ }
108
+
109
+ rl.close();
110
+
111
+ // Create config
112
+ fs.mkdirSync(claudeDir, { recursive: true });
113
+
114
+ const config = {
115
+ telegram: {
116
+ enabled: true,
117
+ token,
118
+ chatId,
119
+ deleteAfterHours: 24,
120
+ },
121
+ windowsNotification: {
122
+ enabled: true,
123
+ },
124
+ sound: {
125
+ enabled: true,
126
+ file: 'C:/Windows/Media/notify.wav',
127
+ },
128
+ voice: {
129
+ enabled: true,
130
+ },
131
+ minSeconds: 15,
132
+ };
133
+
134
+ fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
135
+
136
+ // Patch settings.json
137
+ let settings = {};
138
+
139
+ if (fs.existsSync(settingsPath)) {
140
+ try {
141
+ settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
142
+ } catch {
143
+ settings = {};
144
+ }
145
+ }
146
+
147
+ settings.hooks = settings.hooks || {};
148
+
149
+ addHook(settings, 'UserPromptSubmit');
150
+ addHook(settings, 'Stop');
151
+ addHook(settings, 'Notification');
152
+
153
+ fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
154
+
155
+ // Output
156
+ console.log('');
157
+ console.log('Installed!');
158
+ console.log('');
159
+ console.log('Hooks registered:');
160
+ console.log(' - UserPromptSubmit (start timer)');
161
+ console.log(' - Stop (task finished)');
162
+ console.log(' - Notification (waiting for input)');
163
+ console.log('');
164
+ console.log('Config: ' + configPath);
165
+
166
+ if (token) {
167
+ console.log('Telegram: configured');
168
+ } else {
169
+ console.log('Telegram: skipped (edit config later)');
170
+ }
171
+
172
+ console.log('');
173
+ console.log('To disable per project, add to .claude/settings.local.json:');
174
+ console.log(' { "env": { "DISABLE_CLAUDE_NOTIFIER": "1" } }');
175
+ console.log('');
176
+ }
177
+
178
+ main().then(() => 0);
package/bin/uninstall.js CHANGED
@@ -1,53 +1,53 @@
1
- #!/usr/bin/env node
2
-
3
- import fs from 'fs';
4
- import os from 'os';
5
- import path from 'path';
6
-
7
- const home = os.homedir();
8
- const claudeDir = path.join(home, '.claude');
9
- const configPath = path.join(claudeDir, 'notifier.config.json');
10
- const settingsPath = path.join(claudeDir, 'settings.json');
11
- const statePath = path.join(claudeDir, '.notifier_state.json');
12
-
13
- const HOOK_COMMAND = 'claude-notifier';
14
-
15
- // Remove hooks from settings.json
16
- if (fs.existsSync(settingsPath)) {
17
- try {
18
- const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
19
-
20
- if (settings.hooks) {
21
- for (const event of Object.keys(settings.hooks)) {
22
- settings.hooks[event] = settings.hooks[event].filter((matcher) =>
23
- !matcher.hooks?.some((h) => h.command?.includes(HOOK_COMMAND)),
24
- );
25
-
26
- if (settings.hooks[event].length === 0) {
27
- delete settings.hooks[event];
28
- }
29
- }
30
-
31
- if (Object.keys(settings.hooks).length === 0) {
32
- delete settings.hooks;
33
- }
34
- }
35
-
36
- fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
37
- } catch {
38
- // ignore
39
- }
40
- }
41
-
42
- // Remove config and state files
43
- for (const file of [configPath, statePath]) {
44
- if (fs.existsSync(file)) {
45
- fs.unlinkSync(file);
46
- }
47
- }
48
-
49
- console.log('');
50
- console.log('Claude Notification Plugin uninstalled.');
51
- console.log('Hooks removed from settings.json');
52
- console.log('Config files deleted.');
53
- console.log('');
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'fs';
4
+ import os from 'os';
5
+ import path from 'path';
6
+
7
+ const home = os.homedir();
8
+ const claudeDir = path.join(home, '.claude');
9
+ const configPath = path.join(claudeDir, 'notifier.config.json');
10
+ const settingsPath = path.join(claudeDir, 'settings.json');
11
+ const statePath = path.join(claudeDir, '.notifier_state.json');
12
+
13
+ const HOOK_COMMAND = 'claude-notifier';
14
+
15
+ // Remove hooks from settings.json
16
+ if (fs.existsSync(settingsPath)) {
17
+ try {
18
+ const settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
19
+
20
+ if (settings.hooks) {
21
+ for (const event of Object.keys(settings.hooks)) {
22
+ settings.hooks[event] = settings.hooks[event].filter((matcher) =>
23
+ !matcher.hooks?.some((h) => h.command?.includes(HOOK_COMMAND)),
24
+ );
25
+
26
+ if (settings.hooks[event].length === 0) {
27
+ delete settings.hooks[event];
28
+ }
29
+ }
30
+
31
+ if (Object.keys(settings.hooks).length === 0) {
32
+ delete settings.hooks;
33
+ }
34
+ }
35
+
36
+ fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
37
+ } catch {
38
+ // ignore
39
+ }
40
+ }
41
+
42
+ // Remove config and state files
43
+ for (const file of [configPath, statePath]) {
44
+ if (fs.existsSync(file)) {
45
+ fs.unlinkSync(file);
46
+ }
47
+ }
48
+
49
+ console.log('');
50
+ console.log('Claude Notification Plugin uninstalled.');
51
+ console.log('Hooks removed from settings.json');
52
+ console.log('Config files deleted.');
53
+ console.log('');
@@ -1,252 +1,322 @@
1
- #!/usr/bin/env node
2
-
3
- import fs from 'fs';
4
- import os from 'os';
5
- import path from 'path';
6
- import process from 'process';
7
- import notifier from 'node-notifier';
8
- import player from 'play-sound';
9
- import say from 'say';
10
-
11
- const audio = player({});
12
-
13
- // ----------------------
14
- // CONFIG
15
- // ----------------------
16
-
17
- function loadConfig () {
18
- const configPath = path.join(os.homedir(), '.claude', 'notifier.config.json');
19
-
20
- const config = {
21
- telegram: { enabled: true, token: '', chatId: '' },
22
- windowsNotification: { enabled: true },
23
- sound: { enabled: true, file: 'C:/Windows/Media/notify.wav' },
24
- voice: { enabled: true },
25
- minSeconds: 15,
26
- };
27
-
28
- if (fs.existsSync(configPath)) {
29
- try {
30
- const raw = fs.readFileSync(configPath, 'utf-8');
31
- const user = JSON.parse(raw);
32
- if (user.telegram) {
33
- config.telegram = { ...config.telegram, ...user.telegram };
34
- }
35
- if (user.windowsNotification) {
36
- config.windowsNotification = { ...config.windowsNotification, ...user.windowsNotification };
37
- }
38
- if (user.sound) {
39
- config.sound = { ...config.sound, ...user.sound };
40
- }
41
- if (user.voice) {
42
- config.voice = { ...config.voice, ...user.voice };
43
- }
44
- if (typeof user.minSeconds === 'number') {
45
- config.minSeconds = user.minSeconds;
46
- }
47
- } catch {
48
- // ignore malformed config
49
- }
50
- }
51
-
52
- if (process.env.TELEGRAM_TOKEN) {
53
- config.telegram.token = process.env.TELEGRAM_TOKEN;
54
- }
55
- if (process.env.TELEGRAM_CHAT_ID) {
56
- config.telegram.chatId = process.env.TELEGRAM_CHAT_ID;
57
- }
58
-
59
- // Per-channel env overrides (0 = off, 1 = on)
60
- if (process.env.CLAUDE_NOTIFY_TELEGRAM !== undefined) {
61
- config.telegram.enabled = process.env.CLAUDE_NOTIFY_TELEGRAM === '1';
62
- }
63
- if (process.env.CLAUDE_NOTIFY_WINDOWS !== undefined) {
64
- config.windowsNotification.enabled = process.env.CLAUDE_NOTIFY_WINDOWS === '1';
65
- }
66
- if (process.env.CLAUDE_NOTIFY_SOUND !== undefined) {
67
- config.sound.enabled = process.env.CLAUDE_NOTIFY_SOUND === '1';
68
- }
69
- if (process.env.CLAUDE_NOTIFY_VOICE !== undefined) {
70
- config.voice.enabled = process.env.CLAUDE_NOTIFY_VOICE === '1';
71
- }
72
-
73
- return config;
74
- }
75
-
76
- // ----------------------
77
- // PROJECT-LEVEL DISABLE
78
- // ----------------------
79
-
80
- function isNotifierDisabled () {
81
- return process.env.DISABLE_CLAUDE_NOTIFIER === '1'
82
- || process.env.DISABLE_CLAUDE_NOTIFIER === 'true';
83
- }
84
-
85
- // ----------------------
86
- // STATE FILE
87
- // ----------------------
88
-
89
- const STATE_FILE = path.join(
90
- os.homedir(),
91
- '.claude',
92
- '.notifier_state.json',
93
- );
94
-
95
- function loadState () {
96
- if (fs.existsSync(STATE_FILE)) {
97
- try {
98
- return JSON.parse(fs.readFileSync(STATE_FILE, 'utf-8'));
99
- } catch {
100
- return {};
101
- }
102
- }
103
- return {};
104
- }
105
-
106
- function saveState (state) {
107
- const dir = path.dirname(STATE_FILE);
108
- fs.mkdirSync(dir, { recursive: true });
109
- fs.writeFileSync(STATE_FILE, JSON.stringify(state));
110
- }
111
-
112
- // ----------------------
113
- // TELEGRAM
114
- // ----------------------
115
-
116
- async function sendTelegram (config, text) {
117
- if (!config.telegram.enabled || !config.telegram.token || !config.telegram.chatId) {
118
- return;
119
- }
120
-
121
- const url =
122
- `https://api.telegram.org/bot${config.telegram.token}/sendMessage`;
123
-
124
- try {
125
- await fetch(url, {
126
- method: 'POST',
127
- headers: { 'Content-Type': 'application/json' },
128
- body: JSON.stringify({
129
- chat_id: config.telegram.chatId,
130
- text,
131
- }),
132
- });
133
- } catch {
134
- // silent fail
135
- }
136
- }
137
-
138
- // ----------------------
139
- // WINDOWS NOTIFICATION
140
- // ----------------------
141
-
142
- function sendWindowsNotification (config, message) {
143
- if (!config.windowsNotification.enabled) {
144
- return;
145
- }
146
- notifier.notify({
147
- title: 'Claude Code',
148
- message,
149
- sound: true,
150
- wait: false,
151
- });
152
- }
153
-
154
- // ----------------------
155
- // SOUND & VOICE
156
- // ----------------------
157
-
158
- function playSound (config) {
159
- if (!config.sound.enabled) {
160
- return;
161
- }
162
- try {
163
- audio.play(config.sound.file);
164
- } catch {
165
- // silent fail
166
- }
167
- }
168
-
169
- function speakResult (config, duration) {
170
- if (!config.voice.enabled) {
171
- return;
172
- }
173
- try {
174
- say.speak(`Claude finished coding in ${duration} seconds`);
175
- } catch {
176
- // silent fail
177
- }
178
- }
179
-
180
- // ----------------------
181
- // READ HOOK INPUT
182
- // ----------------------
183
-
184
- let input = '';
185
-
186
- process.stdin.on('data', (chunk) => {
187
- input += chunk;
188
- });
189
-
190
- process.stdin.on('end', async () => {
191
- const config = loadConfig();
192
-
193
- let event = {};
194
- try {
195
- event = JSON.parse(input);
196
- } catch {
197
- // ignore
198
- }
199
-
200
- const eventType = event.hook_event_name || 'unknown';
201
- const cwd = event.cwd || process.cwd();
202
- const project = path.basename(cwd);
203
-
204
- if (isNotifierDisabled()) {
205
- process.exit(0);
206
- }
207
-
208
- const state = loadState();
209
-
210
- // ----------------------
211
- // START TIMER
212
- // ----------------------
213
-
214
- if (eventType === 'UserPromptSubmit') {
215
- state.start = Date.now();
216
- saveState(state);
217
- process.exit(0);
218
- }
219
-
220
- // ----------------------
221
- // STOP / NOTIFICATION EVENT
222
- // ----------------------
223
-
224
- if (eventType !== 'Stop' && eventType !== 'Notification') {
225
- process.exit(0);
226
- }
227
-
228
- let duration = 0;
229
- if (state.start) {
230
- duration = Math.round((Date.now() - state.start) / 1000);
231
- }
232
-
233
- if (duration < config.minSeconds) {
234
- process.exit(0);
235
- }
236
-
237
- let status = 'success';
238
- if (event.error) {
239
- status = 'error';
240
- }
241
- if (eventType === 'Notification') {
242
- status = 'waiting';
243
- }
244
-
245
- const message =
246
- `Claude finished coding\n\nProject: ${project}\nDuration: ${duration}s\nStatus: ${status}`;
247
-
248
- await sendTelegram(config, `\u{1F916} ${message}`);
249
- sendWindowsNotification(config, message);
250
- playSound(config);
251
- speakResult(config, duration);
252
- });
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'fs';
4
+ import os from 'os';
5
+ import path from 'path';
6
+ import process from 'process';
7
+ import notifier from 'node-notifier';
8
+ import player from 'play-sound';
9
+ import say from 'say';
10
+
11
+ const audio = player({});
12
+
13
+ // ----------------------
14
+ // CONFIG
15
+ // ----------------------
16
+
17
+ function loadConfig () {
18
+ const configPath = path.join(os.homedir(), '.claude', 'notifier.config.json');
19
+
20
+ const config = {
21
+ telegram: {
22
+ enabled: true,
23
+ token: '',
24
+ chatId: '',
25
+ deleteAfterHours: 24,
26
+ },
27
+ windowsNotification: {
28
+ enabled: true,
29
+ },
30
+ sound: {
31
+ enabled: true,
32
+ file: 'C:/Windows/Media/notify.wav',
33
+ },
34
+ voice: {
35
+ enabled: true,
36
+ },
37
+ minSeconds: 15,
38
+ };
39
+
40
+ if (fs.existsSync(configPath)) {
41
+ try {
42
+ const raw = fs.readFileSync(configPath, 'utf-8');
43
+ const user = JSON.parse(raw);
44
+ if (user.telegram) {
45
+ config.telegram = { ...config.telegram, ...user.telegram };
46
+ }
47
+ if (user.windowsNotification) {
48
+ config.windowsNotification = { ...config.windowsNotification, ...user.windowsNotification };
49
+ }
50
+ if (user.sound) {
51
+ config.sound = { ...config.sound, ...user.sound };
52
+ }
53
+ if (user.voice) {
54
+ config.voice = { ...config.voice, ...user.voice };
55
+ }
56
+ if (typeof user.minSeconds === 'number') {
57
+ config.minSeconds = user.minSeconds;
58
+ }
59
+ } catch {
60
+ // ignore malformed config
61
+ }
62
+ }
63
+
64
+ if (process.env.TELEGRAM_TOKEN) {
65
+ config.telegram.token = process.env.TELEGRAM_TOKEN;
66
+ }
67
+ if (process.env.TELEGRAM_CHAT_ID) {
68
+ config.telegram.chatId = process.env.TELEGRAM_CHAT_ID;
69
+ }
70
+
71
+ // Per-channel env overrides (0 = off, 1 = on)
72
+ if (process.env.CLAUDE_NOTIFY_TELEGRAM !== undefined) {
73
+ config.telegram.enabled = process.env.CLAUDE_NOTIFY_TELEGRAM === '1';
74
+ }
75
+ if (process.env.CLAUDE_NOTIFY_WINDOWS !== undefined) {
76
+ config.windowsNotification.enabled = process.env.CLAUDE_NOTIFY_WINDOWS === '1';
77
+ }
78
+ if (process.env.CLAUDE_NOTIFY_SOUND !== undefined) {
79
+ config.sound.enabled = process.env.CLAUDE_NOTIFY_SOUND === '1';
80
+ }
81
+ if (process.env.CLAUDE_NOTIFY_VOICE !== undefined) {
82
+ config.voice.enabled = process.env.CLAUDE_NOTIFY_VOICE === '1';
83
+ }
84
+
85
+ return config;
86
+ }
87
+
88
+ // ----------------------
89
+ // PROJECT-LEVEL DISABLE
90
+ // ----------------------
91
+
92
+ function isNotifierDisabled () {
93
+ return process.env.DISABLE_CLAUDE_NOTIFIER === '1'
94
+ || process.env.DISABLE_CLAUDE_NOTIFIER === 'true';
95
+ }
96
+
97
+ // ----------------------
98
+ // STATE FILE
99
+ // ----------------------
100
+
101
+ const STATE_FILE = path.join(
102
+ os.homedir(),
103
+ '.claude',
104
+ '.notifier_state.json',
105
+ );
106
+
107
+ function loadState () {
108
+ if (fs.existsSync(STATE_FILE)) {
109
+ try {
110
+ return JSON.parse(fs.readFileSync(STATE_FILE, 'utf-8'));
111
+ } catch {
112
+ return {};
113
+ }
114
+ }
115
+ return {};
116
+ }
117
+
118
+ function saveState (state) {
119
+ const dir = path.dirname(STATE_FILE);
120
+ fs.mkdirSync(dir, { recursive: true });
121
+ fs.writeFileSync(STATE_FILE, JSON.stringify(state));
122
+ }
123
+
124
+ // ----------------------
125
+ // TELEGRAM
126
+ // ----------------------
127
+
128
+ async function sendTelegram (config, state) {
129
+ if (!config.telegram.enabled || !config.telegram.token || !config.telegram.chatId) {
130
+ return;
131
+ }
132
+
133
+ const baseUrl = `https://api.telegram.org/bot${config.telegram.token}`;
134
+
135
+ // Send new message and store its id
136
+ try {
137
+ const res = await fetch(`${baseUrl}/sendMessage`, {
138
+ method: 'POST',
139
+ headers: { 'Content-Type': 'application/json' },
140
+ body: JSON.stringify({
141
+ chat_id: config.telegram.chatId,
142
+ text: state._telegramText,
143
+ }),
144
+ });
145
+ const data = await res.json();
146
+ if (data.ok && data.result?.message_id) {
147
+ if (!state.sentMessages) {
148
+ state.sentMessages = [];
149
+ }
150
+ state.sentMessages.push({
151
+ id: data.result.message_id,
152
+ ts: Date.now(),
153
+ });
154
+ }
155
+ } catch {
156
+ // silent fail
157
+ }
158
+
159
+ // Delete old messages
160
+ const maxAge = (config.telegram.deleteAfterHours || 24) * 3600_000;
161
+ if (state.sentMessages?.length) {
162
+ const now = Date.now();
163
+ const keep = [];
164
+ for (const msg of state.sentMessages) {
165
+ if (now - msg.ts > maxAge) {
166
+ try {
167
+ await fetch(`${baseUrl}/deleteMessage`, {
168
+ method: 'POST',
169
+ headers: { 'Content-Type': 'application/json' },
170
+ body: JSON.stringify({
171
+ chat_id: config.telegram.chatId,
172
+ message_id: msg.id,
173
+ }),
174
+ });
175
+ } catch {
176
+ // silent fail
177
+ }
178
+ } else {
179
+ keep.push(msg);
180
+ }
181
+ }
182
+ state.sentMessages = keep;
183
+ }
184
+ }
185
+
186
+ // ----------------------
187
+ // WINDOWS NOTIFICATION
188
+ // ----------------------
189
+
190
+ function sendWindowsNotification (config, message) {
191
+ if (!config.windowsNotification.enabled) {
192
+ return;
193
+ }
194
+ notifier.notify({
195
+ title: 'Claude Code',
196
+ message,
197
+ sound: true,
198
+ wait: false,
199
+ });
200
+ }
201
+
202
+ // ----------------------
203
+ // SOUND & VOICE
204
+ // ----------------------
205
+
206
+ function playSound (config) {
207
+ if (!config.sound.enabled) {
208
+ return;
209
+ }
210
+ try {
211
+ audio.play(config.sound.file);
212
+ } catch {
213
+ // silent fail
214
+ }
215
+ }
216
+
217
+ const voicePhrases = {
218
+ en: (d) => `Claude finished coding in ${d} seconds`,
219
+ ru: (d) => `Клод завершил работу за ${d} секунд`,
220
+ de: (d) => `Claude hat die Arbeit in ${d} Sekunden abgeschlossen`,
221
+ fr: (d) => `Claude a termine en ${d} secondes`,
222
+ es: (d) => `Claude termino en ${d} segundos`,
223
+ pt: (d) => `Claude terminou em ${d} segundos`,
224
+ ja: (d) => `Claudeは${d}秒でコーディングを完了しました`,
225
+ ko: (d) => `Claude가 ${d}초 만에 코딩을 완료했습니다`,
226
+ };
227
+
228
+ function getVoicePhrase (duration) {
229
+ const locale = Intl.DateTimeFormat().resolvedOptions().locale || 'en';
230
+ const lang = locale.split('-')[0].toLowerCase();
231
+ const fn = voicePhrases[lang] || voicePhrases.en;
232
+ return fn(duration);
233
+ }
234
+
235
+ function speakResult (config, duration) {
236
+ if (!config.voice.enabled) {
237
+ return;
238
+ }
239
+ try {
240
+ say.speak(getVoicePhrase(duration));
241
+ } catch {
242
+ // silent fail
243
+ }
244
+ }
245
+
246
+ // ----------------------
247
+ // READ HOOK INPUT
248
+ // ----------------------
249
+
250
+ let input = '';
251
+
252
+ process.stdin.on('data', (chunk) => {
253
+ input += chunk;
254
+ });
255
+
256
+ process.stdin.on('end', async () => {
257
+ const config = loadConfig();
258
+
259
+ let event = {};
260
+ try {
261
+ event = JSON.parse(input);
262
+ } catch {
263
+ // ignore
264
+ }
265
+
266
+ const eventType = event.hook_event_name || 'unknown';
267
+ const cwd = event.cwd || process.cwd();
268
+ const project = path.basename(cwd);
269
+
270
+ if (isNotifierDisabled()) {
271
+ process.exit(0);
272
+ }
273
+
274
+ const state = loadState();
275
+
276
+ // ----------------------
277
+ // START TIMER
278
+ // ----------------------
279
+
280
+ if (eventType === 'UserPromptSubmit') {
281
+ state.start = Date.now();
282
+ saveState(state);
283
+ process.exit(0);
284
+ }
285
+
286
+ // ----------------------
287
+ // STOP / NOTIFICATION EVENT
288
+ // ----------------------
289
+
290
+ if (eventType !== 'Stop' && eventType !== 'Notification') {
291
+ process.exit(0);
292
+ }
293
+
294
+ let duration = 0;
295
+ if (state.start) {
296
+ duration = Math.round((Date.now() - state.start) / 1000);
297
+ }
298
+
299
+ if (duration < config.minSeconds) {
300
+ process.exit(0);
301
+ }
302
+
303
+ let status = 'success';
304
+ if (event.error) {
305
+ status = 'error';
306
+ }
307
+ if (eventType === 'Notification') {
308
+ status = 'waiting';
309
+ }
310
+
311
+ const message =
312
+ `Claude finished coding\n\nProject: ${project}\nDuration: ${duration}s\nStatus: ${status}`;
313
+
314
+ state._telegramText = `\u{1F916} ${message}`;
315
+ await sendTelegram(config, state);
316
+ delete state._telegramText;
317
+ saveState(state);
318
+
319
+ sendWindowsNotification(config, message);
320
+ playSound(config);
321
+ speakResult(config, duration);
322
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "claude-notification-plugin",
3
3
  "productName": "claude-notification-plugin",
4
- "version": "1.0.6",
4
+ "version": "1.0.13",
5
5
  "description": "Telegram and Windows notifications for Claude Code task completion",
6
6
  "type": "module",
7
7
  "engines": {
@@ -40,7 +40,7 @@
40
40
  },
41
41
  "homepage": "https://github.com/Bazilio-san/claude-notification-plugin#readme",
42
42
  "publishConfig": {
43
- "provenance": true
43
+ "access": "public"
44
44
  },
45
45
  "dependencies": {
46
46
  "node-notifier": "^10.0.1",