---
description: Show task-focused context usage
---

# Task-Focused Context Usage

## Phase 0: Task Validation (MANDATORY)

### Check Current Task

!`CURRENT_TASK=$(find @backlog/tasks -name "review.md" -newer @backlog/tasks/*/prd.md -exec grep -l "What Changed:" {} \; | head -1 | xargs dirname | basename 2>/dev/null)`
!`if [ -z "$CURRENT_TASK" ]; then echo "ERROR: No active task found. Context analysis requires task context"; exit 1; fi`

### Load Task Context

!`TASK_DIR="@backlog/tasks/$CURRENT_TASK"`
!`echo "=== CONTEXT ANALYSIS FOR TASK ==="`
!`echo "Task ID: $CURRENT_TASK"`
!`echo "Task Goal: $(grep -A 3 'Goal:' "$TASK_DIR/prd.md" | tail -2)"`

## Phase 1: Task-Bounded Context Analysis

### Analyze Context Within Task Scope

**Analysis Focus:** [From PRD goal of task $CURRENT_TASK]
**Analysis Boundaries:** [From PRD scope of task $CURRENT_TASK]
**Analysis Constraints:** [From spec constraints of task $CURRENT_TASK]

### Context Usage Analysis

!`context_usage`

### Task-Focused Insights:

- **Relevance to task**: How does this context serve task $CURRENT_TASK?
- **Scope compliance**: Is this context within PRD boundaries?
- **Constraint alignment**: Does this respect spec constraints?
- **Efficiency**: Is this context essential for task completion?

## Phase 2: Task Context Validation

### Context Compliance Check:

- [ ] Context usage relates to task $CURRENT_TASK
- [ ] No off-task context consumption detected
- [ ] Token usage aligns with task requirements
- [ ] Context boundaries are respected

### Wasteful Context Indicators:

- ❌ Context unrelated to task goal
- ❌ Tokens used outside task scope
- ❌ General exploration instead of task-focused work
- ❌ Excessive context for simple task

## Phase 3: Task-Optimized Recommendations

### Context Optimization for Task $CURRENT_TASK:

1. **Reduce off-task context**: Limit to task-relevant tools
2. **Focus on task constraints**: Prioritize PRD+spec context
3. **Minimize exploration**: Use only essential research for task
4. **Task-bound tokens**: Ensure context serves task success criteria

### Efficiency Actions:

```
If context usage is wasteful for task $CURRENT_TASK:
- Reduce tool usage to task-essential only
- Focus on $TASK_DIR/prd.md and $TASK_DIR/spec.md
- Avoid general exploration
- Prioritize task completion over broad analysis
```

## Phase 4: Task Context Summary

### Task-Focused Context Report:

**Task**: $CURRENT_TASK
**Goal**: [From task PRD]
**Context Efficiency**: [Based on task relevance]
**Optimization Needed**: [If wasteful usage detected]

### Next Actions:

- If context efficient: Continue task work
- If context wasteful: Refocus on task boundaries
- Always validate: Does this context serve task $CURRENT_TASK?

---

**ANTI-HALLUCINATION: Context usage must serve task constraints, not general analysis**
