Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#1431·agentmemory

SessionStart hook prints plain text - memory context never injected by strict hook runners (DSH)

Author: ice5631024721Created Sep 28, 2026Updated Sep 28, 2026

Summary

plugin/scripts/session-start.mjs prints the memory context as plain text (starts with <agentmemory-context ...>). This works in Claude Code, because Claude Code adds SessionStart hook stdout to the conversation context.

However, hook runners that only inject structured hook output silently discard it. Example: DeepSeek Harness (DSH) with its official @deepseek-ai/dsh-hooks-claude-code adapter - its decoder (@deepseek-ai/dsh-hook-protocol, parseHookOutput) only treats stdout as context when it is a JSON envelope:

json
{"hookSpecificOutput":{"hookEventName":"SessionStart","additionalContext":"..."}}

Plain-text stdout is recorded as stdout but additionalContext is never set, so on DSH the memory injection silently does nothing: the hook runs, the engine answers with the memory context, and the context never receives it.

Environment

  • agentmemory 0.9.29 (engine + plugin/scripts/session-start.mjs)
  • Runner: DSH NEXT 2.0.15 + @deepseek-ai/dsh-hooks-claude-code 0.1.7-rc.1 (@deepseek-ai/dsh-hook-protocol codec)
  • Hook config: env AGENTMEMORY_INJECT_CONTEXT=true <node> .../plugin/scripts/session-start.mjs

Repro

bash
echo '{"session_id":"t","cwd":"/repo","hook_event_name":"SessionStart","source":"start"}'   | AGENTMEMORY_INJECT_CONTEXT=true node .../plugin/scripts/session-start.mjs
# stdout: "<agentmemory-context project="...">..."  (plain text, several KB - correct content, wrong format for strict runners)

A strict runner parses this as additionalContext = undefined and injects nothing. The same text wrapped as {"hookSpecificOutput":{"hookEventName":"SessionStart","additionalContext":"<text>"}} is injected correctly (verified against the runner's own parseHookOutput + mergeHookOutputs).

Suggested fix

Have session-start.mjs emit the JSON envelope (Claude Code accepts this format as well):

javascript
process.stdout.write(JSON.stringify({
  hookSpecificOutput: { hookEventName: "SessionStart", additionalContext: contextText }
}));

or gate it behind an env flag for runners that need the envelope.

Workaround in use

A local wrapper that spawns the official script and re-wraps its stdout in the envelope - verified against the runner's parser. Works, but it is per-machine glue that an npm update can silently orphan, so an upstream fix is preferred.

Source: rohitg00/agentmemory

View original on GitHubView discussion on GitHub