Lesson #1457
← Back to Knowledge Board
Use n8n agent-dispatch automation instead of subprocess CLI spawns
- ID
- 1457
- Author
- Agent
- agent-claude
- Reviewed
- No (unreviewed)
- Source authority
- 75 / 100
- Source
- Token-saving β let n8n flows handle agent dispatch via Gitea webhooks, not direct CLI subprocess
- Source issue
- β
- Created at
- 2026-05-12T10:00:23.188348+00:00
- Valid until
- β
- Deprecated at
- β
- Supersedes
- β
- Obsidian path
- /root/.claude/projects/-nvmetank1-projects/memory/feedback_n8n_automation.md
- Obsidian hash
- d065ea2385d9bf5658a48ca5b2a0766b
- Tags
- claude-memory,feedback,deprecated
Content
**Rule:** When delegating tasks to external agents (codex/gemini/or-agent/qwen/cursor), prefer creating Gitea issues with `agent-X` labels + `@agent-X` mentions over spawning the CLI directly via Bash subprocess. The existing n8n flow handles dispatch.
**Why:** User said 2026-05-04: "nutze dein wissen ΓΌber n8n hier auf dem plattform um dinge zu automatisieren und weniger tokens zu verbauchen". Token cost: spawning a 5-min or-agent run via background bash burns Claude tokens for prompt-write + monitor-loop + log-parse. Letting n8n dispatch + handler-script + Gitea-comment-back is fully out-of-band.
**The n8n flow (existing):**
- Webhook: Gitea sends issue/comment events to n8n
- Flow: `03-agent-dispatch` (look for it in n8n UI at automation.joelduss.xyz)
- Trigger: issue/comment contains `@agent-<name>` OR has label `agent-<name>` + `status-ready`
- Action: invokes `/usr/local/bin/agent-handler-<name>.sh <repo> <issue-number>`
- The handler reads the issue, runs the agent CLI, posts result as comment, optionally pushes branch + opens PR
**How to apply:**
1. **Create Gitea issue** via `mcp__gitea__issue_write method=create` with:
- Body containing `## Task / ## Steps / ## Acceptance` structure
- `@agent-<name>` mention in body
- Labels: `agent-<name>` + `priority-{low,high}` + `status-ready` + `type-{bug,feature,refactor,doc}`
2. **Walk away** β the n8n flow + handler does the work.
3. **Monitor** by polling `mcp__gitea__list_issues label=agent-<name> state=open` every 5-10 min, or watch for `status-review` label transition (handler sets this when PR opened).
4. **Merge PR** when handler comments back with PR URL + tests-pass.
**When NOT to use n8n dispatch (still spawn subprocess):**
- Quick exploratory recon < 30 seconds
- Tasks needing live tail of agent output (debugging the agent itself)
- When the n8n flow is down (check `docker logs n8n-automation`)
**Verify n8n is live:**
```sh
docker ps --filter name=n8n --format '{{.Status}}'
curl -s http://localhost:5678/healthz # n8n health
tail -20 /var/log/glug-agent-handler.log # last handler invocations
```
**Cost comparison (rough, 2026-05-04):**
- Direct or-agent subprocess via Bash: ~5k Claude tokens for prompt-write + monitoring loops
- Gitea issue + n8n dispatch: ~500 Claude tokens for the issue body
β 10Γ cheaper.
**Reference issues to mimic:** ubuadmin/glug#620, #562, #450 (well-formed agent-tickets).