This is a MANDATORY IRON RULE for all OpenClaw agents across all projects.
When you receive a software task (implementation, testing, refactoring, spec writing, deployment scripts, etc.), you MUST delegate it to Claude Code (claude CLI) running as a non-interactive background agent.
ALWAYS. EVERY TIME. NO EXCEPTIONS.
claude -p --dangerously-skip-permissions --model claude-opus-4-6 "<task prompt>" 2>&1Without --dangerously-skip-permissions, Claude Code will HANG waiting for user input to approve file writes. There is no user at the terminal. It will hang forever. This flag is not optional.
Required flags — ALL THREE, ALWAYS:
-p— non-interactive (print mode), no user input needed--dangerously-skip-permissions— IRON RULE: ALWAYS USE THIS. NEVER OMIT.--model claude-opus-4-6— always use Opus 4.6 for quality
Execution pattern:
exec pty:true background:true workdir:<project-dir> timeout:600 command:"claude -p --dangerously-skip-permissions --model claude-opus-4-6 '<prompt>' 2>&1 | tee /tmp/claude-agent-<task-name>.log"Logging is MANDATORY. Always pipe through tee to a log file. Claude Code -p buffers all output until completion — without logging you can't debug failures after the fact. Log file naming: /tmp/claude-agent-<short-task-name>.log
- NEVER hand-code changes yourself when the task is non-trivial (>1 file or >20 lines). Delegate to Claude Code.
- ALWAYS use non-interactive mode (
-p). Never spawn interactive Claude Code sessions. - ALWAYS use
--dangerously-skip-permissionsto avoid hanging on permission prompts. - ALWAYS use
--model claude-opus-4-6for consistent quality. - Use
pty:true— Claude Code is a terminal application. - Use
background:truefor long tasks, then poll for completion. - Parallel agents are OK — spawn multiple for independent tasks.
- Include specs by reference — tell the agent to
Read <spec-file>rather than inlining huge prompts. - End with notification — append
When completely finished, run: openclaw system event --text 'Done: <summary>' --mode nowto get notified on completion. - Verify after completion — always run tests / check outputs after agent finishes.
- Commit results — commit the agent's work with a descriptive message.
- Creating or editing code files
- Writing deployment scripts
- Adding tests (unit, e2e, integration)
- Refactoring
- Writing technical specs (that involve reading code)
- Build/CI configuration
- Database migrations
- Simple one-line fixes (just use
edittool directly) - Reading/exploring code (just use
readtool) - Git operations (just use
exec) - Documentation-only changes (use
writetool)
Claude Code -p buffers ALL output until completion. This means:
process logwill show nothing until the agent finishes- Use
process pollwith long timeouts (120-300 seconds) - Check process is alive with
ps aux | grep claudeif worried - Typical task takes 2-8 minutes
Read <spec-file> for full spec.
YOUR TASK: <clear description>
1. <step 1>
2. <step 2>
...
When completely finished, run: openclaw system event --text 'Done: <summary>' --mode now