#19621: feat: shared-bootstrap hook for cross-agent bootstrap files
size: M
Cluster:
Hooks Enhancements and Fixes
## Summary
New bundled hook that auto-discovers `SHARED_*.md` files from `<stateDir>/shared/` (default `~/.openclaw/shared/`) and injects them into every agent's Project Context during `agent:bootstrap`.
- **Zero configuration** — no config entries, no schema changes. If the directory exists and contains `SHARED_*.md` files, they're injected.
- **`SHARED_` prefix required** — only files matching `SHARED_*.md` are loaded, preventing confusion with per-workspace bootstrap files.
- **Alphabetical ordering** — files are sorted and appended after workspace bootstrap files for deterministic injection order.
- **No subagent filtering** — shared files appear in every session type (main, subagent, cron). The whole point is universal rules.
- **Strict error handling** — missing directory is silent (feature not in use); unreadable directory or files throw (mismatched expectations if bootstrap proceeds without expected context).
## Motivation
Multi-agent setups need shared rules, personas, and instructions across all agents without duplicating files per workspace. The existing `bootstrap-extra-files` hook restricts files to within the workspace directory and only loads recognized bootstrap basenames. This hook reads from an external well-known path (`STATE_DIR/shared/`) and accepts any `SHARED_`-prefixed `.md` filename.
## Usage
```bash
mkdir -p ~/.openclaw/shared
echo "# Shared Rules" > ~/.openclaw/shared/SHARED_RULES.md
# restart gateway — every agent now gets SHARED_RULES.md in Project Context
```
## Changes
- `src/hooks/bundled/shared-bootstrap/handler.ts` — hook implementation (43 lines)
- `src/hooks/bundled/shared-bootstrap/handler.test.ts` — 9 tests
- `src/hooks/bundled/shared-bootstrap/HOOK.md` — hook metadata and documentation
## Design decisions
- **Auto-discovery over config** — avoids schema modifications and keeps the feature dead simple. No `enabled`/`dir` config knobs.
- **`SHARED_` prefix** — distinguishes shared files from per-workspace bootstrap files at a glance.
- **`as WorkspaceBootstrapFile` cast** — `WorkspaceBootstrapFileName` is a narrow union of known names (`SOUL.md`, `AGENTS.md`, etc.). Shared files use custom names by design. The cast is localized and downstream `.name` usage is display/logging only.
- **ENOENT vs other errors** — `readdir` catches only `ENOENT` (directory doesn't exist = feature not enabled). All other errors (permissions, I/O) propagate as fatal.
Closes #19620
## Test plan
- [x] Does nothing when shared directory does not exist
- [x] Does nothing when directory is empty
- [x] Does nothing when no `SHARED_*.md` files present
- [x] Injects `SHARED_*.md` files from shared directory
- [x] Sorts files alphabetically
- [x] Ignores files without `SHARED_` prefix
- [x] Throws when shared directory exists but is unreadable
- [x] Throws when a matching file cannot be read
- [x] Shared files survive in subagent sessions
<!-- greptile_comment -->
<h3>Greptile Summary</h3>
Adds a zero-config bundled hook that auto-discovers `SHARED_*.md` files from `~/.openclaw/shared/` and injects them into all agent bootstrap contexts. Clean implementation that follows existing bundled hook patterns (`bootstrap-extra-files`) with comprehensive test coverage (9 tests covering all documented behaviors). The type cast from custom `SHARED_*.md` names to `WorkspaceBootstrapFileName` is intentional and safe, as the `.name` field is only used for display/logging and map lookups downstream (verified in `system-prompt-report.ts:56-57`). Files are sorted alphabetically and appended after workspace bootstrap files.
**Key behaviors:**
- Silent no-op when directory doesn't exist (feature not enabled)
- Throws on permission errors (strict error handling as documented)
- Filters to only `SHARED_*.md` files
- No subagent filtering (universal injection by design)
<h3>Confidence Score: 5/5</h3>
- Safe to merge with no concerns
- Well-tested feature with 9 comprehensive tests covering all edge cases. Implementation follows established patterns from `bootstrap-extra-files` hook. Type cast is intentional and safe (documented in PR and code). Error handling is strict and appropriate. Zero-config design eliminates configuration issues.
- No files require special attention
<sub>Last reviewed commit: 42cd842</sub>
<!-- greptile_other_comments_section -->
<!-- /greptile_comment -->
Most Similar PRs
#19879: Feat/foropenclaw bootstrapfiles clean
by akyourowngames · 2026-02-18
78.2%
#11817: fix(build): compile bundled hook handlers into dist
by AnonO6 · 2026-02-08
73.0%
#10591: feat(hooks): add session-start-memory bundled hook
by morningstar-daemon · 2026-02-06
72.4%
#9726: feat: add identityDir config for separate identity file location
by rickburn · 2026-02-05
72.1%
#9677: feat: expose incomingMessage in bootstrap hook context
by speedbal · 2026-02-05
71.6%
#19826: fix: add in-prompt warnings and doctor check for bootstrap file tru...
by akramcodez · 2026-02-18
71.1%
#20267: feat: workspace-aware post-compaction context
by nickjlamb · 2026-02-18
70.5%
#9947: fix: preserve agent-events as standalone entry point for hook consu...
by therealkaiharper-wq · 2026-02-05
70.4%
#16960: perf: skip cache-busting for bundled hooks, use mtime for workspace...
by mudrii · 2026-02-15
70.3%
#9914: fix(hooks): resolve bundled hook dist paths and packaging checks
by zimmra · 2026-02-05
70.3%