Skip to content

stop_hook.py crashes with PermissionError when cwd is not readable #20

@arshtanov

Description

@arshtanov

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:

  1. os.getcwd() in stop_hook.py:35 — when FEWWORD_CWD is not set, os.getcwd() is used as fallback. This raises PermissionError if the working directory is not readable (common with macOS sandbox).

  2. || operator in hooks.json — the hook command pattern is:

    command -v python3 >/dev/null && python3 "...stop_hook.py" || python "...stop_hook.py"
    

    When python3 is found but the script itself fails (non-zero exit), the || triggers and tries to run python, 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 fallback

hooks.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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions