$3a
This skill reads a Product Requirements Document (PRD) and scaffolds or updates a workspace for long-running autonomous AI coding using the "artifacts over context compaction" methodology (inspired by SamuelQZQ's auto-coding-agent-demo and Anthropic's "Effective Harnesses for Long-Running Agents").
Instead of relying on LLM context compression to remember state across sessions, this methodology uses environment artifacts:
CLAUDE.md — fixed workflow rules (system prompt)task.json — structured task list (single source of truth)progress.txt — human-readable session logsinit.sh — standardized environment recoverygit commit — code change historyEach new Claude Code session starts with a clean context window, reads these artifacts, and completes exactly one task.
The user should provide:
If the user does not explicitly provide both, ask for the PRD path before proceeding.
Before starting, check if the target directory already exists and contains a valid agent workspace (look for CLAUDE.md, task.json, init.sh).
Report which mode was detected to the user.
Read the PRD file thoroughly. Extract:
Based on the PRD, determine the primary stack. Use these signals:
Store this decision; it will shape init.sh, CLAUDE.md, and directory structure.
Create the target directory and subdirectories based on the stack. Typical structure:
Python backend:
project-name/
├── api/
├── core/
├── notify/
├── storage/
├── utils/
├── data/
└── tests/
Next.js full-stack:
project-name/
├── src/
│ ├── app/
│ ├── components/
│ └── lib/
├── supabase/
└── tests/
Generic:
project-name/
├── src/
├── tests/
└── docs/
Create empty __init__.py or index.ts placeholder files as needed.
architecture.mdWrite a comprehensive architecture document. Each section must contain specific content, not just a heading:
Project Overview — 1-2 sentences: what the product does, who the target users are, and what problem it solves.
Tech Stack Table — Use a markdown table: | Layer | Technology | Purpose |
System Architecture Diagram — Mermaid flowchart showing the complete data flow: Frontend → Backend → Database → External Services. Include all components mentioned in the PRD.
Core Business Process Diagrams — At least one Mermaid flowchart for the primary user journey (e.g., user registration → create item → process → result). Cover the main use case from the PRD.
Data Model — Mermaid ER diagram showing entity relationships. Follow with a table for each entity: | Field | Type | Constraints | Description |
API Design — Table: | Method | Path | Description | Request Body | Response Body |. Include authentication requirements if mentioned in PRD.
External Service Integration — For each external API: endpoint URL pattern, auth method, a concrete request example, and expected response example. Use placeholders like your_api_key_here for sensitive data.
Configuration Design — Table: | Config Key | Description | Default | Required |. Include all env vars from .env.example.
Notification / Message Templates — If the PRD mentions notifications (webhooks, emails, IM), include the exact message template format with placeholders.
Use concrete details from the PRD. Do not make up endpoint URLs or API keys unless the PRD provides them.
task.jsonConvert the PRD feature list into 5–15 executable tasks, ordered by dependency:
Each task must be a JSON object:
{
"id": 1,
"title": " concise task title",
"description": "what this task accomplishes",
"steps": [
"specific verifiable step 1",
"specific verifiable step 2",
"specific verifiable step 3"
],
"passes": false
}
Task granularity rules:
Rules:
steps should be concrete enough that an AI agent can verify thempasses is always false initiallyCLAUDE.mdThis is the Agent Workflow Bible. It must include:
Project Context — one-line summary
Mandatory Agent Workflow — 6 steps:
./init.sh)task.json, passes: false)progress.txtBlocking Issues Section — Detailed rules for when an Agent must STOP and ask for human help. This is critical for preventing wasted API tokens and incorrect commits.
Must include ALL of the following subsections:
a. Blocking Scenarios (when to stop): List at least these 4 scenarios:
.env not filled, external service accounts not created, database not initializedb. DO NOT / DO rules:
**DO NOT (禁止):**
- ❌ Submit a git commit
- ❌ Set task.json passes to true
- ❌ Pretend the task is complete
- ❌ Skip the failing step and move to the next one
**DO (必须):**
- ✅ Record current progress and blocking reason in `progress.txt`
- ✅ Output a clear blocking message explaining what human help is needed
- ✅ STOP the task and wait for human intervention
- ✅ Preserve all code changes in the working directory (do not revert)
c. Blocking message format (强制模板): The Agent must output blocking information in this exact format:
🚫 任务阻塞 - 需要人工介入
**当前任务**: [task title from task.json]
**已完成的工作**:
- [completed code/config]
**阻塞原因**:
- [specific reason why cannot continue]
**需要人工帮助**:
1. [specific step 1]
2. [specific step 2]
...
**解除阻塞后**:
- 运行 [command] 继续任务
d. progress.txt logging requirement:
When blocked, the Agent must also append to progress.txt:
## [Date] - BLOCKED: [task title]
**Blocked at step**: [which step in the task]
**Reason**: [blocking reason]
**Completed before block**: [what was done]
**Needs human**: [what human needs to do]
Project Structure — directory map
Commands — stack-specific dev/test/build commands
Coding Conventions — at least 3-5 specific rules (naming, file organization, error handling, logging)
Key Rules — one task per session, test before commit, never remove tasks
New Session Onboarding — If you are a NEW Claude Code session with no prior conversation history, read this file first, then task.json, then progress.txt, then run git log --oneline -20
Tailor testing commands to the detected tech stack:
python -m pytest tests/, python -m py_compile, ruff check ., mypynpm run lint, npm run build, npm test, browser tests with Playwrightgo test ./..., go build, go vet./mvnw test, ./mvnw compileinit.shWrite a bash script that:
.env and warns if missingMake init.sh executable (chmod +x init.sh).
Read the bundled templates from assets/run-automation.sh.template and assets/run-automation.ps1.template. Adapt them for the current project by replacing ALL placeholders:
[PROJECT_NAME] with the actual product name from the PRD[TEST_COMMANDS] with stack-specific test commands (e.g., python -m pytest tests/ for Python, npm test for Node.js, go test ./... for Go)Save both files to the target directory and make run-automation.sh executable.
.env.example
README.md
./init.sh, configure .env, start development)QUICKSTART.md
./init.sh → cp .env.example .env → git init → start agent workflow.\run-automation.ps1 -Runs 10./run-automation.sh 10TECH-NOTES.md
CLAUDE.md, task.json, progress.txt, githttps://github.com/SamuelQZQ/auto-coding-agent-demohttps://www.anthropic.com/engineering/effective-harnesses-for-long-running-agentsnext-task.txt (required for Semi-Auto and Full-Auto modes)
A minimal prompt file used by claude -p. Must follow the single-source principle: do not repeat rules from CLAUDE.md, only reference them.
你正在启动一个全新的 Claude Code session,没有任何历史上下文。
请严格按以下顺序执行:
1. 读取 CLAUDE.md — 这是你的工作流圣经,包含完整的文件读取顺序、任务执行步骤和阻塞处理规则
2. 按照 CLAUDE.md 中的工作流,完成 task.json 中下一个 passes: false 的任务
3. 每次只完成一个任务,然后停止
⚠️ 不要假设任何历史上下文。所有项目状态都在文件中。
progress.txt
# Progress Logmain.py / index.ts / main.go stub
config.py / config.ts / config.go stub
Create a zip archive of the target directory, excluding any virtual environments or cache files.
Report the final file path to the user.
If an existing agent workspace is detected (contains CLAUDE.md, task.json, init.sh), follow these steps instead of creating from scratch.
Read the current files to understand what's already done:
task.json — note which tasks have passes: true vs passes: falseprogress.txt — understand development historyarchitecture.md — understand current architectureCLAUDE.md — understand existing workflow rulesRead the new PRD and identify what's new or changed compared to the existing workspace:
task.jsonDO NOT modify tasks that are already passes: true. Those are considered completed.
Update task.json following these rules:
passes statuspasses: false even if they were previously passes: trueExample merge:
{
"project": "My Project",
"tasks": [
// Existing tasks preserved
{ "id": 1, "title": "Scaffold", ..., "passes": true },
{ "id": 2, "title": "Auth", ..., "passes": true },
{ "id": 3, "title": "Old Feature", ..., "passes": false },
// NEW tasks appended
{ "id": 4, "title": "New Feature from PRD", ..., "passes": false },
{ "id": 5, "title": "Another New Feature", ..., "passes": false }
]
}
Only update files that are affected by the PRD changes:
architecture.md — add new components, APIs, data modelsCLAUDE.md — update if tech stack or testing commands changedinit.sh — add new dependencies if needed.env.example — add new environment variablesREADME.md — update feature listQUICKSTART.md — update if workflow changedprogress.txt — append a note: ## [Date] - PRD Update: [description]Do NOT touch run-automation.sh, run-automation.ps1, or TECH-NOTES.md unless their content is directly affected.
Whether in Create Mode or Update Mode, after all files are generated or updated, DO NOT start executing tasks automatically. First perform pre-execution checks, then use the AskUserQuestion tool to let the user choose a mode.
Before presenting choices, verify:
next-task.txt exists in the target directory.env file exists (if not, warn: "请先运行 cp .env.example .env 并填写配置")Question: Agent Workspace Ready — 选择开发模式
Options:
Manual Mode(推荐前 1-2 个任务)
交互式 session,每个工具调用都需确认。适合验证 Agent 是否理解项目。claude\n然后输入: "请按照 CLAUDE.md 完成下一个任务。"Semi-Auto Mode(跑顺后推荐)
非交互式,每次运行一个 task 后自动退出,下次再手动触发。上下文干净。claude -p --dangerously-skip-permissions < next-task.txtFull-Auto Mode(人离开时用)
脚本自动循环 N 次,每次启动全新 Claude Code 进程。Linux/macOS/Git Bash: ./run-automation.sh 10\nWindows PowerShell: .\run-automation.ps1 -Runs 10If user selects Manual Mode:
运行 claude,然后输入:"请按照 CLAUDE.md 中的工作流,完成 task.json 中的下一个任务。"claude yourself. The user must start it manually.If user selects Semi-Auto Mode:
next-task.txt exists in the project directory.现在立即执行第一个 task?
cd [project-dir] && claude -p --dangerously-skip-permissions < next-task.txt
claude -p finishes (one task completes and exits).task.json to check if passes flipped to true.If user selects Full-Auto Mode:
现在立即启动自动化循环(默认 10 次)?
cd [project-dir] && ./run-automation.sh 10 (or . un-automation.ps1 -Runs 10 on Windows)
Before finishing, verify that the target directory contains:
architecture.mdtask.json (valid JSON, 5–15 tasks for create mode; properly merged for update mode)CLAUDE.mdinit.sh (executable)run-automation.sh (executable)run-automation.ps1.env.exampleREADME.mdQUICKSTART.mdTECH-NOTES.mdprogress.txtnext-task.txtyour_api_key_here.