Skip to content

Commit df52195

Browse files
mostrubclaude
andcommitted
fix: pass project cwd to mgrep watch subprocess
The SessionStart hook reads `cwd` from the hook payload but never passes it to subprocess.Popen. This causes `mgrep watch` to inherit the hook runner's working directory (often ~/), which fails with "Cannot watch home directory or any parent directory". Fix: add cwd=cwd to the Popen call so the watcher starts in the actual project directory. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fe2c523 commit df52195

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

plugins/mgrep/hooks/mgrep_watch.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,10 @@ def read_hook_input():
3939
debug_log(f"PID file already exists: {pid_file}")
4040
sys.exit(1)
4141

42-
process = subprocess.Popen(["mgrep", "watch"], preexec_fn=os.setsid, stdout=open(f"/tmp/mgrep-watch-command-{payload.get('session_id')}.log", "w"), stderr=open(f"/tmp/mgrep-watch-command-{payload.get('session_id')}.log", "w"))
42+
debug_log(f"Starting mgrep watch in cwd: {cwd}")
43+
log_file = open(f"/tmp/mgrep-watch-command-{payload.get('session_id')}.log", "w")
44+
process = subprocess.Popen(["mgrep", "watch"], cwd=cwd, preexec_fn=os.setsid, stdout=log_file, stderr=log_file)
4345
debug_log(f"Started mgrep watch process: {process.pid}")
44-
debug_log(f"All environment variables: {os.environ}")
4546
with open(pid_file, "w") as handle:
4647
handle.write(str(process.pid))
4748

0 commit comments

Comments
 (0)