v5.4.2 (2025-11-10)
Bugfix Release: CWD spatial awareness for SDK agent
What's Fixed
- CWD Context Propagation: SDK agent now receives current working directory (CWD) context from tool executions
- Spatial Awareness: Prevents false "file not found" reports when working across multiple repositories
- Observer Guidance: Agent prompts now include tool_cwd XML elements with spatial awareness instructions
Technical Details
Data Flow:
- Hook extracts CWD from PostToolUseInput (
hookInput.result.tool_cwd) - Worker service receives CWD in PendingMessage and ObservationData interfaces
- SessionManager passes CWD to SDKAgent's addObservation method
- SDK agent includes CWD in tool observation objects sent to Claude API
- Prompts conditionally render tool_cwd XML with spatial awareness guidance
Implementation:
- Optional CWD fields throughout for backward compatibility
- Defaults to empty string when CWD is missing
- CWD treated as read-only display context, not for file operations
- Complete propagation chain from hook → worker → SDK → prompts
Test Coverage:
- 8 comprehensive tests validating CWD propagation
- Tests cover hook extraction, worker forwarding, SDK inclusion, and prompt rendering
- All tests pass with tsx TypeScript loader
Security:
- Zero vulnerabilities introduced
- CodeQL analysis: No alerts
- Read-only context display (no file operation changes)
- Input validation and sanitization maintained
Files Changed
Source Files:
src/hooks/save-hook.ts- Extract CWD from PostToolUseInputsrc/services/worker-types.ts- Add optional CWD fields to interfacessrc/services/worker-service.ts- Forward CWD in message handlingsrc/services/worker/SessionManager.ts- Pass CWD to SDK agentsrc/services/worker/SDKAgent.ts- Include CWD in tool observationssrc/sdk/prompts.ts- Render tool_cwd XML with spatial guidance
Built Artifacts:
plugin/scripts/save-hook.js- Compiled hook with CWD extractionplugin/scripts/worker-service.cjs- Compiled worker with CWD handling
Tests & Documentation:
tests/cwd-propagation.test.ts- Comprehensive test suite (8 tests)context/CWD_CONTEXT_FIX.md- Technical implementation documentationPR_SUMMARY.md- Pull request summary and rationaleSECURITY_SUMMARY.md- Security analysis and reviewCHANGELOG.md- Version history entry
Installation
# Update to latest version
/plugin update claude-memOr restart Claude Code to auto-update.
Upgrade Notes
- Backward Compatible: No breaking changes
- No Action Required: CWD propagation works automatically
- Existing Sessions: Will benefit from improved spatial awareness
Full Changelog: v5.4.1...v5.4.2