[BUG] Hook failed to pass input,
Resolved 💬 4 comments Opened Jan 17, 2026 by wenzhuo4657 Closed Feb 27, 2026
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
I use Notification hook completes the notification function, however when I use the sh script as an entry to pass the hook input in, it never succeeds, I tried the pipeline, stdin, script parameters, they all read as empty, even though I read them correctly in the sh script
What Should Happen?
Correct reading
Error Messages/Logs
2026-01-17T08:52:15.896Z [DEBUG] Notification:permission_prompt [$CLAUDE_PROJECT_DIR/.claude/hooks/notify.sh] completed with status 1
2026-01-17T08:52:15.896Z [DEBUG] Hook output does not start with {, treating as plain text
Steps to Reproduce
#!/bin/bash
set -e
# 从 stdin 一次性读取所有输入,并存入变量
#payload=$(cat)
# 切换到 hooks 目录
cd "$CLAUDE_PROJECT_DIR/.claude/hooks"
#echo "$payload" >> console.log
# 将读取的内容重新作为 参数 传给 notify.ts
cat | npx tsx notify.ts >> notify.log 2>&1
import TelegramBot from 'node-telegram-bot-api';
import { HttpsProxyAgent } from 'https-proxy-agent';
import { readFileSync } from 'fs';
const token = 'xxxxx';
const agent = new HttpsProxyAgent('http://127.0.0.1:10808');
interface HookInput {
session_id: string;
transcript_path: string;
cwd: string;
message: string;
hook_event_name: string;
notification_type: string;
}
const bot = new TelegramBot(token, {
polling: false,
request: {
agent,
},
});
async function readStdin(): Promise<string> {
return new Promise((resolve, reject) => {
let data = '';
process.stdin
.setEncoding('utf8')
.on('data', (chunk) => {
data += chunk;
})
.on('end', () => {
resolve(data);
})
.on('error', (err) => {
reject(err);
});
// 防止卡住
setTimeout(() => {
reject(new Error('Stdin read timeout'));
}, 5000);
});
}
async function main() {
try {
// 👇 使用异步安全读取
const input = await readStdin();
console.error('📥 Raw stdin:', JSON.stringify(input)); // 调试用
if (!input.trim()) {
throw new Error('No input received via stdin');
}
let data: HookInput;
try {
data = JSON.parse(input);
} catch (err) {
throw new Error(`Failed to parse JSON: ${err instanceof Error ? err.message : String(err)}\nReceived: ${input}`);
}
const message = `🔔 Claude
${data.hook_event_name}
${data.message}
${data.cwd}
🔄 Session ID:
${data.session_id}
`;
await bot.sendMessage(6550266873, message);
console.log('✅ success');
process.exit(0);
} catch (err: any) {
console.error('❌ error:', err?.message || err);
process.exit(1);
}
}
main();
Claude Model
Other
Is this a regression?
I don't know
Last Working Version
_No response_
Claude Code Version
2.1.11 (Claude Code)
Platform
Other
Operating System
Windows
Terminal/Shell
WSL (Windows Subsystem for Linux)
Additional Information
_No response_
This issue has 4 comments on GitHub. Read the full discussion on GitHub ↗