claude-watchdog 0.1.0__tar.gz
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.
- claude_watchdog-0.1.0/LICENSE +21 -0
- claude_watchdog-0.1.0/PKG-INFO +124 -0
- claude_watchdog-0.1.0/README.md +111 -0
- claude_watchdog-0.1.0/claude_watchdog/cli.py +87 -0
- claude_watchdog-0.1.0/claude_watchdog/logger.py +53 -0
- claude_watchdog-0.1.0/claude_watchdog/notify.py +25 -0
- claude_watchdog-0.1.0/claude_watchdog/rules.py +47 -0
- claude_watchdog-0.1.0/claude_watchdog/watcher.py +89 -0
- claude_watchdog-0.1.0/claude_watchdog.egg-info/PKG-INFO +124 -0
- claude_watchdog-0.1.0/claude_watchdog.egg-info/SOURCES.txt +13 -0
- claude_watchdog-0.1.0/claude_watchdog.egg-info/dependency_links.txt +1 -0
- claude_watchdog-0.1.0/claude_watchdog.egg-info/entry_points.txt +2 -0
- claude_watchdog-0.1.0/claude_watchdog.egg-info/top_level.txt +1 -0
- claude_watchdog-0.1.0/pyproject.toml +23 -0
- claude_watchdog-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 LinQuan
|
|
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,124 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: claude-watchdog
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Claude Code tmux watchdog — auto-unblock permission dialogs
|
|
5
|
+
Author: LinQuan
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: homepage, https://github.com/mlinquan/claude-watchdog
|
|
8
|
+
Project-URL: repository, https://github.com/mlinquan/claude-watchdog
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# claude-watchdog
|
|
15
|
+
|
|
16
|
+
[English](./README.md) | [中文](./README.zh.md)
|
|
17
|
+
|
|
18
|
+
Claude Code tmux watchdog — auto-unblock permission dialogs so you
|
|
19
|
+
don't have to stare at a blocked session.
|
|
20
|
+
|
|
21
|
+
Only logs hits (blockage detected and cleared), silent otherwise.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install claude-watchdog
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# One-shot check (runs once, exits)
|
|
33
|
+
claude-watchdog --session claude-tl
|
|
34
|
+
|
|
35
|
+
# Monitor continuously
|
|
36
|
+
claude-watchdog --session claude-tl --daemon
|
|
37
|
+
|
|
38
|
+
# Monitor every claude-* session
|
|
39
|
+
claude-watchdog --all --daemon
|
|
40
|
+
|
|
41
|
+
# Alert only — log + notify, don't auto-approve
|
|
42
|
+
claude-watchdog --session claude-tl --daemon --alert-only
|
|
43
|
+
|
|
44
|
+
# View hit log
|
|
45
|
+
claude-watchdog --log
|
|
46
|
+
claude-watchdog --log --follow # tail -f mode
|
|
47
|
+
claude-watchdog --log --session claude-tl # filter by session
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Notify on hit
|
|
51
|
+
|
|
52
|
+
When a blockage is detected and cleared, claude-watchdog can notify you.
|
|
53
|
+
Pass `--notify` (or `-n`) to enable. Examples:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# Integrated: via hermes-notify (bus message, silent progress type)
|
|
57
|
+
claude-watchdog --session claude-tl --daemon --notify
|
|
58
|
+
|
|
59
|
+
# DIY: pipe stdout to anything you want
|
|
60
|
+
|
|
61
|
+
# HTTP webhook (Slack/Telegram/Discord/any API)
|
|
62
|
+
claude-watchdog --session claude-tl --daemon | while read line; do
|
|
63
|
+
curl -s -X POST https://hooks.slack.com/services/xxx/yyy/zzz \
|
|
64
|
+
-H "Content-Type: application/json" \
|
|
65
|
+
-d "{\"text\": \"$line\"}"
|
|
66
|
+
|
|
67
|
+
curl -s -X POST "https://api.telegram.org/bot<TOKEN>/sendMessage" \
|
|
68
|
+
-d "chat_id=<CHAT_ID>&text=$line"
|
|
69
|
+
done
|
|
70
|
+
|
|
71
|
+
# MCP notification (Model Context Protocol — tools with notifications)
|
|
72
|
+
claude-watchdog --session claude-tl --daemon | while read line; do
|
|
73
|
+
curl -s -X POST http://localhost:8080/mcp/notify \
|
|
74
|
+
-H "Content-Type: application/json" \
|
|
75
|
+
-d "{\"jsonrpc\": \"2.0\", \"method\": \"notifications/message\", \
|
|
76
|
+
\"params\": {\"severity\": \"warning\", \"message\": \"$line\"}}"
|
|
77
|
+
done
|
|
78
|
+
|
|
79
|
+
# macOS notification
|
|
80
|
+
claude-watchdog --session claude-tl --daemon | while read line; do
|
|
81
|
+
osascript -e "display notification \"$line\" with title \"Watchdog\""
|
|
82
|
+
done
|
|
83
|
+
|
|
84
|
+
# WeChat (via notify-hermes.py)
|
|
85
|
+
claude-watchdog --session claude-tl --daemon | while read line; do
|
|
86
|
+
~/.hermes/scripts/notify-hermes.py --type progress "Watchdog: $line"
|
|
87
|
+
done
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
The `--notify` flag auto-detects `hermes-notify` if installed. No hard
|
|
91
|
+
dependency — without it, `--notify` is a no-op.
|
|
92
|
+
|
|
93
|
+
## Rules
|
|
94
|
+
|
|
95
|
+
| Pattern | Keys | Description |
|
|
96
|
+
|---------|------|-------------|
|
|
97
|
+
| `Do you want to proceed` | 1 + Enter | Tool confirmation dialog |
|
|
98
|
+
| `Do you want to (make this edit\|overwrite)` | Down + Enter | Allow all edits this session |
|
|
99
|
+
| `accept edits on` | Enter | Accept pending diffs |
|
|
100
|
+
| `bypass permissions on` | Enter | Bypass permission dialog |
|
|
101
|
+
| `Detected a custom API key` | Up + Enter | Confirm custom API key |
|
|
102
|
+
| `Interrupted` | 2 + Enter | Bypass/continue after interruption |
|
|
103
|
+
| `Rate this response` / `评价` / `评分` | Escape | Dismiss evaluation dialog |
|
|
104
|
+
|
|
105
|
+
New patterns can go into `~/.config/claude-watchdog/rules.toml` (future).
|
|
106
|
+
|
|
107
|
+
## Log
|
|
108
|
+
|
|
109
|
+
Hits are logged to `~/.local/share/claude-watchdog/hits.log` as JSONL:
|
|
110
|
+
|
|
111
|
+
```json
|
|
112
|
+
{"ts": "2026-05-18 09:15:23", "session": "claude-tl", "rule": "bypass_permissions", "detail": "Permission bypass prompt — confirm bypass"}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Architecture
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
cli.py ── session/daemon/log ──→ watcher.py ── tmux capture-pane
|
|
119
|
+
│
|
|
120
|
+
↓ rules.py
|
|
121
|
+
pattern match?
|
|
122
|
+
├─ yes → send-keys + log [+ notify]
|
|
123
|
+
└─ no → silent
|
|
124
|
+
```
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# claude-watchdog
|
|
2
|
+
|
|
3
|
+
[English](./README.md) | [中文](./README.zh.md)
|
|
4
|
+
|
|
5
|
+
Claude Code tmux watchdog — auto-unblock permission dialogs so you
|
|
6
|
+
don't have to stare at a blocked session.
|
|
7
|
+
|
|
8
|
+
Only logs hits (blockage detected and cleared), silent otherwise.
|
|
9
|
+
|
|
10
|
+
## Install
|
|
11
|
+
|
|
12
|
+
```bash
|
|
13
|
+
pip install claude-watchdog
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
## Usage
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
# One-shot check (runs once, exits)
|
|
20
|
+
claude-watchdog --session claude-tl
|
|
21
|
+
|
|
22
|
+
# Monitor continuously
|
|
23
|
+
claude-watchdog --session claude-tl --daemon
|
|
24
|
+
|
|
25
|
+
# Monitor every claude-* session
|
|
26
|
+
claude-watchdog --all --daemon
|
|
27
|
+
|
|
28
|
+
# Alert only — log + notify, don't auto-approve
|
|
29
|
+
claude-watchdog --session claude-tl --daemon --alert-only
|
|
30
|
+
|
|
31
|
+
# View hit log
|
|
32
|
+
claude-watchdog --log
|
|
33
|
+
claude-watchdog --log --follow # tail -f mode
|
|
34
|
+
claude-watchdog --log --session claude-tl # filter by session
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Notify on hit
|
|
38
|
+
|
|
39
|
+
When a blockage is detected and cleared, claude-watchdog can notify you.
|
|
40
|
+
Pass `--notify` (or `-n`) to enable. Examples:
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
# Integrated: via hermes-notify (bus message, silent progress type)
|
|
44
|
+
claude-watchdog --session claude-tl --daemon --notify
|
|
45
|
+
|
|
46
|
+
# DIY: pipe stdout to anything you want
|
|
47
|
+
|
|
48
|
+
# HTTP webhook (Slack/Telegram/Discord/any API)
|
|
49
|
+
claude-watchdog --session claude-tl --daemon | while read line; do
|
|
50
|
+
curl -s -X POST https://hooks.slack.com/services/xxx/yyy/zzz \
|
|
51
|
+
-H "Content-Type: application/json" \
|
|
52
|
+
-d "{\"text\": \"$line\"}"
|
|
53
|
+
|
|
54
|
+
curl -s -X POST "https://api.telegram.org/bot<TOKEN>/sendMessage" \
|
|
55
|
+
-d "chat_id=<CHAT_ID>&text=$line"
|
|
56
|
+
done
|
|
57
|
+
|
|
58
|
+
# MCP notification (Model Context Protocol — tools with notifications)
|
|
59
|
+
claude-watchdog --session claude-tl --daemon | while read line; do
|
|
60
|
+
curl -s -X POST http://localhost:8080/mcp/notify \
|
|
61
|
+
-H "Content-Type: application/json" \
|
|
62
|
+
-d "{\"jsonrpc\": \"2.0\", \"method\": \"notifications/message\", \
|
|
63
|
+
\"params\": {\"severity\": \"warning\", \"message\": \"$line\"}}"
|
|
64
|
+
done
|
|
65
|
+
|
|
66
|
+
# macOS notification
|
|
67
|
+
claude-watchdog --session claude-tl --daemon | while read line; do
|
|
68
|
+
osascript -e "display notification \"$line\" with title \"Watchdog\""
|
|
69
|
+
done
|
|
70
|
+
|
|
71
|
+
# WeChat (via notify-hermes.py)
|
|
72
|
+
claude-watchdog --session claude-tl --daemon | while read line; do
|
|
73
|
+
~/.hermes/scripts/notify-hermes.py --type progress "Watchdog: $line"
|
|
74
|
+
done
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
The `--notify` flag auto-detects `hermes-notify` if installed. No hard
|
|
78
|
+
dependency — without it, `--notify` is a no-op.
|
|
79
|
+
|
|
80
|
+
## Rules
|
|
81
|
+
|
|
82
|
+
| Pattern | Keys | Description |
|
|
83
|
+
|---------|------|-------------|
|
|
84
|
+
| `Do you want to proceed` | 1 + Enter | Tool confirmation dialog |
|
|
85
|
+
| `Do you want to (make this edit\|overwrite)` | Down + Enter | Allow all edits this session |
|
|
86
|
+
| `accept edits on` | Enter | Accept pending diffs |
|
|
87
|
+
| `bypass permissions on` | Enter | Bypass permission dialog |
|
|
88
|
+
| `Detected a custom API key` | Up + Enter | Confirm custom API key |
|
|
89
|
+
| `Interrupted` | 2 + Enter | Bypass/continue after interruption |
|
|
90
|
+
| `Rate this response` / `评价` / `评分` | Escape | Dismiss evaluation dialog |
|
|
91
|
+
|
|
92
|
+
New patterns can go into `~/.config/claude-watchdog/rules.toml` (future).
|
|
93
|
+
|
|
94
|
+
## Log
|
|
95
|
+
|
|
96
|
+
Hits are logged to `~/.local/share/claude-watchdog/hits.log` as JSONL:
|
|
97
|
+
|
|
98
|
+
```json
|
|
99
|
+
{"ts": "2026-05-18 09:15:23", "session": "claude-tl", "rule": "bypass_permissions", "detail": "Permission bypass prompt — confirm bypass"}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## Architecture
|
|
103
|
+
|
|
104
|
+
```
|
|
105
|
+
cli.py ── session/daemon/log ──→ watcher.py ── tmux capture-pane
|
|
106
|
+
│
|
|
107
|
+
↓ rules.py
|
|
108
|
+
pattern match?
|
|
109
|
+
├─ yes → send-keys + log [+ notify]
|
|
110
|
+
└─ no → silent
|
|
111
|
+
```
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
import argparse
|
|
3
|
+
import subprocess
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
from .watcher import watch_loop, watch_all, get_sessions
|
|
7
|
+
from .logger import read_log
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def main():
|
|
11
|
+
parser = argparse.ArgumentParser(
|
|
12
|
+
prog="claude-watchdog",
|
|
13
|
+
description="Claude Code tmux watchdog — auto-unblock permission dialogs",
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
# Monitor mode
|
|
17
|
+
parser.add_argument("--session", "-s", type=str, default=None,
|
|
18
|
+
help="Session name to monitor (e.g. claude-tl)")
|
|
19
|
+
parser.add_argument("--all", "-a", action="store_true",
|
|
20
|
+
help="Monitor all claude-* sessions")
|
|
21
|
+
parser.add_argument("--daemon", "-d", action="store_true",
|
|
22
|
+
help="Run continuously until session ends")
|
|
23
|
+
parser.add_argument("--interval", "-i", type=int, default=10,
|
|
24
|
+
help="Poll interval in seconds (default: 10)")
|
|
25
|
+
parser.add_argument("--notify", "-n", action="store_true",
|
|
26
|
+
help="Send notification on hit via hermes-notify")
|
|
27
|
+
parser.add_argument("--alert-only", action="store_true",
|
|
28
|
+
help="Log+notify only, do NOT auto-approve dialogs")
|
|
29
|
+
|
|
30
|
+
# Log mode
|
|
31
|
+
parser.add_argument("--log", "-l", action="store_true",
|
|
32
|
+
help="View hit log")
|
|
33
|
+
parser.add_argument("--last", type=int, default=20,
|
|
34
|
+
help="Last N log entries (default: 20)")
|
|
35
|
+
parser.add_argument("--follow", "-f", action="store_true",
|
|
36
|
+
help="Tail -f the log")
|
|
37
|
+
|
|
38
|
+
args = parser.parse_args()
|
|
39
|
+
|
|
40
|
+
# --log mode
|
|
41
|
+
if args.log:
|
|
42
|
+
read_log(last=args.last, follow=args.follow, session_filter=args.session)
|
|
43
|
+
return
|
|
44
|
+
|
|
45
|
+
# --daemon without --session or --all: auto-detect
|
|
46
|
+
if args.daemon and not args.session and not args.all:
|
|
47
|
+
sessions = get_sessions()
|
|
48
|
+
if not sessions:
|
|
49
|
+
print("No claude-* tmux sessions found.")
|
|
50
|
+
sys.exit(1)
|
|
51
|
+
if len(sessions) == 1:
|
|
52
|
+
args.session = sessions[0]
|
|
53
|
+
else:
|
|
54
|
+
print(f"Multiple sessions found: {', '.join(sessions)}. Use --session or --all.")
|
|
55
|
+
sys.exit(1)
|
|
56
|
+
|
|
57
|
+
# Validate
|
|
58
|
+
if not args.session and not args.all:
|
|
59
|
+
parser.print_help()
|
|
60
|
+
sys.exit(1)
|
|
61
|
+
|
|
62
|
+
# One-shot check
|
|
63
|
+
if not args.daemon:
|
|
64
|
+
from .watcher import check_session
|
|
65
|
+
if args.all:
|
|
66
|
+
sessions = get_sessions()
|
|
67
|
+
for s in sessions:
|
|
68
|
+
check_session(s, args.notify, args.alert_only)
|
|
69
|
+
else:
|
|
70
|
+
from .watcher import session_exists
|
|
71
|
+
if not session_exists(args.session):
|
|
72
|
+
print(f"Session '{args.session}' not found.")
|
|
73
|
+
sys.exit(1)
|
|
74
|
+
check_session(args.session, args.notify, args.alert_only)
|
|
75
|
+
return
|
|
76
|
+
|
|
77
|
+
# Daemon mode
|
|
78
|
+
if args.all:
|
|
79
|
+
print(f"Watching all claude-* sessions (interval={args.interval}s)")
|
|
80
|
+
watch_all(interval=args.interval, use_notify=args.notify, alert_only=args.alert_only)
|
|
81
|
+
else:
|
|
82
|
+
print(f"Watching session '{args.session}' (interval={args.interval}s)")
|
|
83
|
+
watch_loop(args.session, interval=args.interval, use_notify=args.notify, alert_only=args.alert_only)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
if __name__ == "__main__":
|
|
87
|
+
main()
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
import time
|
|
4
|
+
from datetime import datetime
|
|
5
|
+
|
|
6
|
+
LOG_DIR = os.path.expanduser("~/.local/share/claude-watchdog")
|
|
7
|
+
LOG_FILE = os.path.join(LOG_DIR, "hits.log")
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def _ensure_log_dir():
|
|
11
|
+
os.makedirs(LOG_DIR, exist_ok=True)
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
def log_hit(session: str, rule_name: str, detail: str):
|
|
15
|
+
_ensure_log_dir()
|
|
16
|
+
ts = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
17
|
+
line = json.dumps({"ts": ts, "session": session, "rule": rule_name, "detail": detail})
|
|
18
|
+
with open(LOG_FILE, "a") as f:
|
|
19
|
+
f.write(line + "\n")
|
|
20
|
+
# Also print to stdout so --daemon runner sees it
|
|
21
|
+
print(f"[{ts}] ⛔ {session}: {detail}")
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def read_log(last: int = 20, follow: bool = False, session_filter: str | None = None):
|
|
25
|
+
_ensure_log_dir()
|
|
26
|
+
if not os.path.exists(LOG_FILE):
|
|
27
|
+
print("No hits yet.")
|
|
28
|
+
return
|
|
29
|
+
|
|
30
|
+
if follow:
|
|
31
|
+
import subprocess
|
|
32
|
+
cmd = ["tail", "-f", LOG_FILE]
|
|
33
|
+
if last:
|
|
34
|
+
cmd.insert(1, f"-n{last}")
|
|
35
|
+
proc = subprocess.run(cmd)
|
|
36
|
+
proc.check_returncode()
|
|
37
|
+
return
|
|
38
|
+
|
|
39
|
+
lines = []
|
|
40
|
+
with open(LOG_FILE) as f:
|
|
41
|
+
for line in f:
|
|
42
|
+
lines.append(line)
|
|
43
|
+
|
|
44
|
+
for line in lines[-last:]:
|
|
45
|
+
try:
|
|
46
|
+
entry = json.loads(line)
|
|
47
|
+
if session_filter and entry.get("session") != session_filter:
|
|
48
|
+
continue
|
|
49
|
+
ts = entry["ts"]
|
|
50
|
+
detail = entry["detail"]
|
|
51
|
+
print(f"[{ts}] ⛔ {detail}")
|
|
52
|
+
except json.JSONDecodeError:
|
|
53
|
+
print(line.strip())
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Optional notify integration — bridges to hermes-notify if available."""
|
|
2
|
+
import shutil
|
|
3
|
+
import subprocess
|
|
4
|
+
import shlex
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def _notify_cmd() -> str | None:
|
|
8
|
+
"""Return notify CLI path if installed."""
|
|
9
|
+
return shutil.which("hermes-notify") or shutil.which("notify")
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def send_hit(session: str, rule_name: str, detail: str):
|
|
13
|
+
cmd = _notify_cmd()
|
|
14
|
+
if not cmd:
|
|
15
|
+
return # notify not installed, silent skip
|
|
16
|
+
try:
|
|
17
|
+
text = shlex.quote(f"[watchdog] {session}: {detail}")
|
|
18
|
+
subprocess.run(
|
|
19
|
+
f"{cmd} send --type progress --text {text}",
|
|
20
|
+
shell=True,
|
|
21
|
+
timeout=5,
|
|
22
|
+
capture_output=True,
|
|
23
|
+
)
|
|
24
|
+
except Exception:
|
|
25
|
+
pass # notify failure is non-critical
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# Rule: list of dialog patterns with match regex and keystroke sequence
|
|
2
|
+
# Each entry: (name, regex, keys, description)
|
|
3
|
+
|
|
4
|
+
RULES = [
|
|
5
|
+
(
|
|
6
|
+
"proceed",
|
|
7
|
+
r"Do you want to proceed",
|
|
8
|
+
["1", "Enter"],
|
|
9
|
+
"Tool confirmation dialog — select option 1 (Yes)",
|
|
10
|
+
),
|
|
11
|
+
(
|
|
12
|
+
"edit_or_overwrite",
|
|
13
|
+
r"Do you want to (make this edit|overwrite)",
|
|
14
|
+
["Down", "Enter"],
|
|
15
|
+
"File edit/overwrite dialog — 'Allow all this session'",
|
|
16
|
+
),
|
|
17
|
+
(
|
|
18
|
+
"accept_edits",
|
|
19
|
+
r"accept edits on",
|
|
20
|
+
["Enter"],
|
|
21
|
+
"Diff review prompt — accept pending diffs",
|
|
22
|
+
),
|
|
23
|
+
(
|
|
24
|
+
"bypass_permissions",
|
|
25
|
+
r"bypass permissions on",
|
|
26
|
+
["Enter"],
|
|
27
|
+
"Permission bypass prompt — confirm bypass",
|
|
28
|
+
),
|
|
29
|
+
(
|
|
30
|
+
"custom_api_key",
|
|
31
|
+
r"Detected a custom API key",
|
|
32
|
+
["Up", "Enter"],
|
|
33
|
+
"API key detection — confirm custom key (select Yes)",
|
|
34
|
+
),
|
|
35
|
+
(
|
|
36
|
+
"interrupted",
|
|
37
|
+
r"Interrupted",
|
|
38
|
+
["2", "Enter"],
|
|
39
|
+
"Interrupted dialog — select option 2 (Bypass/Continue)",
|
|
40
|
+
),
|
|
41
|
+
(
|
|
42
|
+
"rate_claude",
|
|
43
|
+
r"(Rate this response|How was this)",
|
|
44
|
+
["Escape"],
|
|
45
|
+
"Rating/evaluation dialog — dismiss (press Escape)",
|
|
46
|
+
),
|
|
47
|
+
]
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import re
|
|
2
|
+
import subprocess
|
|
3
|
+
import time
|
|
4
|
+
|
|
5
|
+
from .rules import RULES
|
|
6
|
+
from .logger import log_hit
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def get_sessions() -> list[str]:
|
|
10
|
+
"""List all running tmux sessions whose name starts with 'claude-'."""
|
|
11
|
+
try:
|
|
12
|
+
result = subprocess.run(
|
|
13
|
+
["tmux", "list-sessions", "-F", "#{session_name}"],
|
|
14
|
+
capture_output=True, text=True, timeout=5,
|
|
15
|
+
)
|
|
16
|
+
return [s.strip() for s in result.stdout.splitlines() if s.strip().startswith("claude-")]
|
|
17
|
+
except (subprocess.TimeoutExpired, FileNotFoundError):
|
|
18
|
+
return []
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def session_exists(session: str) -> bool:
|
|
22
|
+
try:
|
|
23
|
+
subprocess.run(
|
|
24
|
+
["tmux", "has-session", "-t", session],
|
|
25
|
+
capture_output=True, timeout=3, check=True,
|
|
26
|
+
)
|
|
27
|
+
return True
|
|
28
|
+
except (subprocess.CalledProcessError, subprocess.TimeoutExpired, FileNotFoundError):
|
|
29
|
+
return False
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def capture_pane(session: str, lines: int = 15) -> str:
|
|
33
|
+
try:
|
|
34
|
+
result = subprocess.run(
|
|
35
|
+
["tmux", "capture-pane", "-t", session, "-p", "-S", f"-{lines}"],
|
|
36
|
+
capture_output=True, text=True, timeout=5,
|
|
37
|
+
)
|
|
38
|
+
return result.stdout
|
|
39
|
+
except (subprocess.TimeoutExpired, FileNotFoundError):
|
|
40
|
+
return ""
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def send_keys(session: str, keys: list[str]):
|
|
44
|
+
import shlex
|
|
45
|
+
for key in keys:
|
|
46
|
+
subprocess.run(
|
|
47
|
+
["tmux", "send-keys", "-t", session, key],
|
|
48
|
+
capture_output=True, timeout=3,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def check_session(session: str, use_notify: bool = False, alert_only: bool = False) -> bool:
|
|
53
|
+
"""
|
|
54
|
+
Check a single session for blocked dialogs.
|
|
55
|
+
Returns True if a dialog was detected and cleared.
|
|
56
|
+
"""
|
|
57
|
+
output = capture_pane(session)
|
|
58
|
+
if not output:
|
|
59
|
+
return False
|
|
60
|
+
|
|
61
|
+
for name, pattern, keys, desc in RULES:
|
|
62
|
+
if re.search(pattern, output, re.MULTILINE):
|
|
63
|
+
if not alert_only:
|
|
64
|
+
send_keys(session, keys)
|
|
65
|
+
log_hit(session, name, desc)
|
|
66
|
+
if use_notify:
|
|
67
|
+
from .notify import send_hit
|
|
68
|
+
send_hit(session, name, desc)
|
|
69
|
+
return True
|
|
70
|
+
return False
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
def watch_loop(session: str, interval: int = 10, use_notify: bool = False, alert_only: bool = False):
|
|
74
|
+
"""Continuously monitor a session until it disappears."""
|
|
75
|
+
while session_exists(session):
|
|
76
|
+
check_session(session, use_notify, alert_only)
|
|
77
|
+
time.sleep(interval)
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def watch_all(interval: int = 10, use_notify: bool = False, alert_only: bool = False):
|
|
81
|
+
"""Monitor all claude-* sessions in a round-robin."""
|
|
82
|
+
while True:
|
|
83
|
+
sessions = get_sessions()
|
|
84
|
+
if not sessions:
|
|
85
|
+
time.sleep(interval)
|
|
86
|
+
continue
|
|
87
|
+
for s in sessions:
|
|
88
|
+
check_session(s, use_notify, alert_only)
|
|
89
|
+
time.sleep(interval)
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: claude-watchdog
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Claude Code tmux watchdog — auto-unblock permission dialogs
|
|
5
|
+
Author: LinQuan
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: homepage, https://github.com/mlinquan/claude-watchdog
|
|
8
|
+
Project-URL: repository, https://github.com/mlinquan/claude-watchdog
|
|
9
|
+
Requires-Python: >=3.10
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Dynamic: license-file
|
|
13
|
+
|
|
14
|
+
# claude-watchdog
|
|
15
|
+
|
|
16
|
+
[English](./README.md) | [中文](./README.zh.md)
|
|
17
|
+
|
|
18
|
+
Claude Code tmux watchdog — auto-unblock permission dialogs so you
|
|
19
|
+
don't have to stare at a blocked session.
|
|
20
|
+
|
|
21
|
+
Only logs hits (blockage detected and cleared), silent otherwise.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install claude-watchdog
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
# One-shot check (runs once, exits)
|
|
33
|
+
claude-watchdog --session claude-tl
|
|
34
|
+
|
|
35
|
+
# Monitor continuously
|
|
36
|
+
claude-watchdog --session claude-tl --daemon
|
|
37
|
+
|
|
38
|
+
# Monitor every claude-* session
|
|
39
|
+
claude-watchdog --all --daemon
|
|
40
|
+
|
|
41
|
+
# Alert only — log + notify, don't auto-approve
|
|
42
|
+
claude-watchdog --session claude-tl --daemon --alert-only
|
|
43
|
+
|
|
44
|
+
# View hit log
|
|
45
|
+
claude-watchdog --log
|
|
46
|
+
claude-watchdog --log --follow # tail -f mode
|
|
47
|
+
claude-watchdog --log --session claude-tl # filter by session
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Notify on hit
|
|
51
|
+
|
|
52
|
+
When a blockage is detected and cleared, claude-watchdog can notify you.
|
|
53
|
+
Pass `--notify` (or `-n`) to enable. Examples:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
# Integrated: via hermes-notify (bus message, silent progress type)
|
|
57
|
+
claude-watchdog --session claude-tl --daemon --notify
|
|
58
|
+
|
|
59
|
+
# DIY: pipe stdout to anything you want
|
|
60
|
+
|
|
61
|
+
# HTTP webhook (Slack/Telegram/Discord/any API)
|
|
62
|
+
claude-watchdog --session claude-tl --daemon | while read line; do
|
|
63
|
+
curl -s -X POST https://hooks.slack.com/services/xxx/yyy/zzz \
|
|
64
|
+
-H "Content-Type: application/json" \
|
|
65
|
+
-d "{\"text\": \"$line\"}"
|
|
66
|
+
|
|
67
|
+
curl -s -X POST "https://api.telegram.org/bot<TOKEN>/sendMessage" \
|
|
68
|
+
-d "chat_id=<CHAT_ID>&text=$line"
|
|
69
|
+
done
|
|
70
|
+
|
|
71
|
+
# MCP notification (Model Context Protocol — tools with notifications)
|
|
72
|
+
claude-watchdog --session claude-tl --daemon | while read line; do
|
|
73
|
+
curl -s -X POST http://localhost:8080/mcp/notify \
|
|
74
|
+
-H "Content-Type: application/json" \
|
|
75
|
+
-d "{\"jsonrpc\": \"2.0\", \"method\": \"notifications/message\", \
|
|
76
|
+
\"params\": {\"severity\": \"warning\", \"message\": \"$line\"}}"
|
|
77
|
+
done
|
|
78
|
+
|
|
79
|
+
# macOS notification
|
|
80
|
+
claude-watchdog --session claude-tl --daemon | while read line; do
|
|
81
|
+
osascript -e "display notification \"$line\" with title \"Watchdog\""
|
|
82
|
+
done
|
|
83
|
+
|
|
84
|
+
# WeChat (via notify-hermes.py)
|
|
85
|
+
claude-watchdog --session claude-tl --daemon | while read line; do
|
|
86
|
+
~/.hermes/scripts/notify-hermes.py --type progress "Watchdog: $line"
|
|
87
|
+
done
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
The `--notify` flag auto-detects `hermes-notify` if installed. No hard
|
|
91
|
+
dependency — without it, `--notify` is a no-op.
|
|
92
|
+
|
|
93
|
+
## Rules
|
|
94
|
+
|
|
95
|
+
| Pattern | Keys | Description |
|
|
96
|
+
|---------|------|-------------|
|
|
97
|
+
| `Do you want to proceed` | 1 + Enter | Tool confirmation dialog |
|
|
98
|
+
| `Do you want to (make this edit\|overwrite)` | Down + Enter | Allow all edits this session |
|
|
99
|
+
| `accept edits on` | Enter | Accept pending diffs |
|
|
100
|
+
| `bypass permissions on` | Enter | Bypass permission dialog |
|
|
101
|
+
| `Detected a custom API key` | Up + Enter | Confirm custom API key |
|
|
102
|
+
| `Interrupted` | 2 + Enter | Bypass/continue after interruption |
|
|
103
|
+
| `Rate this response` / `评价` / `评分` | Escape | Dismiss evaluation dialog |
|
|
104
|
+
|
|
105
|
+
New patterns can go into `~/.config/claude-watchdog/rules.toml` (future).
|
|
106
|
+
|
|
107
|
+
## Log
|
|
108
|
+
|
|
109
|
+
Hits are logged to `~/.local/share/claude-watchdog/hits.log` as JSONL:
|
|
110
|
+
|
|
111
|
+
```json
|
|
112
|
+
{"ts": "2026-05-18 09:15:23", "session": "claude-tl", "rule": "bypass_permissions", "detail": "Permission bypass prompt — confirm bypass"}
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
## Architecture
|
|
116
|
+
|
|
117
|
+
```
|
|
118
|
+
cli.py ── session/daemon/log ──→ watcher.py ── tmux capture-pane
|
|
119
|
+
│
|
|
120
|
+
↓ rules.py
|
|
121
|
+
pattern match?
|
|
122
|
+
├─ yes → send-keys + log [+ notify]
|
|
123
|
+
└─ no → silent
|
|
124
|
+
```
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
claude_watchdog/cli.py
|
|
5
|
+
claude_watchdog/logger.py
|
|
6
|
+
claude_watchdog/notify.py
|
|
7
|
+
claude_watchdog/rules.py
|
|
8
|
+
claude_watchdog/watcher.py
|
|
9
|
+
claude_watchdog.egg-info/PKG-INFO
|
|
10
|
+
claude_watchdog.egg-info/SOURCES.txt
|
|
11
|
+
claude_watchdog.egg-info/dependency_links.txt
|
|
12
|
+
claude_watchdog.egg-info/entry_points.txt
|
|
13
|
+
claude_watchdog.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
claude_watchdog
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "claude-watchdog"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Claude Code tmux watchdog — auto-unblock permission dialogs"
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
license = {text = "MIT"}
|
|
7
|
+
authors = [{name = "LinQuan"}]
|
|
8
|
+
requires-python = ">=3.10"
|
|
9
|
+
dependencies = []
|
|
10
|
+
|
|
11
|
+
[project.urls]
|
|
12
|
+
homepage = "https://github.com/mlinquan/claude-watchdog"
|
|
13
|
+
repository = "https://github.com/mlinquan/claude-watchdog"
|
|
14
|
+
|
|
15
|
+
[project.scripts]
|
|
16
|
+
claude-watchdog = "claude_watchdog.cli:main"
|
|
17
|
+
|
|
18
|
+
[tool.setuptools.packages.find]
|
|
19
|
+
include = ["claude_watchdog*"]
|
|
20
|
+
|
|
21
|
+
[build-system]
|
|
22
|
+
requires = ["setuptools", "wheel"]
|
|
23
|
+
build-backend = "setuptools.build_meta"
|