@gonzih/cc-tg 0.1.8 → 0.1.9

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/dist/claude.js +30 -1
  2. package/package.json +1 -1
package/dist/claude.js CHANGED
@@ -5,6 +5,7 @@
5
5
  */
6
6
  import { spawn } from "child_process";
7
7
  import { EventEmitter } from "events";
8
+ import { existsSync } from "fs";
8
9
  export class ClaudeProcess extends EventEmitter {
9
10
  proc;
10
11
  buffer = "";
@@ -37,7 +38,9 @@ export class ClaudeProcess extends EventEmitter {
37
38
  delete env.ANTHROPIC_API_KEY;
38
39
  }
39
40
  }
40
- this.proc = spawn("claude", args, {
41
+ // Resolve claude binary — check common install locations if not in PATH
42
+ const claudeBin = resolveClaude(env.PATH);
43
+ this.proc = spawn(claudeBin, args, {
41
44
  cwd: opts.cwd ?? process.cwd(),
42
45
  env,
43
46
  stdio: ["pipe", "pipe", "pipe"],
@@ -127,3 +130,29 @@ export function extractText(msg) {
127
130
  }
128
131
  return "";
129
132
  }
133
+ /**
134
+ * Resolve the claude CLI binary path.
135
+ * Checks PATH entries + common npm global install locations.
136
+ */
137
+ function resolveClaude(pathEnv) {
138
+ // Try PATH entries first
139
+ const dirs = (pathEnv ?? process.env.PATH ?? "").split(":");
140
+ for (const dir of dirs) {
141
+ const candidate = `${dir}/claude`;
142
+ if (existsSync(candidate))
143
+ return candidate;
144
+ }
145
+ // Common fallback locations
146
+ const fallbacks = [
147
+ `${process.env.HOME}/.npm-global/bin/claude`,
148
+ "/opt/homebrew/bin/claude",
149
+ "/usr/local/bin/claude",
150
+ "/usr/bin/claude",
151
+ ];
152
+ for (const p of fallbacks) {
153
+ if (existsSync(p))
154
+ return p;
155
+ }
156
+ // Last resort — let the OS resolve it (will throw ENOENT if missing)
157
+ return "claude";
158
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gonzih/cc-tg",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Claude Code Telegram bot — chat with Claude Code via Telegram",
5
5
  "type": "module",
6
6
  "bin": {