claude-notification-plugin 1.0.3 → 1.0.6

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,82 +1,113 @@
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
11
- - Skips short tasks (< 15s by default)
12
- - Per-project disable
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
- "token": "YOUR_BOT_TOKEN",
34
- "chatId": "YOUR_CHAT_ID"
35
- },
36
- "sound": {
37
- "enabled": true,
38
- "file": "C:/Windows/Media/notify.wav"
39
- },
40
- "voice": {
41
- "enabled": true
42
- },
43
- "minSeconds": 15
44
- }
45
- ```
46
-
47
- Environment variables `TELEGRAM_TOKEN` and `TELEGRAM_CHAT_ID` override config file values.
48
-
49
- ### Disable per project
50
-
51
- Add to `.claude/settings.local.json` in the project root:
52
-
53
- ```json
54
- {
55
- "env": {
56
- "DISABLE_CLAUDE_NOTIFIER": "1"
57
- }
58
- }
59
- ```
60
-
61
- ## Telegram Setup
62
-
63
- 1. Open Telegram, find **@BotFather**
64
- 2. Send `/newbot`, follow prompts, pick a name
65
- 3. Copy the bot token (format: `123456789:ABCdef...`)
66
- 4. Send any message to your new bot
67
- 5. Open `https://api.telegram.org/bot<YOUR_TOKEN>/getUpdates`
68
- 6. Find `"chat":{"id":123456789}` in the response that's your Chat ID
69
- 7. Run `claude-notify-install` and enter the token and chat ID
70
-
71
- Alternative for Chat ID: add **@userinfobot** to a chat and it will reply with the ID.
72
-
73
- ## Uninstall
74
-
75
- ```bash
76
- claude-notify-uninstall
77
- npm uninstall -g claude-notification-plugin
78
- ```
79
-
80
- ## License
81
-
82
- 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
+ },
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
package/bin/install.js CHANGED
@@ -1,165 +1,166 @@
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: { token, chatId },
116
- sound: { enabled: true, file: 'C:/Windows/Media/notify.wav' },
117
- voice: { enabled: true },
118
- minSeconds: 15,
119
- };
120
-
121
- fs.writeFileSync(configPath, JSON.stringify(config, null, 2));
122
-
123
- // Patch settings.json
124
- let settings = {};
125
-
126
- if (fs.existsSync(settingsPath)) {
127
- try {
128
- settings = JSON.parse(fs.readFileSync(settingsPath, 'utf-8'));
129
- } catch {
130
- settings = {};
131
- }
132
- }
133
-
134
- settings.hooks = settings.hooks || {};
135
-
136
- addHook(settings, 'UserPromptSubmit');
137
- addHook(settings, 'Stop');
138
- addHook(settings, 'Notification');
139
-
140
- fs.writeFileSync(settingsPath, JSON.stringify(settings, null, 2));
141
-
142
- // Output
143
- console.log('');
144
- console.log('Installed!');
145
- console.log('');
146
- console.log('Hooks registered:');
147
- console.log(' - UserPromptSubmit (start timer)');
148
- console.log(' - Stop (task finished)');
149
- console.log(' - Notification (waiting for input)');
150
- console.log('');
151
- console.log('Config: ' + configPath);
152
-
153
- if (token) {
154
- console.log('Telegram: configured');
155
- } else {
156
- console.log('Telegram: skipped (edit config later)');
157
- }
158
-
159
- console.log('');
160
- console.log('To disable per project, add to .claude/settings.local.json:');
161
- console.log(' { "env": { "DISABLE_CLAUDE_NOTIFIER": "1" } }');
162
- console.log('');
163
- }
164
-
165
- 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: { 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);
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,231 +1,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: { token: '', chatId: '' },
22
- sound: { enabled: true, file: 'C:/Windows/Media/notify.wav' },
23
- voice: { enabled: true },
24
- minSeconds: 15,
25
- };
26
-
27
- if (fs.existsSync(configPath)) {
28
- try {
29
- const raw = fs.readFileSync(configPath, 'utf-8');
30
- const user = JSON.parse(raw);
31
- if (user.telegram) {
32
- config.telegram = { ...config.telegram, ...user.telegram };
33
- }
34
- if (user.sound) {
35
- config.sound = { ...config.sound, ...user.sound };
36
- }
37
- if (user.voice) {
38
- config.voice = { ...config.voice, ...user.voice };
39
- }
40
- if (typeof user.minSeconds === 'number') {
41
- config.minSeconds = user.minSeconds;
42
- }
43
- } catch {
44
- // ignore malformed config
45
- }
46
- }
47
-
48
- if (process.env.TELEGRAM_TOKEN) {
49
- config.telegram.token = process.env.TELEGRAM_TOKEN;
50
- }
51
- if (process.env.TELEGRAM_CHAT_ID) {
52
- config.telegram.chatId = process.env.TELEGRAM_CHAT_ID;
53
- }
54
-
55
- return config;
56
- }
57
-
58
- // ----------------------
59
- // PROJECT-LEVEL DISABLE
60
- // ----------------------
61
-
62
- function isNotifierDisabled () {
63
- return process.env.DISABLE_CLAUDE_NOTIFIER === '1'
64
- || process.env.DISABLE_CLAUDE_NOTIFIER === 'true';
65
- }
66
-
67
- // ----------------------
68
- // STATE FILE
69
- // ----------------------
70
-
71
- const STATE_FILE = path.join(
72
- os.homedir(),
73
- '.claude',
74
- '.notifier_state.json',
75
- );
76
-
77
- function loadState () {
78
- if (fs.existsSync(STATE_FILE)) {
79
- try {
80
- return JSON.parse(fs.readFileSync(STATE_FILE, 'utf-8'));
81
- } catch {
82
- return {};
83
- }
84
- }
85
- return {};
86
- }
87
-
88
- function saveState (state) {
89
- const dir = path.dirname(STATE_FILE);
90
- fs.mkdirSync(dir, { recursive: true });
91
- fs.writeFileSync(STATE_FILE, JSON.stringify(state));
92
- }
93
-
94
- // ----------------------
95
- // TELEGRAM
96
- // ----------------------
97
-
98
- async function sendTelegram (config, text) {
99
- if (!config.telegram.token || !config.telegram.chatId) {
100
- return;
101
- }
102
-
103
- const url =
104
- `https://api.telegram.org/bot${config.telegram.token}/sendMessage`;
105
-
106
- try {
107
- await fetch(url, {
108
- method: 'POST',
109
- headers: { 'Content-Type': 'application/json' },
110
- body: JSON.stringify({
111
- chat_id: config.telegram.chatId,
112
- text,
113
- }),
114
- });
115
- } catch {
116
- // silent fail
117
- }
118
- }
119
-
120
- // ----------------------
121
- // WINDOWS NOTIFICATION
122
- // ----------------------
123
-
124
- function sendWindowsNotification (message) {
125
- notifier.notify({
126
- title: 'Claude Code',
127
- message,
128
- sound: true,
129
- wait: false,
130
- });
131
- }
132
-
133
- // ----------------------
134
- // SOUND & VOICE
135
- // ----------------------
136
-
137
- function playSound (config) {
138
- if (!config.sound.enabled) {
139
- return;
140
- }
141
- try {
142
- audio.play(config.sound.file);
143
- } catch {
144
- // silent fail
145
- }
146
- }
147
-
148
- function speakResult (config, duration) {
149
- if (!config.voice.enabled) {
150
- return;
151
- }
152
- try {
153
- say.speak(`Claude finished coding in ${duration} seconds`);
154
- } catch {
155
- // silent fail
156
- }
157
- }
158
-
159
- // ----------------------
160
- // READ HOOK INPUT
161
- // ----------------------
162
-
163
- let input = '';
164
-
165
- process.stdin.on('data', (chunk) => {
166
- input += chunk;
167
- });
168
-
169
- process.stdin.on('end', async () => {
170
- const config = loadConfig();
171
-
172
- let event = {};
173
- try {
174
- event = JSON.parse(input);
175
- } catch {
176
- // ignore
177
- }
178
-
179
- const eventType = event.hook_event_name || 'unknown';
180
- const cwd = event.cwd || process.cwd();
181
- const project = path.basename(cwd);
182
-
183
- if (isNotifierDisabled()) {
184
- process.exit(0);
185
- }
186
-
187
- const state = loadState();
188
-
189
- // ----------------------
190
- // START TIMER
191
- // ----------------------
192
-
193
- if (eventType === 'UserPromptSubmit') {
194
- state.start = Date.now();
195
- saveState(state);
196
- process.exit(0);
197
- }
198
-
199
- // ----------------------
200
- // STOP / NOTIFICATION EVENT
201
- // ----------------------
202
-
203
- if (eventType !== 'Stop' && eventType !== 'Notification') {
204
- process.exit(0);
205
- }
206
-
207
- let duration = 0;
208
- if (state.start) {
209
- duration = Math.round((Date.now() - state.start) / 1000);
210
- }
211
-
212
- if (duration < config.minSeconds) {
213
- process.exit(0);
214
- }
215
-
216
- let status = 'success';
217
- if (event.error) {
218
- status = 'error';
219
- }
220
- if (eventType === 'Notification') {
221
- status = 'waiting';
222
- }
223
-
224
- const message =
225
- `Claude finished coding\n\nProject: ${project}\nDuration: ${duration}s\nStatus: ${status}`;
226
-
227
- await sendTelegram(config, `\u{1F916} ${message}`);
228
- sendWindowsNotification(message);
229
- playSound(config);
230
- speakResult(config, duration);
231
- });
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
+ });
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.3",
4
+ "version": "1.0.6",
5
5
  "description": "Telegram and Windows notifications for Claude Code task completion",
6
6
  "type": "module",
7
7
  "engines": {
@@ -39,6 +39,9 @@
39
39
  "url": "git+https://github.com/Bazilio-san/claude-notification-plugin.git"
40
40
  },
41
41
  "homepage": "https://github.com/Bazilio-san/claude-notification-plugin#readme",
42
+ "publishConfig": {
43
+ "provenance": true
44
+ },
42
45
  "dependencies": {
43
46
  "node-notifier": "^10.0.1",
44
47
  "play-sound": "^1.1.6",