🤝 handoff — Bidirectional Agent Handoff & Session Resumption Engine
Aliases: agent-handoff | subagent-handoff | context-packet | resume | where-were-we
handoff provides bidirectional context continuity across agent lifecycles:
- Inbound Resumption: Resumes previous agent sessions with boundary-safe directory matching, leading with any unanswered open questions.
- Outbound Dispatch: Generates lean, bounded context packets before dispatching subagents or stepping away.
When to Use
Mode A: Inbound Session Resumption
- User asks: "where were we", "resume", "pick up where I left off", "what was I doing", or begins a session with no fresh prompt.
- Restoring state after an interruption or machine restart.
Mode B: Outbound Subagent Dispatch
- Before dispatching any subagent for backend, frontend, testing, or refactoring.
- Before spawning multi-agent teams or worker processes.
- Before stepping away from a long-running session (>30 minutes).
- Whenever a task prompt to another agent exceeds 3 sentences.
Quick Reference
Inbound vs Outbound Comparison
| Capability |
Inbound Resumption Mode |
Outbound Dispatch Mode |
| Trigger |
"where were we", "resume" |
"dispatch worker", "handoff to subagent" |
| Matching Rule |
Strict directory-boundary matching (=== or startsWith(cwd + sep)) |
Explicit destination file and line range scope |
| First Output |
Unanswered user question (if any) |
Single 1-sentence actionable objective |
| Persistence |
Session memory / .agents/artifacts/ |
.agents/artifacts/handoff-<timestamp>.md |
| Closing Token |
Concrete atomic next-step pointer |
Deterministic verification command |
Procedures
🔄 Mode A: Inbound Session Resumption Procedure
- Resolve Workspace Directory:
Normalize the current working directory. If a directory override argument is provided, resolve to an absolute path.
- Retrieve Prior Session:
Query session history (via MCP memory tools
memory_sessions / memory_recall or inspect .agents/artifacts/ and .agents/context/current.md).
- Surface Unanswered Questions FIRST:
If the prior session ended on an unanswered user question (
?), highlight it at the very top of your response. Do not guess the answer.
- Format Resumption Summary:
Resuming [session_id] "[session_title]".
❓ Open Question from Last Session:
[Unanswered question, if present]
📌 State Summary:
- Key decisions & modified files
- Active roadblocks
👉 Immediate Next Step:
[Single concrete atomic action]
📦 Mode B: Outbound Subagent Dispatch Procedure
- Extract Operational Facts:
- Objective: Exact 1-sentence goal starting with an imperative verb.
- Decisions Made: Irreversible choices not to be re-litigated.
- Ruled-Out Paths: Approaches tried and eliminated with failure reasons.
- Target Scope: Exact files to touch.
- Hard Constraints: Forbidden files, libraries, or credentials (
MUST NOT).
- Deterministic Verification: Exact test or build command.
- If Blocked: Escalation fallback.
- Write Handoff Packet:
Save to
.agents/artifacts/handoff-<timestamp>.md:
# Agent Handoff — <ISO timestamp>
## Objective
[One sentence starting with an imperative verb.]
## Context the Subagent Needs
- [Key architectural decision, API behavior, or business rule]
- [Runtime invariant not obvious from static source]
## Already Tried — Do NOT Re-Attempt
- [Approach A]: [Exact failure reason]
- [Approach B]: [Exact failure reason]
## Files to Touch
- `path/to/file.ts` — [Exact modification]
## Hard Constraints
- [MUST NOT]: [Forbidden scope, .env, credentials, or prohibited library]
## Success Criterion
- [ ] [Verifiable command — test passes, build succeeds, HTTP 200]
## If Blocked
[Explicit fallback action — emit dead-letter record, escalate with finding.]
- Echo & Dispatch:
Embed packet directly into the subagent invocation prompt.
Pitfalls
- Raw Prefix Collisions: Never match session directories using raw
startsWith(path); sibling directories like /project-staging will falsely match /project.
- Hiding Open Questions: Never bury an unanswered user question under a wall of status logs.
- Compound Objectives: Never combine multiple decoupled tasks into one outbound packet.
- Omitted Ruled-Out Paths: Subagents re-explore failed attempts unless explicitly forbidden.
Verification
1---2name: handoff3description: Bidirectional agent handoff and session resumption engine. Resume previous agent sessions with strict directory-boundary matching and unanswered questions leading, or generate structured outbound context packets before dispatching subagents.4license: MIT5---67# 🤝 handoff — Bidirectional Agent Handoff & Session Resumption Engine89> **Aliases**: `agent-handoff` | `subagent-handoff` | `context-packet` | `resume` | `where-were-we`1011`handoff` provides bidirectional context continuity across agent lifecycles:121. **Inbound Resumption**: Resumes previous agent sessions with boundary-safe directory matching, leading with any unanswered open questions.132. **Outbound Dispatch**: Generates lean, bounded context packets before dispatching subagents or stepping away.1415---1617## When to Use1819### Mode A: Inbound Session Resumption20- User asks: *"where were we"*, *"resume"*, *"pick up where I left off"*, *"what was I doing"*, or begins a session with no fresh prompt.21- Restoring state after an interruption or machine restart.2223### Mode B: Outbound Subagent Dispatch24- Before dispatching any subagent for backend, frontend, testing, or refactoring.25- Before spawning multi-agent teams or worker processes.26- Before stepping away from a long-running session (>30 minutes).27- Whenever a task prompt to another agent exceeds 3 sentences.2829---3031## Quick Reference3233### Inbound vs Outbound Comparison3435| Capability | Inbound Resumption Mode | Outbound Dispatch Mode |36|:---|:---|:---|37| **Trigger** | *"where were we"*, *"resume"* | *"dispatch worker"*, *"handoff to subagent"* |38| **Matching Rule** | Strict directory-boundary matching (`===` or `startsWith(cwd + sep)`) | Explicit destination file and line range scope |39| **First Output** | Unanswered user question (if any) | Single 1-sentence actionable objective |40| **Persistence** | Session memory / `.agents/artifacts/` | `.agents/artifacts/handoff-<timestamp>.md` |41| **Closing Token** | Concrete atomic next-step pointer | Deterministic verification command |4243---4445## Procedures4647### 🔄 Mode A: Inbound Session Resumption Procedure48491. **Resolve Workspace Directory**:50 Normalize the current working directory. If a directory override argument is provided, resolve to an absolute path.512. **Retrieve Prior Session**:52 Query session history (via MCP memory tools `memory_sessions` / `memory_recall` or inspect `.agents/artifacts/` and `.agents/context/current.md`).53 - **Enforce Directory-Boundary Isolation**:54 ```ts55 // Prohibit raw prefix matching to prevent sibling repo bleed:56 session.cwd === projectPath || session.cwd.startsWith(projectPath + path.sep)57 ```583. **Surface Unanswered Questions FIRST**:59 If the prior session ended on an unanswered user question (`?`), highlight it at the very top of your response. Do not guess the answer.604. **Format Resumption Summary**:61 ```text62 Resuming [session_id] "[session_title]".6364 ❓ Open Question from Last Session:65 [Unanswered question, if present]6667 📌 State Summary:68 - Key decisions & modified files69 - Active roadblocks7071 👉 Immediate Next Step:72 [Single concrete atomic action]73 ```7475---7677### 📦 Mode B: Outbound Subagent Dispatch Procedure78791. **Extract Operational Facts**:80 - **Objective**: Exact 1-sentence goal starting with an imperative verb.81 - **Decisions Made**: Irreversible choices not to be re-litigated.82 - **Ruled-Out Paths**: Approaches tried and eliminated with failure reasons.83 - **Target Scope**: Exact files to touch.84 - **Hard Constraints**: Forbidden files, libraries, or credentials (`MUST NOT`).85 - **Deterministic Verification**: Exact test or build command.86 - **If Blocked**: Escalation fallback.872. **Write Handoff Packet**:88 Save to `.agents/artifacts/handoff-<timestamp>.md`:8990```markdown91# Agent Handoff — <ISO timestamp>9293## Objective94[One sentence starting with an imperative verb.]9596## Context the Subagent Needs97- [Key architectural decision, API behavior, or business rule]98- [Runtime invariant not obvious from static source]99100## Already Tried — Do NOT Re-Attempt101- [Approach A]: [Exact failure reason]102- [Approach B]: [Exact failure reason]103104## Files to Touch105- `path/to/file.ts` — [Exact modification]106107## Hard Constraints108- [MUST NOT]: [Forbidden scope, .env, credentials, or prohibited library]109110## Success Criterion111- [ ] [Verifiable command — test passes, build succeeds, HTTP 200]112113## If Blocked114[Explicit fallback action — emit dead-letter record, escalate with finding.]115```1161173. **Echo & Dispatch**:118 Embed packet directly into the subagent invocation prompt.119120---121122## Pitfalls123124- **Raw Prefix Collisions**: Never match session directories using raw `startsWith(path)`; sibling directories like `/project-staging` will falsely match `/project`.125- **Hiding Open Questions**: Never bury an unanswered user question under a wall of status logs.126- **Compound Objectives**: Never combine multiple decoupled tasks into one outbound packet.127- **Omitted Ruled-Out Paths**: Subagents re-explore failed attempts unless explicitly forbidden.128129---130131## Verification132133- [ ] Inbound resumption surfaces any unanswered question before status text.134- [ ] Session matching strictly validates directory boundaries.135- [ ] Outbound handoff packet is written to `.agents/artifacts/handoff-<timestamp>.md`.136- [ ] All 7 outbound sections are populated with zero placeholder text.