Skip to content

Commit 055de0a

Browse files
jwaldripclaude
andcommitted
fix: make subagent context hook load state from correct branch
The hook runs in the parent's context, so runtime worktree detection and plan loading were reflecting the parent's state, not the subagent's. Replace with static branch references and a bootstrap section that instructs subagents to load unit-scoped state after entering their own worktree. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bd48be9 commit 055de0a

File tree

1 file changed

+32
-38
lines changed

1 file changed

+32
-38
lines changed

plugin/hooks/subagent-context.sh

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -116,15 +116,6 @@ if [ -f "${INTENT_DIR}/completion-criteria.md" ]; then
116116
echo ""
117117
fi
118118

119-
# Current plan is ephemeral state - keep in han keep
120-
PLAN=$(load_keep_value current-plan.md)
121-
if [ -n "$PLAN" ]; then
122-
echo "### Current Plan"
123-
echo ""
124-
echo "$PLAN"
125-
echo ""
126-
fi
127-
128119
# Display testing requirements if configured (stored in intent.md frontmatter)
129120
if [ -f "$INTENT_FILE" ]; then
130121
TESTING_JSON=$(han parse yaml testing --json < "$INTENT_FILE" 2>/dev/null || echo "")
@@ -238,42 +229,45 @@ echo ""
238229
echo "## AI-DLC Workflow Rules"
239230
echo ""
240231

241-
# Get current branch and working directory
242-
CURRENT_BRANCH=$(git branch --show-current 2>/dev/null || echo "unknown")
243-
CURRENT_DIR=$(pwd)
244-
IS_WORKTREE=$(git rev-parse --is-inside-work-tree 2>/dev/null && [ -f "$(git rev-parse --git-dir)/commondir" ] && echo "yes" || echo "no")
232+
# Branch references for cross-branch state access
233+
echo "### Branch References"
234+
echo ""
235+
echo "- **Intent branch:** \`ai-dlc/${INTENT_SLUG}/main\`"
236+
echo "- **Intent worktree:** \`/tmp/ai-dlc-${INTENT_SLUG}/\`"
237+
echo ""
238+
echo "To access intent-level state from a unit branch:"
239+
echo "\`\`\`bash"
240+
echo "han keep load --branch \"ai-dlc/${INTENT_SLUG}/main\" <key>"
241+
echo "\`\`\`"
242+
echo ""
245243

246-
echo "### Current Working Context"
244+
echo "### Bootstrap (MANDATORY)"
247245
echo ""
248-
echo "- **Branch:** \`${CURRENT_BRANCH}\`"
249-
echo "- **Directory:** \`${CURRENT_DIR}\`"
250-
if [ "$IS_WORKTREE" = "yes" ]; then
251-
echo "- **Worktree:** ✅ Yes (isolated workspace)"
252-
else
253-
echo "- **Worktree:** ⚠️ NO - You should be in a worktree!"
254-
fi
246+
echo "Your spawn prompt tells you which worktree and branch to use."
247+
echo "After entering your unit worktree, load unit-scoped state:"
248+
echo ""
249+
echo "\`\`\`bash"
250+
echo "# Load previous context from your unit branch"
251+
echo "han keep load current-plan.md --quiet 2>/dev/null || true"
252+
echo "han keep load scratchpad.md --quiet 2>/dev/null || true"
253+
echo "han keep load blockers.md --quiet 2>/dev/null || true"
254+
echo "han keep load next-prompt.md --quiet 2>/dev/null || true"
255+
echo "\`\`\`"
256+
echo ""
257+
echo "These are scoped to YOUR branch. Read them to understand prior work on this unit."
255258
echo ""
256259

257-
echo "### Worktree Isolation (MANDATORY)"
260+
echo "### Worktree Isolation"
258261
echo ""
259-
echo "All bolt work MUST happen in an isolated worktree at:"
260-
echo "\`/tmp/ai-dlc-{intent-slug}-{unit-slug}/\`"
262+
echo "All bolt work MUST happen in an isolated worktree."
263+
echo "Working outside a worktree will cause conflicts with the parent session."
261264
echo ""
262-
if [ "$IS_WORKTREE" = "yes" ] && [[ "$CURRENT_BRANCH" == ai-dlc/* ]]; then
263-
echo "✅ You are in the correct worktree on an AI-DLC branch. Continue working here."
264-
elif [[ "$CURRENT_DIR" == /tmp/ai-dlc-* ]]; then
265-
echo "✅ You are in an AI-DLC worktree directory. Continue working here."
266-
else
267-
echo "🛑 **STOP!** You are NOT in a worktree!"
268-
echo ""
269-
echo "Before doing ANY work, you must:"
270-
echo "1. Have the parent create the worktree"
271-
echo "2. cd to the worktree directory"
272-
echo "3. Verify you're on the unit branch"
273-
echo ""
274-
echo "Working outside a worktree will cause conflicts with the parent session."
275-
fi
265+
echo "After entering your worktree, verify:"
266+
echo "1. You are in \`/tmp/ai-dlc-${INTENT_SLUG}-{unit-slug}/\`"
267+
echo "2. You are on the correct unit branch (\`git branch --show-current\`)"
268+
echo "3. You loaded unit-scoped state (see Bootstrap above)"
276269
echo ""
270+
277271
echo "### Before Stopping"
278272
echo ""
279273
echo "1. **Commit changes**: \`git add -A && git commit\`"

0 commit comments

Comments
 (0)