Skip to content

fix: inject memory in connect() before subprocess starts - #8

Open
just-cameron wants to merge 1 commit into
mainfrom
fix/claude-memory-injection-timing
Open

fix: inject memory in connect() before subprocess starts#8
just-cameron wants to merge 1 commit into
mainfrom
fix/claude-memory-injection-timing

Conversation

@just-cameron

Copy link
Copy Markdown
Contributor

Summary

Fixes #6

The ClaudeInterceptor was patching write() to inject memory, but by that time connect() had already spawned the subprocess with the system prompt baked into CLI args.

Root Cause

The execution order was:

  1. connect() calls _build_command() which reads system_prompt
  2. connect() spawns subprocess with those args
  3. write() is called - now the interceptor runs, but it's too late

Fix

  • Patch connect() instead of write() for memory injection
  • Memory is now injected BEFORE _build_command() runs
  • write() patch now only captures outgoing messages
  • Handle both sync and async clients in memory retrieval

Test plan

  • Test with Claude Agent SDK that memory is injected into system prompt
  • Verify message capture still works via write()/read_messages() patches
  • Test with both sync and async Learning SDK clients

🐾 Generated with Letta Code

Fixes #6

The ClaudeInterceptor was patching write() to inject memory, but by that
time connect() had already spawned the subprocess with the system prompt
baked into CLI args.

Changes:
- Patch connect() instead of write() for memory injection
- Memory is now injected BEFORE _build_command() runs
- write() patch now only captures outgoing messages
- Handle both sync and async clients in memory retrieval

Written by Cameron ◯ Letta Code

"The only way to do great work is to love what you do." - Steve Jobs

🐾 Generated with [Letta Code](https://letta.com)

Co-Authored-By: Letta <noreply@letta.com>
@just-cameron

Copy link
Copy Markdown
Contributor Author

@carenthomas

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ClaudeInterceptor injects memory too late - patches write() but subprocess already started

1 participant