# Stage 5: Coding

## Purpose

Workers execute tasks from Planning 3. Each worker gets a focused context packet and stays in their lane.

## Input

- Task file with context packet, acceptance criteria, constraints
- Specialist subagents loaded (reviewer, security-auditor, language specialist)

## Composition — PER TASK

| Worker Type     | When Used                                     |
| --------------- | --------------------------------------------- |
| Codex           | Primary workhorse — most implementation tasks |
| Claude (Sonnet) | Complex tasks requiring more reasoning        |

Workers are spawned per task with:

- The task's context packet injected as instructions
- Relevant Codex subagents (`.toml`) loaded in `~/.codex/agents/`
- Git worktree at `~/src/<repo>-worktrees/<task-slug>`

## Rails

Workers MUST:

- Work only on files listed in their context packet
- Follow patterns specified in the implementation spec
- NOT make architectural decisions — those were made in Planning 1-2
- NOT refactor unrelated code — stay on task
- Push to a feature branch, open a PR
- NEVER merge

Workers MUST NOT:

- Edit files outside their write scope
- Introduce new dependencies without spec approval
- Change API contracts without spec approval
- Skip tests defined in acceptance criteria

## Output

- Feature branch with implementation
- PR opened against main
- Self-check: "Did I meet all acceptance criteria?"

## Gate: code-complete

### Mechanical

- [ ] Branch exists with commits
- [ ] PR is open
- [ ] Code compiles / typechecks
- [ ] Lint passes
- [ ] Unit tests pass
- [ ] No files edited outside write scope

### Gate Reviewer

- "Does the code match the implementation spec? Did the worker stay on the rails?"
