#10591: feat(hooks): add session-start-memory bundled hook
stale
## Summary
Adds a new internal hook that loads workspace memory files into session context at agent bootstrap, making memory loading **structural** instead of **optional**.
## Problem
Agents often suffer from "amnesia" - they forget to read their memory files at session start, losing continuity across sessions. Manual memory loading is voluntary and easily skipped.
## Solution
This hook runs at `agent:bootstrap` (before any user messages are processed) and automatically injects workspace memory into session context. Memory loading becomes **unskippable**.
## What It Does
1. **Loads configured paths** - Default: `MEMORY.md`, `memory/continuity-test.md`
2. **Loads recent memory** - Finds `memory/YYYY-MM-DD*.md` files from last N days
3. **Injects into context** - Creates `CURRENT_SESSION_MEMORY.md` in bootstrap files
4. **Runs before first message** - Memory is already loaded before agent processes anything
## Configuration
```json
{
"hooks": {
"internal": {
"entries": {
"session-start-memory": {
"enabled": true,
"paths": ["MEMORY.md", "memory/continuity-test.md"],
"recentDays": 2
}
}
}
}
}
```
| Option | Type | Default | Description |
|--------|------|---------|-------------|
| `paths` | `string[]` | `["MEMORY.md", "memory/continuity-test.md"]` | Files to always load |
| `recentDays` | `number` | `2` | Days of recent memory to load |
## Use Cases
- **Continuity testing** - Load test questions that verify agent remembers recent work
- **Long-term memory** - Inject curated `MEMORY.md` every session
- **Recent context** - Auto-surface last few days of work
- **Session checklists** - Ensure critical context is always present
## Design Decisions
- **Optional by default** - Users opt-in via config
- **Graceful degradation** - Missing files are skipped silently
- **Generic implementation** - Works with any markdown-based memory system
- **No external dependencies** - Pure Node.js fs operations
- **Follows existing patterns** - Matches `session-memory` and `boot-md` structure
## Testing
Tests cover:
- Event type filtering (only runs on `agent:bootstrap`)
- Default path loading
- Recent file discovery and date filtering
- Configuration options (`paths`, `recentDays`)
- Missing file handling
- File sorting (newest-first)
- Edge cases (missing workspace dir, empty memory)
## Related PRs
- #9677 - Exposes `incomingMessage` to bootstrap hooks (complementary)
- #9782 - Adds `session:start`/`session:end` hooks (different scope - command lifecycle)
This PR focuses on making workspace memory loading automatic and structural, solving the amnesia problem for agents that maintain markdown-based memory systems.
<!-- greptile_comment -->
<h2>Greptile Overview</h2>
<h3>Greptile Summary</h3>
- Adds `session-start-memory` bundled internal hook that runs on `agent:bootstrap` and injects a generated `CURRENT_SESSION_MEMORY.md` bootstrap file with content loaded from workspace paths and recent `memory/YYYY-MM-DD*.md` files.
- Introduces Vitest coverage for default paths, recent file discovery/sorting, config overrides, and missing-file scenarios.
- Updates Slack extension read action to pass `threadId` through to runtime Slack handler.
- The hook implementation currently has correctness/security gaps around config enablement, path confinement, and date handling that should be addressed before merge.
<h3>Confidence Score: 2/5</h3>
- This PR should not be merged as-is due to a path traversal risk and config/behavior mismatches in the new bundled hook.
- The new hook reads user-configured paths and joins them directly to `workspaceDir`, allowing `../`/absolute-path reads outside the workspace and injecting their contents into session context. Additionally, the hook ignores its own `enabled` flag (conflicts with the documented disabling behavior) and has timezone-sensitive date filtering that can misclassify recent files. Slack change looks straightforward, but the hook issues are blocking.
- src/hooks/bundled/session-start-memory/handler.ts
<!-- greptile_other_comments_section -->
<sub>(3/5) Reply to the agent's comments like "Can you suggest a fix for this @greptileai?" or ask follow-up questions!</sub>
<!-- /greptile_comment -->
Most Similar PRs
#7091: feat: add pre-answer hooks system for automatic context injection
by dizhaky · 2026-02-02
82.7%
#14243: fix: fire session-memory hook on auto-resets + topic-aware memory p...
by TheDude135 · 2026-02-11
82.2%
#8431: Hooks: add session-graphiti memory feed
by JorgeAlan · 2026-02-04
81.9%
#9026: fix(session-memory): sanitize content to prevent binary data in mem...
by Flamrru · 2026-02-04
80.1%
#6858: feat(hooks): improve session-memory with LLM summarization
by alauppe · 2026-02-02
79.2%
#7301: fix(hooks): use resolveAgentIdFromSessionKey instead of split(":")[0]
by tsukhani · 2026-02-02
78.7%
#8244: feat(hooks): add session:before_compact and session:after_compact i...
by kephail · 2026-02-03
78.6%
#19565: feat: add agent lifecycle hook events (session, message, error)
by tag-assistant · 2026-02-17
78.4%
#9726: feat: add identityDir config for separate identity file location
by rickburn · 2026-02-05
78.3%
#20706: feat(hooks): add outputDir config for session-memory hook
by botBehavior · 2026-02-19
77.8%