Pitfall Memory peon-notify

Unset Claudecode Nested Cli

claude-codeenv-varnestedpeon-notify

What Happened

PeonNotify hooks shell out to claude -p for AI calls: CodeGuard runs lint review, DocGuard generates changelogs, and Obsidian extracts vault notes. All three failed silently. No error, no output : the hook completed but the AI call produced nothing. The CLAUDECODE environment variable set by the parent session was the cause.

Root Cause

When Claude Code runs, it sets a CLAUDECODE environment variable. Any child process inherits it. When a hook script calls claude -p, the nested CLI detects CLAUDECODE and refuses to run : it interprets this as a re-entrant call from within an active session, which it blocks to prevent infinite recursion. The refusal is silent: no stderr, no exit code surfaced to the hook caller.

How to Avoid

Always unset CLAUDECODE before calling claude -p in any hook script:

unset CLAUDECODE
claude -p "Your prompt here" --model sonnet

This is required for every hook that shells out to Claude: CodeGuard, DocGuard, Obsidian flush, or any future hook that makes AI calls.