Add Claude Code usage notes for sub-agent workflow

This commit is contained in:
Hoid 2026-02-14 11:50:39 +00:00
parent a6afccf123
commit e769311db4
5 changed files with 59 additions and 18 deletions

View file

@ -1,19 +1,10 @@
#!/bin/bash
# Wrapper that sets ANTHROPIC_API_KEY from OpenClaw's auth config
export ANTHROPIC_API_KEY=$(python3 -c "
import json
with open('/home/openclaw/.openclaw/agents/main/agent/auth-profiles.json') as f:
data = json.load(f)
for key, profile in data.get('profiles', {}).items():
if 'anthropic' in key:
print(profile.get('token', ''))
break
" 2>/dev/null)
#!/usr/bin/env bash
# Claude Code CLI wrapper
# Usage: claude-code "task description" [working-dir]
set -euo pipefail
if [ -z "$ANTHROPIC_API_KEY" ]; then
echo "Error: Could not extract Anthropic API key from auth-profiles.json"
exit 1
fi
TASK="${1:?Usage: claude-code <task> [working-dir]}"
WORKDIR="${2:-$(pwd)}"
export PATH=$PATH:/usr/local/go/bin
exec claude "$@"
cd "$WORKDIR"
exec claude -p "$TASK" --allowedTools "Edit,Write,Bash"

BIN
debug_health_orb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 33 KiB

BIN
debug_mana_orb.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 32 KiB

@ -1 +1 @@
Subproject commit 67f2e5536aba342d3108cecdac29d3839cbd6dac
Subproject commit 0716aeb5e13a100a632eff255e33f840240f0715

View file

@ -0,0 +1,50 @@
# Claude Code Usage Notes
## Golden Rule
**User gives task → spawn sub-agent → sub-agent runs Claude Code → sub-agent verifies → user gets ONE summary message. No play-by-play.**
## How to Use Claude Code
### Via Sub-Agent (preferred for complex tasks)
```
sessions_spawn with task like:
"Run Claude Code to [task]. Working dir: /path/to/project.
After Claude Code finishes, verify the changes compile and make sense.
If not, run Claude Code again with fixes. Commit and push when done."
```
### Direct (simple tasks only)
```bash
cd /path/to/project
claude -p "task description" --allowedTools "Edit,Write,Bash"
```
## Key Facts
- **Default model**: Opus 4.6 (no override needed)
- **Auth**: OAuth login already completed, no API key needed
- **Allowed tools**: Always pass `--allowedTools "Edit,Write,Bash"`
- **Timeout**: Claude Code can take 5-20 minutes for complex tasks. Don't micromanage.
- **Hanging**: Sometimes streams hang after ~10-15 min. Sub-agent can detect this and retry.
- **PTY mode**: Use `pty=true` when running via exec
## Sub-Agent Task Template
```
Run Claude Code CLI in /path/to/project to do the following:
[TASK DESCRIPTION]
Steps:
1. Run: cd /path/to/project && claude -p "[task]" --allowedTools "Edit,Write,Bash"
2. Wait for completion (up to 20 min, check if process is still alive periodically)
3. If it hangs (no file changes for 10+ min), kill and retry once
4. After completion, verify: go build / npm build / etc
5. If build fails, run Claude Code again with the error
6. Commit and push when everything works
7. Report summary of all changes made
```
## Anti-Patterns
- ❌ Polling every 30 seconds and reporting progress
- ❌ Sending WhatsApp messages during the process
- ❌ Reading every file before/after to narrate changes
- ✅ Fire and forget, verify at end, report once