claude-notification-plugin 1.0.3 → 1.0.4

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,82 @@
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
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
package/bin/install.js CHANGED
@@ -1,165 +1,165 @@
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: { 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);
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,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: { 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: { 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
+ });
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.4",
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",