Skip to content

Error: Context generation failed: Worker service connection failed. #305

@clayton

Description

@clayton

Describe the bug
Plugin always starts with error about worker service connection failed.

To Reproduce
Steps to reproduce the behavior:

  1. On MacOS 26.1
  2. Install Claude Code v2.0.69
  3. Start Claude
  4. Run /plugin marketplace add thedotmack/claude-mem then plugin install claude-mem
  5. Install for user scope
  6. Exit and restart Claude Code
  7. See error
  8. Exit Claude Code and follow instructions to restart worker
  9. Open Claude Code
  10. See error again

Expected behavior
I am expecting that the plugin works after installing and reopening Claude Code. I am also expecting that following the instructions from the error fixes the issue.

Instructions from the error:

To restart the worker:
    1. Exit Claude Code completely
    2. Open Terminal
    3. Navigate to: ~/.claude/plugins/marketplaces/thedotmack
    4. Run: npm run worker:restart

Desktop (please complete the following information):

  • OS: MacOS 26.1
  • CC Version 2.0.69
  • Plugin version: 7.1.14

Full Claude output:

claude

 * ▐▛███▜▌ *   Claude Code v2.0.69
* ▝▜█████▛▘ *  Opus 4.5 · Claude Max
 *  ▘▘ ▝▝  *   ~/Projects/MyProject
  ⎿  SessionStart:startup says: Plugin hook error: ---
     🎉  Note: This appears under Plugin Hook Error, but it's not an error. That's the only option for
        user messages in Claude Code UI until a better method is provided.
     ---

     ⚠️  Claude-Mem: First-Time Setup

     Dependencies are installing in the background. This only happens once.

     💡 TIPS:
        • Memories will start generating while you work
        • Use /init to write or update your CLAUDE.md for better project context
        • Try /clear after one session to see what context looks like

     Thank you for installing Claude-Mem!

     This message was not added to your startup context, so you can continue working as normal.
  ⎿ SessionStart:startup says: Plugin hook error: [2025-12-14 11:41:33.256] [ERROR] [HOOK  ] Context 
    generation failed {status=404, hookName=context, operation=Context generation, 
    project=MyProject, port=37777} <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>Error</title>
    </head>
    <body>
    <pre>Cannot GET /api/context/inject</pre>
    </body>
    </html>

    file:///Users/clayton/.claude/plugins/cache/thedotmack/claude-mem/7.1.14/scripts/context-hook.js:14
    ${u}`),u}var 
    j=C.join(Ct(),".claude","plugins","marketplaces","thedotmack"),V=U(S.HEALTH_CHECK),_=null;function 
    E(){if(_!==null)return _;try{let 
    n=C.join(l.get("CLAUDE_MEM_DATA_DIR"),"settings.json"),t=l.loadFromFile(n);return 
    _=parseInt(t.CLAUDE_MEM_WORKER_PORT,10),_}catch(n){return c.debug("SYSTEM","Failed to load port 
    from settings, using default",{error:n}),_=parseInt(l.get("CLAUDE_MEM_WORKER_PORT"),10),_}}async 
    function I(){try{let n=E();return(await 
    fetch(`http://127.0.0.1:${n}/health`,{signal:AbortSignal.timeout(V)})).ok}catch(n){return 
    c.debug("SYSTEM","Worker health check failed",{error:n instanceof 
    Error?n.message:String(n),errorType:n?.constructor?.name}),!1}}function Rt(){try{let 
    n=C.join(j,"package.json");return JSON.parse(Dt(n,"utf-8")).version}catch(n){return 
    c.debug("SYSTEM","Failed to read plugin version",{error:n instanceof 
    Error?n.message:String(n)}),null}}async function It(){try{let n=E(),t=await 
    fetch(`http://127.0.0.1:${n}/api/version`,{signal:AbortSignal.timeout(V)});return t.ok?(await 
    t.json()).version:null}catch(n){return c.debug("SYSTEM","Failed to get worker version",{error:n 
    instanceof Error?n.message:String(n)}),null}}async function B(){let n=Rt(),t=await 
    It();!n||!t||n!==t&&(c.info("SYSTEM","Worker version mismatch detected - restarting 
    worker",{pluginVersion:n,workerVersion:t}),await O.restart(E()),await new 
    Promise(e=>setTimeout(e,1e3)),await I()||c.error("SYSTEM","Worker failed to restart after version 
    mismatch",{expectedVersion:n,runningVersion:t,port}))}async function wt(){let 
    n=l.get("CLAUDE_MEM_DATA_DIR"),t=C.join(n,".pm2-migrated");if(Lt(n,{recursive:!0}),!Mt(t))try{At("p
    m2",["delete","claude-mem-worker"],{stdio:"ignore"}),K(t,new 
    Date().toISOString(),"utf-8"),c.debug("SYSTEM","PM2 cleanup completed and marked")}catch{K(t,new 
    Date().toISOString(),"utf-8")}let e=E(),r=await O.start(e);return 
    r.success||c.error("SYSTEM","Failed to start 
    worker",{platform:process.platform,port:e,error:r.error,marketplaceRoot:j}),r.success}async 
    function G(){if(await I()){await B();return}if(!await wt()){let e=E();throw new 
    Error(m({port:e,customPrefix:`Worker service failed to start on port ${e}.`}))}for(let 
    e=0;e<5;e++)if(await new Promise(r=>setTimeout(r,500)),await I()){await B();return}let t=E();throw 
    c.error("SYSTEM","Worker started but not responding to health checks"),new 
    Error(m({port:t,customPrefix:`Worker service started but is not responding on port 
    ${t}.`}))}function X(n){throw n.cause?.code==="ECONNREFUSED"||n.code==="ConnectionRefused"||n.name=
    =="TimeoutError"||n.message?.includes("fetch failed")||n.message?.includes("Unable to connect")?new
     Error(m()):n}function Y(n,t,e){c.error("HOOK",`${e.operation} 
    failed`,{status:n.status,...e},t);let r=e.toolName?`Failed ${e.operation} for ${e.toolName}: 
    ${m()}`:`${e.operation} failed: ${m()}`;throw new Error(r)}async function J(n){await G();let 
    t=n?.cwd??process.cwd(),e=t?bt.basename(t):"unknown-project",r=E(),o=`http://127.0.0.1:${r}/api/con
    text/inject?project=${encodeURIComponent(e)}`;try{let s=await 
    fetch(o,{signal:AbortSignal.timeout(S.DEFAULT)});if(!s.ok){let a=await 
    s.text();Y(s,a,{hookName:"context",operation:"Context generation",project:e,port:r})}return(await 
    s.text()).trim()}catch(s){X(s)}}var yt=process.argv.includes("--colors");if(w.isTTY||yt)J(void 
    0).then(n=>{console.log(n),process.exit(0)});else{let 
    n="";w.on("data",t=>n+=t),w.on("end",async()=>{let t=n.trim()?JSON.parse(n):void 0,e=await 
    J(t);console.log(JSON.stringify({hookSpecificOutput:{hookEventName:"SessionStart",additionalContext
    :e}})),process.exit(0)})}
                                                                                                       
                                                                                                       
                                                                                                       
                                                                                                       
                                                                                                       
                                                                                                       
                                                                                                       
                                                                                                       
                                                                                                       
                                                                                                       
                                  

    Error: Context generation failed: Worker service connection failed.

    To restart the worker:
    1. Exit Claude Code completely
    2. Open Terminal
    3. Navigate to: ~/.claude/plugins/marketplaces/thedotmack
    4. Run: npm run worker:restart
        at Y (file:///Users/clayton/.claude/plugins/cache/thedotmack/claude-mem/7.1.14/scripts/context-
    hook.js:14:2822)
        at J (file:///Users/clayton/.claude/plugins/cache/thedotmack/claude-mem/7.1.14/scripts/context-
    hook.js:14:3110)
        at process.processTicksAndRejections (node:internal/process/task_queues:103:5)
        at async Socket.<anonymous> (file:///Users/clayton/.claude/plugins/cache/thedotmack/claude-mem/
    7.1.14/scripts/context-hook.js:14:3433)

    Node.js v25.2.1

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions