consult-mcp 0.3.0 → 0.3.1

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.
package/README.md CHANGED
@@ -91,7 +91,7 @@ Settings are stored in `$XDG_CONFIG_HOME/consult/settings.json` (default `~/.con
91
91
 
92
92
  | CLI | How consult finds the session |
93
93
  | --- | --- |
94
- | claude | `CLAUDE_CODE_SESSION_ID`. After `/clear`, the entry still points at the earlier conversation until the session restarts. |
94
+ | claude | the record Claude Code keeps for each running process (`~/.claude/sessions/<pid>.json`), so it follows `/resume` and `/clear`; `CLAUDE_CODE_SESSION_ID` as a fallback. Listed once the conversation is saved, after its first message |
95
95
  | codex | the `rollout-*.jsonl` file the codex process holds open, from the session's first turn on |
96
96
  | grok | the `~/.grok/sessions/<cwd>/<session id>/events.jsonl` file the interactive grok process holds open, from the session's first turn on; not identified if several sessions are open |
97
97
 
@@ -1,4 +1,4 @@
1
- import { existsSync, readdirSync, readlinkSync } from "node:fs";
1
+ import { existsSync, readdirSync, readFileSync, readlinkSync } from "node:fs";
2
2
  import { homedir } from "node:os";
3
3
  import { basename, join } from "node:path";
4
4
  import { AGENTS, SESSION_ID_PATTERN } from "../types.js";
@@ -23,11 +23,14 @@ export async function detectHost(deps) {
23
23
  export async function currentSession(host, deps) {
24
24
  switch (host.agent) {
25
25
  case "claude": {
26
- const sessionId = deps.env.CLAUDE_CODE_SESSION_ID;
26
+ // CLAUDE_CODE_SESSION_ID is fixed when this server starts, so it goes stale after /resume or /clear.
27
+ // Claude Code's per-process record follows the conversation, so it wins when there is one.
28
+ const sessionId = (host.pid === undefined ? undefined : deps.claudeSessionOf(host.pid)) ?? deps.env.CLAUDE_CODE_SESSION_ID;
27
29
  if (!sessionId || !SAFE_ID.test(sessionId))
28
30
  return undefined;
31
+ // A fork resumes the saved conversation, so the session can only be asked once its transcript exists.
29
32
  const transcriptPath = deps.claudeTranscript(sessionId);
30
- return { sessionId, ...(transcriptPath ? { transcriptPath } : {}) };
33
+ return transcriptPath ? { sessionId, transcriptPath } : undefined;
31
34
  }
32
35
  case "codex": {
33
36
  if (host.pid === undefined)
@@ -71,6 +74,7 @@ function procFds(pid) {
71
74
  }
72
75
  }
73
76
  export function systemIdentityDeps(run, env = process.env, platform = process.platform, startPid = process.ppid) {
77
+ const claudeDir = env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude");
74
78
  return {
75
79
  env,
76
80
  async ancestors() {
@@ -94,8 +98,20 @@ export function systemIdentityDeps(run, env = process.env, platform = process.pl
94
98
  .filter((line) => line.startsWith("n"))
95
99
  .map((line) => line.slice(1));
96
100
  },
101
+ claudeSessionOf(pid) {
102
+ try {
103
+ const record = JSON.parse(readFileSync(join(claudeDir, "sessions", `${pid}.json`), "utf8"));
104
+ return record.pid === pid && typeof record.sessionId === "string" && SAFE_ID.test(record.sessionId)
105
+ ? record.sessionId
106
+ : undefined;
107
+ }
108
+ catch {
109
+ // No record (older Claude Code, or not a claude process) or one being rewritten: use the env var.
110
+ return undefined;
111
+ }
112
+ },
97
113
  claudeTranscript(sessionId) {
98
- const projects = join(env.CLAUDE_CONFIG_DIR || join(homedir(), ".claude"), "projects");
114
+ const projects = join(claudeDir, "projects");
99
115
  let dirs;
100
116
  try {
101
117
  dirs = readdirSync(projects);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "consult-mcp",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "MCP server that lets Claude Code, Codex and Grok ask each other for a second opinion through the CLIs already signed in on your machine",
5
5
  "keywords": [
6
6
  "mcp",