Expose print mode (-p) in hook context

Resolved 💬 1 comment Opened Mar 29, 2026 by 3amyatin Closed Mar 29, 2026

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=1 env var, or
  • "print_mode": true field 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.

View original on GitHub ↗

This issue has 1 comment on GitHub. Read the full discussion on GitHub ↗