Sub-agents ignore CLAUDE.md rules and memory files when writing automation scripts
Resolved 💬 3 comments Opened Mar 31, 2026 by minatoplanb Closed Apr 4, 2026
Description
When Claude Code is asked to write a batch automation script (e.g., a Python script that calls an external API), it bypasses all safety mechanisms that are in place for interactive tool use:
- CLAUDE.md rules are ignored — Rules like "NEVER change workflow settings without asking" were documented but not followed when building the script
- Memory files with LOCKED/CRITICAL settings are not consulted — Verified settings were documented in memory files with explicit "DO NOT CHANGE" labels, but the agent built the script from scratch using different values
- PreToolUse hooks are bypassed — Hooks that validate settings on interactive tool calls (Bash, Write, Edit) have no effect on the content of generated scripts that make HTTP API calls
- No diff/comparison step — The agent never compared its generated settings against the documented verified settings before executing
Reproduction
- Document verified settings in memory files marked as LOCKED/CRITICAL
- Set up PreToolUse hooks that enforce those settings
- Ask Claude to write a batch Python script that calls an external API (e.g., ComfyUI REST API)
- The generated script will use whatever values Claude decides, ignoring both memory files and hooks
Expected Behavior
When generating scripts that automate external systems, Claude should:
- Read and follow CLAUDE.md rules and memory files the same way it does for interactive tool use
- Compare generated settings against documented LOCKED settings before execution
- Show the user a settings diff before batch execution
- Not silently change values that are documented as verified/locked
Actual Behavior
Claude extracted settings from a stale UI state via graphToPrompt(), hardcoded incorrect values (wrong duration, wrong NAG scale, wrong upscaler), and batch-executed 60 jobs with wrong settings — wasting ~2 hours of GPU time and producing unusable output.
Impact
- 60 videos generated with wrong settings (truncated duration + subtitle-causing parameters)
- User's overnight automation time wasted
- All existing safety hooks (5+ hooks, CLAUDE.md rules, memory LOCKED flags) were ineffective because the work was done inside a generated Python script
Environment
- Claude Code on Windows 11
- Multiple PreToolUse hooks installed
- Extensive CLAUDE.md and memory files with documented rules
- ComfyUI REST API as the external system
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗