hookbell 0.1.0__py3-none-any.whl
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.
- hookbell/__init__.py +6 -0
- hookbell/claude_code/__init__.py +2 -0
- hookbell/claude_code/event.py +19 -0
- hookbell/claude_code/stdin.py +57 -0
- hookbell/claude_code/transcript.py +88 -0
- hookbell/cli.py +67 -0
- hookbell/notifiers/__init__.py +2 -0
- hookbell/notifiers/base.py +13 -0
- hookbell/notifiers/slack.py +61 -0
- hookbell/notify_style.py +26 -0
- hookbell/py.typed +0 -0
- hookbell-0.1.0.dist-info/METADATA +178 -0
- hookbell-0.1.0.dist-info/RECORD +17 -0
- hookbell-0.1.0.dist-info/WHEEL +5 -0
- hookbell-0.1.0.dist-info/entry_points.txt +2 -0
- hookbell-0.1.0.dist-info/licenses/LICENSE +21 -0
- hookbell-0.1.0.dist-info/top_level.txt +1 -0
hookbell/__init__.py
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Copyright (c) 2026 Yukihiko Shinoda
|
|
2
|
+
"""Composes a notification text from a Claude Code hook event."""
|
|
3
|
+
|
|
4
|
+
from hookbell.claude_code.stdin import ClaudeCodeStdin
|
|
5
|
+
from hookbell.claude_code.transcript import Transcript
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ClaudeCodeHookEvent:
|
|
9
|
+
"""A Claude Code hook event, combining its stdin payload and referenced transcript."""
|
|
10
|
+
|
|
11
|
+
def __init__(self, stdin: ClaudeCodeStdin) -> None:
|
|
12
|
+
self.stdin = stdin
|
|
13
|
+
self.transcript = Transcript(stdin.transcript_path)
|
|
14
|
+
|
|
15
|
+
@property
|
|
16
|
+
def text(self) -> str:
|
|
17
|
+
"""Return the notification text for this hook event."""
|
|
18
|
+
content = self.transcript.text_content or self.stdin.fallback_text
|
|
19
|
+
return f"{content}\n\nMessage type: {self.stdin.message}\n\n```{self.transcript.report()}```"
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
# Copyright (c) 2026 Yukihiko Shinoda
|
|
2
|
+
"""Parses Claude Code hook stdin payloads."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import json
|
|
7
|
+
from logging import getLogger
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class ClaudeCodeStdin:
|
|
13
|
+
"""A Claude Code hook stdin payload."""
|
|
14
|
+
|
|
15
|
+
TRANSCRIPT_PATH_KEY = "transcript_path"
|
|
16
|
+
|
|
17
|
+
def __init__(self, data: dict[str, Any]) -> None:
|
|
18
|
+
self.data = data
|
|
19
|
+
|
|
20
|
+
@classmethod
|
|
21
|
+
def parse(cls, raw_stdin: str) -> ClaudeCodeStdin | None:
|
|
22
|
+
"""Return a ClaudeCodeStdin when raw_stdin holds a Claude Code hook payload, else None."""
|
|
23
|
+
try:
|
|
24
|
+
data = json.loads(raw_stdin)
|
|
25
|
+
except json.JSONDecodeError:
|
|
26
|
+
return None
|
|
27
|
+
if not isinstance(data, dict) or cls.TRANSCRIPT_PATH_KEY not in data:
|
|
28
|
+
return None
|
|
29
|
+
getLogger(__name__).debug("raw stdin: %s", raw_stdin)
|
|
30
|
+
return cls(data)
|
|
31
|
+
|
|
32
|
+
@property
|
|
33
|
+
def message(self) -> str:
|
|
34
|
+
"""Return the hook's message, falling back to its event name."""
|
|
35
|
+
return str(self.data.get("message") or self.data.get("hook_event_name", "Notification"))
|
|
36
|
+
|
|
37
|
+
@property
|
|
38
|
+
def transcript_path(self) -> Path:
|
|
39
|
+
"""Return the transcript file path this hook event refers to."""
|
|
40
|
+
return Path(self.data[self.TRANSCRIPT_PATH_KEY])
|
|
41
|
+
|
|
42
|
+
@property
|
|
43
|
+
def fallback_text(self) -> str:
|
|
44
|
+
"""Return text to show when the transcript's last line has no readable text.
|
|
45
|
+
|
|
46
|
+
PermissionRequest payloads carry the pending tool call directly instead of assistant text, and Stop payloads
|
|
47
|
+
carry a ready-made last_assistant_message when the transcript's last line was something else (e.g. a sidechain
|
|
48
|
+
or summary entry).
|
|
49
|
+
"""
|
|
50
|
+
last_assistant_message = self.data.get("last_assistant_message")
|
|
51
|
+
if last_assistant_message:
|
|
52
|
+
return str(last_assistant_message)
|
|
53
|
+
tool_name = self.data.get("tool_name")
|
|
54
|
+
if tool_name:
|
|
55
|
+
tool_input = json.dumps(self.data.get("tool_input", {}), ensure_ascii=False)
|
|
56
|
+
return f"Waiting for permission: {tool_name}({tool_input})"
|
|
57
|
+
return self.message
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Copyright (c) 2026 Yukihiko Shinoda
|
|
2
|
+
"""Reads and sanitizes a Claude Code transcript's last entry."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
from typing import TYPE_CHECKING
|
|
9
|
+
from typing import Any
|
|
10
|
+
|
|
11
|
+
if TYPE_CHECKING:
|
|
12
|
+
import io
|
|
13
|
+
from pathlib import Path
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
class FileLastLineGetter:
|
|
17
|
+
"""Gets the last line of a file without reading the whole file into memory."""
|
|
18
|
+
|
|
19
|
+
def __init__(self, file_path: Path) -> None:
|
|
20
|
+
self.file_path = file_path
|
|
21
|
+
|
|
22
|
+
def get_last_line(self) -> str:
|
|
23
|
+
"""Return the last line of the file."""
|
|
24
|
+
with self.file_path.open("rb") as file_pointer:
|
|
25
|
+
return self._get_last_line(file_pointer)
|
|
26
|
+
|
|
27
|
+
@staticmethod
|
|
28
|
+
def _get_last_line(file_pointer: io.BufferedIOBase) -> str:
|
|
29
|
+
try:
|
|
30
|
+
FileLastLineGetter._seek_to_last_new_line(file_pointer)
|
|
31
|
+
except OSError:
|
|
32
|
+
# In case of a one line file
|
|
33
|
+
file_pointer.seek(0)
|
|
34
|
+
return file_pointer.readline().decode("utf-8").strip()
|
|
35
|
+
|
|
36
|
+
@staticmethod
|
|
37
|
+
def _seek_to_last_new_line(file_pointer: io.BufferedIOBase) -> None:
|
|
38
|
+
file_pointer.seek(-2, os.SEEK_END)
|
|
39
|
+
while file_pointer.read(1) != b"\n":
|
|
40
|
+
file_pointer.seek(-2, os.SEEK_CUR)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class Transcript:
|
|
44
|
+
"""A Claude Code transcript.
|
|
45
|
+
|
|
46
|
+
The transcript's last line is not always a plain assistant text message: it may be a tool call, a sub-
|
|
47
|
+
agent/sidechain entry, or a compaction summary entry, each with a different shape. Every accessor here must
|
|
48
|
+
tolerate keys being absent rather than assume the full schema.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
UNREADABLE_KEYS = ("parentUuid", "isSidechain", "sessionId", "version", "requestId", "uuid", "timestamp")
|
|
52
|
+
|
|
53
|
+
def __init__(self, path: Path) -> None:
|
|
54
|
+
transcript_json_string = FileLastLineGetter(path).get_last_line()
|
|
55
|
+
self.data: Any = json.loads(transcript_json_string)
|
|
56
|
+
|
|
57
|
+
def report(self) -> str:
|
|
58
|
+
"""Return the last transcript entry as pretty-printed, sanitized JSON."""
|
|
59
|
+
return json.dumps(self._remove_unreadable_keys(), indent=2, ensure_ascii=False)
|
|
60
|
+
|
|
61
|
+
def _remove_unreadable_keys(self) -> dict[str, Any]:
|
|
62
|
+
if not isinstance(self.data, dict):
|
|
63
|
+
return {"raw": self.data}
|
|
64
|
+
data = self.data.copy()
|
|
65
|
+
for key in self.UNREADABLE_KEYS:
|
|
66
|
+
data.pop(key, None)
|
|
67
|
+
message = data.get("message")
|
|
68
|
+
if isinstance(message, dict):
|
|
69
|
+
self._remove_unreadable_message_keys(message)
|
|
70
|
+
return data
|
|
71
|
+
|
|
72
|
+
@staticmethod
|
|
73
|
+
def _remove_unreadable_message_keys(message: dict[str, Any]) -> None:
|
|
74
|
+
message.pop("id", None)
|
|
75
|
+
for message_content in message.get("content") or []:
|
|
76
|
+
if isinstance(message_content, dict):
|
|
77
|
+
message_content.pop("id", None)
|
|
78
|
+
|
|
79
|
+
@property
|
|
80
|
+
def text_content(self) -> str:
|
|
81
|
+
"""Return the concatenated assistant text blocks of the last transcript entry."""
|
|
82
|
+
if not isinstance(self.data, dict):
|
|
83
|
+
return ""
|
|
84
|
+
contents = self.data.get("message", {}).get("content") or []
|
|
85
|
+
if not isinstance(contents, list):
|
|
86
|
+
return ""
|
|
87
|
+
texts = [item["text"] for item in contents if isinstance(item, dict) and item.get("type") == "text"]
|
|
88
|
+
return "\n".join(texts)
|
hookbell/cli.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
# Copyright (c) 2026 Yukihiko Shinoda
|
|
2
|
+
"""Console script for hookbell."""
|
|
3
|
+
|
|
4
|
+
import sys
|
|
5
|
+
from logging import DEBUG
|
|
6
|
+
from logging import basicConfig
|
|
7
|
+
from logging import getLogger
|
|
8
|
+
from pathlib import Path
|
|
9
|
+
|
|
10
|
+
import click
|
|
11
|
+
|
|
12
|
+
from hookbell.claude_code.event import ClaudeCodeHookEvent
|
|
13
|
+
from hookbell.claude_code.stdin import ClaudeCodeStdin
|
|
14
|
+
from hookbell.notifiers.slack import SlackNotifier
|
|
15
|
+
from hookbell.notify_style import PlainTextNotification
|
|
16
|
+
|
|
17
|
+
basicConfig(filename=Path("slack.log"), level=DEBUG)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
@click.command()
|
|
21
|
+
def main() -> int:
|
|
22
|
+
"""Notify Slack, either as a Claude Code hook or from any piped input.
|
|
23
|
+
|
|
24
|
+
Reads stdin (unless it is a TTY) and decides which mode applies: a Claude Code hook payload (JSON carrying
|
|
25
|
+
"transcript_path") is reported through its referenced transcript; anything else is posted as free-form text.
|
|
26
|
+
"""
|
|
27
|
+
raw_stdin = "" if sys.stdin.isatty() else sys.stdin.read()
|
|
28
|
+
claude_code_stdin = ClaudeCodeStdin.parse(raw_stdin) if raw_stdin else None
|
|
29
|
+
if claude_code_stdin is not None:
|
|
30
|
+
_notify_claude_code_hook(claude_code_stdin)
|
|
31
|
+
else:
|
|
32
|
+
_notify_plain_text(raw_stdin)
|
|
33
|
+
return 0
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def _notify_claude_code_hook(claude_code_stdin: ClaudeCodeStdin) -> None:
|
|
37
|
+
# Reason: This runs as a Claude Code hook, where a failed notification is best-effort side-
|
|
38
|
+
# channel noise rather than something that should surface as this hook's own failure. Logging
|
|
39
|
+
# and swallowing keeps a transient issue (a malformed transcript line, the network being
|
|
40
|
+
# briefly down, an unreachable webhook) from producing hook-failure feedback for a non-critical
|
|
41
|
+
# path. The failure surface spans stdlib json, pathlib and urllib plus future code, so
|
|
42
|
+
# narrowing to specific exception types would leave gaps:
|
|
43
|
+
# - Pylint broad-exception-caught (W0718): no narrower alternative fits an evolving surface
|
|
44
|
+
# https://pylint.readthedocs.io/en/latest/user_guide/messages/warning/broad-exception-caught.html
|
|
45
|
+
try:
|
|
46
|
+
SlackNotifier.from_environment().notify(ClaudeCodeHookEvent(claude_code_stdin).text)
|
|
47
|
+
except Exception: # pylint: disable=broad-exception-caught
|
|
48
|
+
getLogger(__name__).exception("Failed to notify Claude Code hook event")
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _notify_plain_text(raw_stdin: str) -> None:
|
|
52
|
+
# Reason: same broad failure surface as _notify_claude_code_hook above, but this branch is a
|
|
53
|
+
# direct, interactive invocation, so the failure is surfaced to the caller by re-raising as
|
|
54
|
+
# ClickException instead of only logged. Click's standalone mode ignores this
|
|
55
|
+
# command callback's own return value for the process exit code (only a raised exception, or an
|
|
56
|
+
# explicit ctx.exit(), controls it), and ClickException is the one exception type Click always
|
|
57
|
+
# turns into a clean "Error: ..." message on stderr plus a guaranteed exit code of exactly 1:
|
|
58
|
+
# - Pylint broad-exception-caught (W0718): no narrower alternative fits an evolving surface
|
|
59
|
+
# https://pylint.readthedocs.io/en/latest/user_guide/messages/warning/broad-exception-caught.html
|
|
60
|
+
try:
|
|
61
|
+
SlackNotifier.from_environment().notify(PlainTextNotification(raw_stdin).text)
|
|
62
|
+
except Exception as error: # pylint: disable=broad-exception-caught
|
|
63
|
+
raise click.ClickException(str(error)) from error
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
if __name__ == "__main__":
|
|
67
|
+
sys.exit(main()) # pragma: no cover
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Copyright (c) 2026 Yukihiko Shinoda
|
|
2
|
+
"""Notifier interface shared by every notification backend."""
|
|
3
|
+
|
|
4
|
+
from abc import ABC
|
|
5
|
+
from abc import abstractmethod
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class Notifier(ABC):
|
|
9
|
+
"""A destination hookbell can send a notification text to."""
|
|
10
|
+
|
|
11
|
+
@abstractmethod
|
|
12
|
+
def notify(self, text: str) -> None:
|
|
13
|
+
"""Send text as a notification."""
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
# Copyright (c) 2026 Yukihiko Shinoda
|
|
2
|
+
"""Slack notification backend."""
|
|
3
|
+
|
|
4
|
+
from __future__ import annotations
|
|
5
|
+
|
|
6
|
+
import json
|
|
7
|
+
import os
|
|
8
|
+
import ssl
|
|
9
|
+
from logging import getLogger
|
|
10
|
+
from pathlib import Path
|
|
11
|
+
from typing import ClassVar
|
|
12
|
+
from urllib import request
|
|
13
|
+
|
|
14
|
+
import certifi
|
|
15
|
+
|
|
16
|
+
from hookbell.notifiers.base import Notifier
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class SlackNotifier(Notifier):
|
|
20
|
+
"""Posts a notification to Slack via an incoming webhook."""
|
|
21
|
+
|
|
22
|
+
HEADERS: ClassVar[dict[str, str]] = {"Content-Type": "application/json"}
|
|
23
|
+
WEBHOOK_URL_SECRET_PATH = Path("/run/secrets/slack_webhook_url")
|
|
24
|
+
|
|
25
|
+
def __init__(self, webhook_url: str) -> None:
|
|
26
|
+
self.webhook_url = webhook_url
|
|
27
|
+
self.logger = getLogger(__name__)
|
|
28
|
+
|
|
29
|
+
@classmethod
|
|
30
|
+
def from_environment(cls) -> SlackNotifier:
|
|
31
|
+
"""Build a SlackNotifier from the Docker secret, falling back to the environment variable."""
|
|
32
|
+
if cls.WEBHOOK_URL_SECRET_PATH.exists():
|
|
33
|
+
return cls(webhook_url=cls.WEBHOOK_URL_SECRET_PATH.read_text(encoding="utf-8").strip())
|
|
34
|
+
return cls(webhook_url=os.environ["SLACK_WEBHOOK_URL"])
|
|
35
|
+
|
|
36
|
+
def notify(self, text: str) -> None:
|
|
37
|
+
"""Post text to Slack as a single section block."""
|
|
38
|
+
if not self.webhook_url.startswith("https://"):
|
|
39
|
+
message = f"Slack webhook URL must use https://, got: {self.webhook_url!r}"
|
|
40
|
+
raise ValueError(message)
|
|
41
|
+
data = {"blocks": [{"type": "section", "text": {"type": "mrkdwn", "text": text}}]}
|
|
42
|
+
# Reason: self.webhook_url is only ever populated by from_environment() above, from an
|
|
43
|
+
# operator-configured Docker secret file or the SLACK_WEBHOOK_URL environment variable --
|
|
44
|
+
# never from untrusted external input -- and the https:// scheme check right above rules
|
|
45
|
+
# out the file:/custom-scheme risk this rule targets. Ruff still flags the call even with
|
|
46
|
+
# that check in place, since it does no control-flow analysis:
|
|
47
|
+
# - Ruff Rule S310: suspicious-url-open-usage
|
|
48
|
+
# https://docs.astral.sh/ruff/rules/suspicious-url-open-usage/
|
|
49
|
+
# - Bandit B310: urllib urlopen
|
|
50
|
+
# https://bandit.readthedocs.io/en/1.9.4/blacklists/blacklist_calls.html#b310-urllib-urlopen
|
|
51
|
+
# - Issue: Avoid raising S310 if user explicitly checks for URL scheme
|
|
52
|
+
# https://github.com/astral-sh/ruff/issues/7918
|
|
53
|
+
req = request.Request( # noqa: S310
|
|
54
|
+
self.webhook_url,
|
|
55
|
+
data=json.dumps(data).encode("utf-8"),
|
|
56
|
+
headers=self.HEADERS,
|
|
57
|
+
)
|
|
58
|
+
ssl_context = ssl.create_default_context(cafile=certifi.where())
|
|
59
|
+
with request.urlopen(req, context=ssl_context) as response: # noqa: S310 # nosec B310
|
|
60
|
+
response_data = response.read().decode("utf-8")
|
|
61
|
+
self.logger.debug("response_data: %s", response_data)
|
hookbell/notify_style.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
# Copyright (c) 2026 Yukihiko Shinoda
|
|
2
|
+
"""Composes a plain-text notification from captured stdin.
|
|
3
|
+
|
|
4
|
+
A bare invocation notifies "Finished!", and piped stdin gets wrapped into a code block beneath it, truncated to Slack's
|
|
5
|
+
message character limit.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class PlainTextNotification:
|
|
10
|
+
"""A plain-text notification built from optional piped stdin."""
|
|
11
|
+
|
|
12
|
+
DEFAULT_TEXT = "Finished!"
|
|
13
|
+
# Following the character length limit on Slack messages:
|
|
14
|
+
# https://api.slack.com/changelog/2018-04-truncating-really-long-messages
|
|
15
|
+
STDIN_CHARACTER_LIMIT = 39900
|
|
16
|
+
|
|
17
|
+
def __init__(self, captured_stdin: str) -> None:
|
|
18
|
+
self.captured_stdin = captured_stdin
|
|
19
|
+
|
|
20
|
+
@property
|
|
21
|
+
def text(self) -> str:
|
|
22
|
+
"""Return the notification text."""
|
|
23
|
+
if not self.captured_stdin:
|
|
24
|
+
return self.DEFAULT_TEXT
|
|
25
|
+
truncated = self.captured_stdin[-self.STDIN_CHARACTER_LIMIT :]
|
|
26
|
+
return f"{self.DEFAULT_TEXT}\n```\n{truncated}\n```"
|
hookbell/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hookbell
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Notifies Slack, as a Claude Code hook or as a notify-compatible CLI.
|
|
5
|
+
Author-email: Yukihiko Shinoda <yuk.hik.future@gmail.com>
|
|
6
|
+
Maintainer-email: Yukihiko Shinoda <yuk.hik.future@gmail.com>
|
|
7
|
+
License: MIT License
|
|
8
|
+
|
|
9
|
+
Copyright (c) 2026 Yukihiko Shinoda
|
|
10
|
+
|
|
11
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
12
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
13
|
+
in the Software without restriction, including without limitation the rights
|
|
14
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
15
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
16
|
+
furnished to do so, subject to the following conditions:
|
|
17
|
+
|
|
18
|
+
The above copyright notice and this permission notice shall be included in all
|
|
19
|
+
copies or substantial portions of the Software.
|
|
20
|
+
|
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
22
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
23
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
24
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
25
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
26
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
|
+
SOFTWARE.
|
|
28
|
+
|
|
29
|
+
Project-URL: homepage, https://github.com/yukihiko-shinoda/hookbell
|
|
30
|
+
Project-URL: repository, https://github.com/yukihiko-shinoda/hookbell
|
|
31
|
+
Keywords: hookbell
|
|
32
|
+
Classifier: Development Status :: 4 - Beta
|
|
33
|
+
Classifier: Environment :: Console
|
|
34
|
+
Classifier: Intended Audience :: Developers
|
|
35
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
36
|
+
Classifier: Natural Language :: English
|
|
37
|
+
Classifier: Operating System :: OS Independent
|
|
38
|
+
Classifier: Topic :: Communications :: Chat
|
|
39
|
+
Classifier: Programming Language :: Python
|
|
40
|
+
Classifier: Programming Language :: Python :: 3
|
|
41
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
42
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
43
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
44
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
45
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
46
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
47
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
48
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
49
|
+
Classifier: Typing :: Typed
|
|
50
|
+
Requires-Python: >=3.7
|
|
51
|
+
Description-Content-Type: text/markdown
|
|
52
|
+
License-File: LICENSE
|
|
53
|
+
Requires-Dist: certifi>=2026.7.22
|
|
54
|
+
Requires-Dist: click>=7.0
|
|
55
|
+
Dynamic: license-file
|
|
56
|
+
|
|
57
|
+
# Hookbell
|
|
58
|
+
|
|
59
|
+
[](https://github.com/yukihiko-shinoda/hookbell/actions?query=workflow%3ATest)
|
|
60
|
+
[](https://github.com/yukihiko-shinoda/hookbell/actions?query=workflow%3ACodeQL)
|
|
61
|
+
[](https://qlty.sh/gh/yukihiko-shinoda/projects/hookbell)
|
|
62
|
+
[](https://qlty.sh/gh/yukihiko-shinoda/projects/hookbell)
|
|
63
|
+
[](https://github.com/yukihiko-shinoda/hookbell/security/dependabot)
|
|
64
|
+
[](https://pypi.org/project/hookbell/)
|
|
65
|
+
[](https://pypi.org/project/hookbell/)
|
|
66
|
+
[](https://x.com/intent/post?text=Hookbell&url=https%3A%2F%2Fpypi.org%2Fproject%2Fhookbell%2F&hashtags=python)
|
|
67
|
+
|
|
68
|
+
Notifies Slack — as a Claude Code hook, or as a general "notify me when this finishes" command for
|
|
69
|
+
any piped output.
|
|
70
|
+
|
|
71
|
+
## Advantage
|
|
72
|
+
|
|
73
|
+
A Claude Code hook script that only understands its own hook JSON payload
|
|
74
|
+
(`transcript_path`, `hook_event_name`, ...) can't double as a general-purpose notification command
|
|
75
|
+
for anything else you run — and a general-purpose command built without Claude Code in mind knows
|
|
76
|
+
nothing about its transcripts, so it can't report what the assistant actually said or which
|
|
77
|
+
permission it's waiting on. Maintaining one script per use case means duplicating the Slack-posting
|
|
78
|
+
logic each time.
|
|
79
|
+
|
|
80
|
+
Hookbell covers both with a single command: it inspects stdin and automatically picks the right
|
|
81
|
+
behavior. A Claude Code hook payload gets reported through its referenced transcript; anything else
|
|
82
|
+
is treated as free-form piped text and posted as-is.
|
|
83
|
+
|
|
84
|
+
## Quickstart
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
uv tool install hookbell
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Set the webhook URL from a Slack [Incoming Webhook](https://api.slack.com/messaging/webhooks):
|
|
91
|
+
|
|
92
|
+
```bash
|
|
93
|
+
export SLACK_WEBHOOK_URL="https://hooks.slack.com/services/T000/B000/XXXX"
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Pipe any text into hookbell to post it to Slack:
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
echo 'Hello world' | uvx hookbell
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
That posts this single Slack message:
|
|
103
|
+
|
|
104
|
+
````text
|
|
105
|
+
Finished!
|
|
106
|
+
```
|
|
107
|
+
Hello world
|
|
108
|
+
```
|
|
109
|
+
````
|
|
110
|
+
|
|
111
|
+
Since any piped input gets wrapped the same way, piping a long-running command's own output into
|
|
112
|
+
hookbell delivers that output to Slack the moment the command is done, without having to watch the
|
|
113
|
+
terminal for it — redirecting stderr into stdout matters here, since build tools like
|
|
114
|
+
`docker compose build` write their progress there:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
docker compose build 2>&1 | uvx hookbell
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
When the command's output isn't worth forwarding and only knowing it ended matters, chaining with
|
|
121
|
+
`;` instead leaves hookbell's stdin empty, so it just posts `Finished!` on its own:
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
docker compose build; uvx hookbell
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
<!-- markdownlint-disable no-trailing-punctuation -->
|
|
128
|
+
## How do I...
|
|
129
|
+
<!-- markdownlint-enable no-trailing-punctuation -->
|
|
130
|
+
|
|
131
|
+
### How do I use hookbell as a Claude Code hook?
|
|
132
|
+
|
|
133
|
+
Point Claude Code's `Notification`, `PermissionRequest`, and `Stop` hooks at hookbell in
|
|
134
|
+
`settings.json`:
|
|
135
|
+
|
|
136
|
+
```json
|
|
137
|
+
{
|
|
138
|
+
"hooks": {
|
|
139
|
+
"Stop": [
|
|
140
|
+
{
|
|
141
|
+
"hooks": [{ "type": "command", "command": "uvx hookbell" }]
|
|
142
|
+
}
|
|
143
|
+
]
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
Hookbell recognizes a Claude Code hook payload by its `transcript_path` field and posts a message
|
|
149
|
+
built from that transcript: the assistant's own last message when there is one, or a description of
|
|
150
|
+
the pending permission request otherwise. A failed notification here is logged (see `slack.log`)
|
|
151
|
+
rather than raised, so a flaky network never turns into hook-failure noise.
|
|
152
|
+
|
|
153
|
+
### How do I use hookbell in a Docker container?
|
|
154
|
+
|
|
155
|
+
Hookbell checks `/run/secrets/slack_webhook_url` before falling back to `SLACK_WEBHOOK_URL`, so a
|
|
156
|
+
[Docker secret] keeps the webhook URL out of the container's environment and image layers entirely.
|
|
157
|
+
With Compose, write the URL to a local file Compose reads at build/run time, and mount it as a
|
|
158
|
+
secret named `slack_webhook_url` so Docker places it at that exact path:
|
|
159
|
+
|
|
160
|
+
```yaml
|
|
161
|
+
services:
|
|
162
|
+
app:
|
|
163
|
+
secrets:
|
|
164
|
+
- slack_webhook_url
|
|
165
|
+
|
|
166
|
+
secrets:
|
|
167
|
+
slack_webhook_url:
|
|
168
|
+
file: ./slack_webhook_url.txt
|
|
169
|
+
```
|
|
170
|
+
|
|
171
|
+
[Docker secret]: https://docs.docker.com/compose/how-tos/use-secrets/
|
|
172
|
+
|
|
173
|
+
## Credits
|
|
174
|
+
|
|
175
|
+
This package was created with [Cookiecutter] and the [yukihiko-shinoda/cookiecutter-pypackage] project template.
|
|
176
|
+
|
|
177
|
+
[Cookiecutter]: https://github.com/audreyr/cookiecutter
|
|
178
|
+
[yukihiko-shinoda/cookiecutter-pypackage]: https://github.com/audreyr/cookiecutter-pypackage
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
hookbell/__init__.py,sha256=tOSJtsVldBmhyCqV4cl94I9tjOpSq79nylKqaAVKAFc,174
|
|
2
|
+
hookbell/cli.py,sha256=D30ufAgXDzGgbcLw0ackYUWpOfwx_xuxX4v9IDjMdgg,3310
|
|
3
|
+
hookbell/notify_style.py,sha256=Vh9gZFajtdr1AUgXuFm1YnVRYlwwwG5Sh1Je46t4OdA,943
|
|
4
|
+
hookbell/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
hookbell/claude_code/__init__.py,sha256=7r_mOOE7X98SvdJmEUhG_58yoIul4aoJM3dDFO6HeBA,79
|
|
6
|
+
hookbell/claude_code/event.py,sha256=pyo8uzyLY06giZ-SBa9NiSmN3WkyVUawCPzbMSrGk9U,762
|
|
7
|
+
hookbell/claude_code/stdin.py,sha256=AUUuuHdWNRPHXg8a5b-ZUi-uM1SbETBxjtoVzbH2E9g,2112
|
|
8
|
+
hookbell/claude_code/transcript.py,sha256=NoSt53xFbZCAbuJ3BuRnuj57BwhkuG3tcVU7od1p-dw,3224
|
|
9
|
+
hookbell/notifiers/__init__.py,sha256=c1nk2qGKtvx64f3XlURdDLDK6egnXU4toRU402u4DQI,67
|
|
10
|
+
hookbell/notifiers/base.py,sha256=Y_ka9p_ACPrFjO_NJA7g9e3C8bB1-nWLB_0PSQ2NgyI,347
|
|
11
|
+
hookbell/notifiers/slack.py,sha256=Q2JSxSo6-K7zV-ZBO-uC0zCZ0UqEQ_7NYFEnQILGKEQ,2778
|
|
12
|
+
hookbell-0.1.0.dist-info/licenses/LICENSE,sha256=wR3OZFWiZhZS_5KnHg9cOJyRZaeaa72r2g0727YlfQI,1073
|
|
13
|
+
hookbell-0.1.0.dist-info/METADATA,sha256=DIAe_QOutB_Q_flS7Bbv6QZsM35uzsmGE0XpQsln7NU,7472
|
|
14
|
+
hookbell-0.1.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
15
|
+
hookbell-0.1.0.dist-info/entry_points.txt,sha256=UiHEavoJquKk3SdQVO8ZSqEmsebAGq1CULy80PlDQ1s,47
|
|
16
|
+
hookbell-0.1.0.dist-info/top_level.txt,sha256=K28WvqQwaUVmXOewxTACFaXmTLZ8Gp_AGYk5bMsUKWM,9
|
|
17
|
+
hookbell-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Yukihiko Shinoda
|
|
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.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hookbell
|