Expose print mode (-p) in hook context
Problem
Hooks (especially Stop hooks) have no way to detect if the current session is running in print mode (-p / --print). The environment variables available in hooks (CLAUDECODE, CLAUDE_CODE_ENTRYPOINT=cli) are identical for both interactive and -p sessions.
Impact
Stop hooks that modify Claude's behavior (e.g., memory checks, review prompts) fire for headless -p subprocess calls too. When Claude responds to the hook's blocking message, it replaces its original output (e.g., JSON) with commentary, breaking automation pipelines that parse structured output.
Proposed solution
Expose a variable in the hook context, e.g.:
CLAUDE_CODE_PRINT_MODE=1env var, or"print_mode": truefield in the hook's stdin JSON
Workaround
Currently the only workaround is setting a custom env var in the subprocess call and checking it in the hook — but this only works for projects you control, not for arbitrary claude -p usage.
This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗