Skip to content

fix: load deferred memory tools at session start in Claude Code#43

Merged
Alan-TheGentleman merged 2 commits intoGentleman-Programming:mainfrom
jmeiracorbal:fix/deferred-tools-session-start
Mar 13, 2026
Merged

fix: load deferred memory tools at session start in Claude Code#43
Alan-TheGentleman merged 2 commits intoGentleman-Programming:mainfrom
jmeiracorbal:fix/deferred-tools-session-start

Conversation

@jmeiracorbal
Copy link

Summary

  • Instruct the agent to call ToolSearch at session start so core memory tools are available before any proactive save triggers fire.
  • Applied in both session-start.sh (hook context) and SKILL.md (always-active skill).

Motivation

Closes #42

All Claude Code plugin tools are placed in the deferred pool by the platform, regardless of the defer_loading MCP annotation. The agent receives the Memory Protocol telling it to call mem_save, but the tool is unknown until ToolSearch discovers it. This results in 0 observations saved across all sessions.

Changes

  • plugin/claude-code/scripts/session-start.sh: added FIRST ACTION section to the injected protocol with the exact ToolSearch query for the four core tools
  • plugin/claude-code/skills/memory/SKILL.md: added FIRST ACTION section at the top of the protocol so the agent loads tools even when the hook context is not available (e.g. after compaction)

Test plan

  • go test ./... passes
  • Manually tested: opened a fresh Claude Code session, confirmed ToolSearch was called at session start, confirmed mem_save successfully persisted an observation, verified with engram stats that Observations is no longer 0

Copy link
Collaborator

@Alan-TheGentleman Alan-TheGentleman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need changes

Copy link
Collaborator

@Alan-TheGentleman Alan-TheGentleman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This solves the immediate problem — without it, mem_save literally never gets called in Claude Code. Good find and clean fix.

One change needed: add mcp__plugin_engram_engram__mem_session_end to the select list in both session-start.sh and SKILL.md. Right now you're loading 4 tools but missing the one that marks sessions as ended. If the session-stop hook (#47) fails for any reason, the agent has no fallback because it doesn't know the tool exists.

Everything else looks good. I'll approve once mem_session_end is added to the select.

@Alan-TheGentleman Alan-TheGentleman self-requested a review March 8, 2026 08:49
@Tech-Code1
Copy link

Hey @jmeiracorbal — the fix is solid and addresses a real blocker. To unblock the approval, Alan's requested change is a one-liner in both files:

Add mcp__plugin_engram_engram__mem_session_end to the select query, so the final string becomes:

select:mcp__plugin_engram_engram__mem_save,mcp__plugin_engram_engram__mem_context,mcp__plugin_engram_engram__mem_search,mcp__plugin_engram_engram__mem_session_summary,mcp__plugin_engram_engram__mem_session_end

Apply that in both plugin/claude-code/scripts/session-start.sh and plugin/claude-code/skills/memory/SKILL.md and it should be ready to approve.

@jmeiracorbal
Copy link
Author

This solves the immediate problem — without it, mem_save literally never gets called in Claude Code. Good find and clean fix.

One change needed: add mcp__plugin_engram_engram__mem_session_end to the select list in both session-start.sh and SKILL.md. Right now you're loading 4 tools but missing the one that marks sessions as ended. If the session-stop hook (#47) fails for any reason, the agent has no fallback because it doesn't know the tool exists.

Everything else looks good. I'll approve once mem_session_end is added to the select.

Hello!

Added mcp__plugin_engram_engram__mem_session_end to the ToolSearch select in session-start.sh and SKILL.md.

@Alan-TheGentleman Alan-TheGentleman merged commit 43c4111 into Gentleman-Programming:main Mar 13, 2026
1 check passed
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.

Bug: mem_save never called engram tools are deferred in Claude Code plugin system

3 participants