8 Commits

Author SHA1 Message Date
Alex Newman c27f07023c fix: Remove all session validation to prevent continuation errors after /exit
Root cause: Hooks provide session_id as the source of truth. We were adding
unnecessary validation (checking if sessions exist, checking status, etc.)
which caused 409 conflicts when continuing sessions after /exit.

Changes:
1. worker-service.ts: Removed 409 "Session already exists" check in handleInit
2. SessionStore.ts: Made createSDKSession idempotent using INSERT OR IGNORE
3. new-hook.ts: Simplified to just call createSDKSession - no findActiveSDKSession,
   no reactivateSession logic, no status management
4. save-hook.ts: Removed session validation, use fixed port instead of session.worker_port
5. summary-hook.ts: Removed session validation, use fixed port instead of session.worker_port

Philosophy: Hooks manage lifecycle, we just save data with whatever session_id
they give us. No validation, no status checks, no guessing.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-10-21 21:44:58 -04:00
Alex Newman 874815770a fix: Add missing process.exit(0) calls in hook entry points
All 4 hook entry point scripts were missing process.exit(0) after successful
execution, causing Node processes to hang indefinitely instead of returning
control to Claude Code with exit code 0.

Root cause: In commit 6f62a56, process.exit(0) calls were removed from the
hook functions but were never added to the entry point scripts that wrap them.

Fixed files:
- src/bin/hooks/save-hook.ts (PostToolUse)
- src/bin/hooks/new-hook.ts (UserPromptSubmit)
- src/bin/hooks/summary-hook.ts (Stop)
- src/bin/hooks/context-hook.ts (SessionStart)

This restores proper hook exit behavior and prevents Claude Code from waiting
indefinitely for hook completion.
2025-10-18 18:49:11 -04:00
Alex Newman 3e617a8b1e Refactor code structure for improved readability and maintainability 2025-10-16 19:50:24 -04:00
Alex Newman 834cf4095e Add standalone hook entry points for context, new, save, summary, and worker
- Implemented context-hook.ts for handling session start events.
- Created new-hook.ts for user prompt submission events.
- Developed save-hook.ts for post tool use events.
- Added summary-hook.ts for handling stop events.
- Introduced worker.ts as a standalone background process for the SDK agent.
- Each hook reads input from stdin, processes it, and handles errors gracefully.
2025-10-16 15:39:30 -04:00
Alex Newman 58a9554bb3 feat: Complete Phase 1 implementation with database schema, shared layer, and hook functions
- Created new tables for SDK sessions and observations
- Implemented HooksDatabase for CRUD operations
- Developed four hook functions: context, new, save, and summary
- Added CLI commands for each hook
- Established comprehensive test suite with all tests passing

feat: Complete Phase 2 implementation with SDK worker process and XML parsing

- Developed SDK prompts for initializing and processing observations
- Implemented XML parser for SDK responses
- Created SDK worker process to handle background observation processing
- Verified integration with HooksDatabase and added tests for all components

feat: Complete Phase 3 integration with comprehensive testing and validation

- Verified all hook functions with database integration
- Created integration and end-to-end tests for session lifecycle
- Ensured non-blocking operations and performance requirements met
- Updated CLI commands for hook architecture and installation flow
- Documented success criteria and next steps for real-world testing
2025-10-15 20:13:04 -04:00
Alex Newman 29f1cb3b4c feat: Add comprehensive best practices guide for context engineering in AI agents 2025-10-15 20:09:57 -04:00
Alex Newman d989ba62f9 feat: add models overview and detailed comparison for Claude models 2025-10-15 18:08:50 -04:00
Alex Newman 7fac3e3bb6 Add comprehensive documentation for Claude Code hooks and streaming input modes
- Introduced a detailed reference for implementing hooks in Claude Code, covering configuration, project-specific scripts, plugin hooks, and various hook events.
- Explained the input modes available in the Claude Agent SDK, emphasizing the benefits of streaming input mode and providing implementation examples for both streaming and single message input.
- Highlighted security considerations and best practices for writing hooks, along with debugging tips and execution details.
2025-10-15 15:51:25 -04:00