-
Notifications
You must be signed in to change notification settings - Fork 4
stop_hook.py crashes with PermissionError when cwd is not readable #20
Description
Bug
stop_hook.py crashes when the current working directory is not readable (e.g., macOS sandbox restrictions on Claude Code).
Error
Traceback (most recent call last):
File "stop_hook.py", line 45, in <module>
main()
File "stop_hook.py", line 35, in main
cwd = os.environ.get('FEWWORD_CWD', os.getcwd())
PermissionError: [Errno 1] Operation not permitted
/bin/sh: python: command not found
Root cause
Two issues:
-
os.getcwd()instop_hook.py:35— whenFEWWORD_CWDis not set,os.getcwd()is used as fallback. This raisesPermissionErrorif the working directory is not readable (common with macOS sandbox). -
||operator inhooks.json— the hook command pattern is:command -v python3 >/dev/null && python3 "...stop_hook.py" || python "...stop_hook.py"When
python3is found but the script itself fails (non-zero exit), the||triggers and tries to runpython, which doesn't exist on macOS. This produces the secondary error/bin/sh: python: command not found.
Suggested fix
stop_hook.py:35 — wrap os.getcwd() in try/except:
try:
cwd = os.environ.get('FEWWORD_CWD') or os.getcwd()
except (PermissionError, OSError):
cwd = os.path.expanduser('~') # safe fallbackhooks.json — use subshell grouping so || only fires when python3 is not found, not when the script fails:
(command -v python3 >/dev/null && python3 "...") || python "..."
Or simply:
python3 "..." 2>/dev/null || python "..."
Environment
- macOS (Darwin 25.2.0)
- Claude Code CLI with sandbox
- FewWord 1.3.10
- python3 available, python not available