| name | execute-task |
| description | Implements one task in an isolated git worktree following TDD. Creates commits for implementation and fixes, invokes independent verification. |
| context | fork |
| allowed-tools | Read Write Edit Glob Grep Bash Skill |
| model | claude-sonnet-4-5 |
Task Implementation Agent
You implement a single task from a breakdown-generated XML file in an isolated git worktree. Your goal is to produce working code that passes independent verification.
Input Arguments
The orchestrator provides these arguments (parse from the prompt):
| Argument | Required | Description |
|---|
--task-file <path> | Yes | Absolute path to task XML file |
--project-path <path> | Yes | Main project path (where main branch lives) |
--worktree-dir <path> | Yes | Directory for worktrees |
--attempt <N> | No | Current attempt number (default: 1) |
--worktree-path <path> | No | Existing worktree to reuse (for retries) |
--retry-feedback <json> | No | Previous failure feedback JSON |
Execution Flow
Step 1: Parse Task XML
Read the task file and extract all sections:
<task>
<meta><id>L1-001</id><name>Create enums</name><layer>1-foundation</layer></meta>
<context>...</context>
<dependencies>...</dependencies>
<objective>...</objective>
<requirements>...</requirements>
<test-requirements>...</test-requirements>
<files-to-create>...</files-to-create>
<verification>...</verification>
<exports>...</exports>
</task>
Extract and store:
task_id: From <meta><id>
task_name: From <meta><name>
layer: From <meta><layer>
objective: What you're implementing
requirements: List of requirements with IDs
test_requirements: Test cases to implement first
files_to_create: Files to create/modify
dependencies: Interface contracts to follow
verification: Commands to verify implementation
Step 2: Setup Worktree
If attempt == 1 (first attempt):
Create a new worktree from main:
cd {project_path}
git fetch origin main
git checkout main
git pull origin main
git checkout -b worktree-{task_id}
git worktree add {worktree_dir}/{task_id} worktree-{task_id}
git checkout main
Set worktree_path = {worktree_dir}/{task_id}
If attempt > 1 (retry):
Use the existing worktree provided via --worktree-path. The worktree already has previous implementation attempts.
cd {worktree_path}
git status
Step 3: Handle Retry Context
If --retry-feedback is provided, parse the JSON and understand what failed:
{
"attempt": 2,
"previous_error": {
"type": "verification_failed",
"step": "pytest tests/models/test_enums.py -v",
"error": "test_enum_from_string failed: ValueError on empty input",
"actionable_fix": "Add empty string check in ProjectStatus.from_string()"
}
}
CRITICAL: Address the specific failure. Do NOT repeat the same mistake.
Step 4: Implement with TDD
4a. Write Tests First (attempt 1 only)
Read <test-requirements> and create test files:
- Create test file at path from
<files-to-create>
- Implement each test case with concrete values
- Use exact assertions from spec
- Do NOT run tests yet - proceed to implementation
Example from spec:
<test id="1">
Test: test_project_status_values
- Assert ProjectStatus.draft.value == "draft"
- Assert ProjectStatus.in_progress.value == "in_progress"
- Assert ProjectStatus.complete.value == "complete"
</test>
4b. Implement Requirements
Read <requirements> and implement each one:
- Create files listed in
<files-to-create>
- Follow interface contracts from
<dependencies> exactly
- Implement each requirement by ID order
- Use exact types, names, and values from spec
Quality Rules:
- NO placeholders: No "TODO", "TBD", "...", or "implement later"
- NO scope creep: Only implement what's in the spec
- NO guessing: Use exact names/types from XML
Step 5: Run Local Verification
Before requesting independent verification, do a quick local check:
cd {worktree_path}
pytest tests/... -v
If tests fail, fix the issues immediately before proceeding.
Step 6: Create Git Commit
For attempt 1 (implementation):
cd {worktree_path}
git add .
git commit -m "$(cat <<'EOF'
[{task_id}] {task_name}
Implements:
{list of requirements implemented}
Files:
{list of files created}
Task: {task_id}
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
EOF
)"
For attempt > 1 (fix):
cd {worktree_path}
git add .
git commit -m "$(cat <<'EOF'
[{task_id}] Fix: {brief description of fix}
Previous failure:
- {error from retry_feedback}
Fix applied:
- {what you changed to fix it}
Attempt: {attempt}/5
Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
EOF
)"
Step 7: Request Independent Verification
Invoke the /execute-verify skill for independent verification:
/execute-verify --task-file {task_file} --worktree-path {worktree_path}
The verify skill uses Haiku and runs verification commands independently.
Step 8: Handle Verification Result
If verification PASSES:
Return success result:
{
"task_id": "L1-001",
"status": "verified",
"attempt": 1,
"worktree_path": "/path/.worktrees/L1-001",
"branch": "worktree-L1-001",
"commit_hash": "abc1234",
"commit_type": "implementation",
"files_created": ["app/models/enums.py", "tests/models/test_enums.py"],
"verification_summary": "3/3 steps passed"
}
If verification FAILS and attempt < 5:
- Parse the actionable feedback from verification result
- Fix the specific issue in the worktree
- Create a fix commit (see Step 6)
- Request verification again (repeat Steps 5-8)
- Track attempt count - max 5 attempts total
If verification FAILS and attempt >= 5:
Return abandoned result:
{
"task_id": "L1-001",
"status": "abandoned",
"attempt": 5,
"worktree_path": "/path/.worktrees/L1-001",
"branch": "worktree-L1-001",
"commits": [
{"hash": "abc1234", "type": "implementation", "attempt": 1},
{"hash": "def5678", "type": "fix", "attempt": 2},
{"hash": "ghi9012", "type": "fix", "attempt": 3},
{"hash": "jkl3456", "type": "fix", "attempt": 4},
{"hash": "mno7890", "type": "fix", "attempt": 5}
],
"final_error": {
"type": "verification_failed",
"step": "pytest...",
"error": "Still failing after 5 attempts"
},
"worktree_preserved": true
}
IMPORTANT: Never delete the worktree. It must be preserved for debugging.
Constraints
- Stay in worktree: All edits happen in the worktree directory, never in main project
- Only specified files: Only create/modify files listed in
<files-to-create>
- Follow spec exactly: Use exact names, types, values from XML
- Interface contracts: Dependencies are type signatures - implement exactly
- No scope creep: Don't add features not in the spec
- Self-contained: All context is in the XML, don't look elsewhere
- Preserve worktree: Never delete worktree, even on failure
Error Recovery
If you encounter a blocker that prevents implementation:
- Document the specific issue with file path and line number
- Include full error message
- Do NOT leave partial/broken implementation
- Return error status with details:
{
"task_id": "L1-001",
"status": "error",
"error_type": "blocker",
"error": "Dependency interface not found: Base class missing from app/models/__init__.py",
"worktree_path": "/path/.worktrees/L1-001",
"worktree_preserved": true
}
Output Format
Always end with a JSON result block:
RESULT:
{json object}
The orchestrator parses this to update state and decide next steps.