claude-remote 0.1.5 → 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/server.js +30 -5
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "claude-remote",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "Remote control bridge for Claude Code REPL - drive from phone/WebUI",
5
5
  "main": "server.js",
6
6
  "bin": {
package/server.js CHANGED
@@ -197,16 +197,41 @@ function maybeAttachHookSession(data, source) {
197
197
  const target = resolveHookTranscript(data);
198
198
  if (!target) return;
199
199
 
200
+ // Already attached to this exact session — no-op
200
201
  if (currentSessionId === target.sessionId && transcriptPath &&
201
202
  normalizeFsPath(transcriptPath) === normalizeFsPath(target.full)) {
202
203
  return;
203
204
  }
204
205
 
205
- // session-start is authoritative — always allow it to switch sessions.
206
- // pre-tool-use is opportunistic — only accept if expecting a switch.
207
- if (currentSessionId && currentSessionId !== target.sessionId && !expectingSwitch && source !== 'session-start') {
208
- log(`Ignored hook session from ${source}: ${target.sessionId} (current=${currentSessionId})`);
209
- return;
206
+ const targetHasContent = fileLooksLikeTranscript(target.full);
207
+
208
+ if (source === 'session-start') {
209
+ // session-start is unreliable for --resume (fires twice, one is a
210
+ // snapshot-only session). Only accept when:
211
+ // 1. No session bound yet (first attach), OR
212
+ // 2. Expecting a switch (/clear), OR
213
+ // 3. Target has conversation content and current doesn't
214
+ if (currentSessionId && !expectingSwitch) {
215
+ const currentHasContent = transcriptPath && fileLooksLikeTranscript(transcriptPath);
216
+ if (!targetHasContent || currentHasContent) {
217
+ log(`Ignored session-start: ${target.sessionId} (current=${currentSessionId} currentHasContent=${currentHasContent} targetHasContent=${targetHasContent})`);
218
+ return;
219
+ }
220
+ }
221
+ } else if (source === 'pre-tool-use') {
222
+ // pre-tool-use is the authoritative source — comes from the actually
223
+ // running Claude process. Always allow it to correct the session,
224
+ // as long as the target transcript has conversation content.
225
+ if (currentSessionId && currentSessionId !== target.sessionId && !targetHasContent) {
226
+ log(`Ignored pre-tool-use: ${target.sessionId} (no conversation content)`);
227
+ return;
228
+ }
229
+ } else {
230
+ // Other sources (e.g. stop) — only accept if matching current or no session
231
+ if (currentSessionId && currentSessionId !== target.sessionId && !expectingSwitch) {
232
+ log(`Ignored hook session from ${source}: ${target.sessionId} (current=${currentSessionId})`);
233
+ return;
234
+ }
210
235
  }
211
236
 
212
237
  log(`Hook session attached from ${source}: ${target.sessionId}`);