perf(claude-code): first-message bootstrap asks for mem_context after SessionStart already injected the same context
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 78/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- bash, powershell
- Domain
- tooling
Research direction
Start with plugin/claude-code/scripts/user-prompt-submit.sh:72 and user-prompt-submit.ps1:33, comparing against what session-start.sh:151 injects as additionalContext. Decide which of the two suggested directions to implement (drop the last sentence vs. keep it only when SessionStart injected no context), leaving the ToolSearch instruction untouched. Look for existing tests covering these hook scripts before editing; done means a first-message payload no longer instructs mem_context when SessionStart already provided context, and both Bash and PowerShell versions stay in sync.
Written by the indexing model from the issue text.
Description
📋 Pre-flight Checks
- I have searched existing issues and this is not a duplicate. The closest ones are #163 (size of the SessionStart injection), #581 (slim protocol prose) and #1077 (which tools the first-message ToolSearch loads); none covers the
mem_contextinstruction in the same bootstrap. - I understand this issue needs
status:approvedbefore a PR can be opened
📝 Bug Description
On the first message of every Claude Code session, the UserPromptSubmit bootstrap tells the agent to call mem_context, although the SessionStart hook has already injected that same project context a moment earlier.
plugin/claude-code/scripts/session-start.sh:151fetches/context?project=…&compact=1&pinned=20&max_bytes=16384and prints it asadditionalContext(lines 207–208), under "Memory from Previous Sessions".plugin/claude-code/scripts/user-prompt-submit.sh:72(anduser-prompt-submit.ps1:33) ends the first-message payload with:After loading tools, call mem_context to check for prior session history before responding.
The agent follows the instruction and receives recent sessions, prompts and observations it already has in context. Line numbers are from main at 1edbd5b.
Measured on Claude Code sessions from Oct 5–6, 2026: mem_context was called in 11 sessions, once each, and in all 11 the SessionStart context was already present. Median response 8.9 KB, 82 KB in total. The cost is one extra tool round trip and a duplicated block per session, not a per-turn cost.
🔄 Steps to Reproduce
- Install the Claude Code plugin with
engram setup claude-codein a project that has earlier sessions. - Start a new Claude Code session and send any message.
- Observe the SessionStart
additionalContextwith "Memory from Previous Sessions", then the UserPromptSubmit instruction, then amem_contextcall whose result repeats those sessions, prompts and observations.
✅ Expected Behavior
When SessionStart has injected the project context, the first-message bootstrap does not ask for mem_context again. The agent still calls it on demand, as the memory skill and the server instructions already describe (start of work, after compaction).
❌ Actual Behavior
Every new session pays one mem_context call that returns content already in context. --protocol=slim does not change this: it gates the protocol prose in session-start.sh and post-compaction.sh, not the UserPromptSubmit payload.
🖥️ Environment
- OS: Linux (Fedora 44)
- engram 3.1.0, Claude Code plugin 0.1.6
- Agent / Client: Claude Code 2.1.292
💡 Additional Context
Possible directions, smallest first:
- Drop the last sentence from the first-message payload in both the Bash and PowerShell scripts, leaving the ToolSearch part untouched.
- Or keep it only as a fallback for sessions where SessionStart injected no context (server unreachable, empty project), if the hook can tell.
This is independent of which tools the ToolSearch selector loads (#1077, #1139). Found in the same measurement as #1686.
- Dominant language
- Go
- Stars
- 7.1k
- Forks
- 729
- Avg merge
- 10h 43m
- Merged PRs (30d)
- 332
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from Gentleman-Programming/engram
-
priority:medium status:needs-review type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 80/100
Gentleman-Programming/engram#863 · 1 comment ·
Maintainers usually reply within 1 day
-
question(sync): isolate enrolled-repair writer blocking in a reproducible fixturePossibly taken @dnlrsls claimed this today. Openstatus:approved type:question
Gentleman-Programming/engram#1913 · 3 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
status:needs-review type:bug
Difficulty 4/5 3-5 days Newbie friendliness 12/100
Gentleman-Programming/engram#1912 ·
Maintainers usually reply within 1 day
-
status:needs-review type:bug
Difficulty 5/5 Over a week Newbie friendliness 15/100
Gentleman-Programming/engram#1911 ·
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 12/100
Gentleman-Programming/engram#1909 · 1 comment ·
Maintainers usually reply within 1 day
All issues in Gentleman-Programming/engram
Similar issues
-
Named Tuple element with a space in its name fails to parsePossibly taken @spicysharkco claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
ClickHouse/clickhouse-go#2073 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
ci: nothing regenerates the Go contract types, so a hand-edit to types.gen.go passesPossibly taken @shaiknoorullah claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
shaiknoorullah/hg-mono#993 · 2 comments ·
Maintainers usually reply within 1 day
-
type:bug
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
CarlosDanielDev/aiacc#78 · 1 comment ·
Maintainers usually reply within 1 day
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100