@gonzih/cc-tg 0.1.6 → 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.
package/README.md CHANGED
@@ -26,6 +26,18 @@ That's it. Open your bot in Telegram and start chatting.
26
26
 
27
27
  *One of CLAUDE_CODE_TOKEN or ANTHROPIC_API_KEY is required.
28
28
 
29
+ ## How to get your Claude Code token
30
+
31
+ Run this once to generate a long-lived OAuth token:
32
+
33
+ ```bash
34
+ npx @anthropic-ai/claude-code setup-token
35
+ ```
36
+
37
+ It opens a browser, logs you in with your Anthropic account, and prints a token starting with `sk-ant-oat`. Paste that as `CLAUDE_CODE_TOKEN`.
38
+
39
+ Alternatively, use an `ANTHROPIC_API_KEY` from [console.anthropic.com](https://console.anthropic.com) (API key starts with `sk-ant-api`).
40
+
29
41
  ## How to get your Telegram user ID
30
42
 
31
43
  Message [@userinfobot](https://t.me/userinfobot) on Telegram — it replies with your ID.
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 = "";
@@ -17,25 +18,29 @@ export class ClaudeProcess extends EventEmitter {
17
18
  "--input-format", "stream-json",
18
19
  "--print",
19
20
  "--verbose",
21
+ "--dangerously-skip-permissions",
20
22
  ];
21
23
  if (opts.systemPrompt) {
22
24
  args.push("--system-prompt", opts.systemPrompt);
23
25
  }
24
26
  const env = { ...process.env };
25
27
  if (opts.token) {
26
- // OAuth tokens start with sk-ant-oat — set CLAUDE_CODE_OAUTH_TOKEN only
27
28
  // API keys start with sk-ant-api — set ANTHROPIC_API_KEY only
29
+ // Everything else (OAuth sk-ant-oat, setup-token format with #, etc.)
30
+ // goes into CLAUDE_CODE_OAUTH_TOKEN
28
31
  // Mixing them causes "Invalid API key" errors
29
- if (opts.token.startsWith("sk-ant-oat")) {
30
- env.CLAUDE_CODE_OAUTH_TOKEN = opts.token;
31
- delete env.ANTHROPIC_API_KEY;
32
- }
33
- else {
32
+ if (opts.token.startsWith("sk-ant-api")) {
34
33
  env.ANTHROPIC_API_KEY = opts.token;
35
34
  delete env.CLAUDE_CODE_OAUTH_TOKEN;
36
35
  }
36
+ else {
37
+ env.CLAUDE_CODE_OAUTH_TOKEN = opts.token;
38
+ delete env.ANTHROPIC_API_KEY;
39
+ }
37
40
  }
38
- 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, {
39
44
  cwd: opts.cwd ?? process.cwd(),
40
45
  env,
41
46
  stdio: ["pipe", "pipe", "pipe"],
@@ -125,3 +130,29 @@ export function extractText(msg) {
125
130
  }
126
131
  return "";
127
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.6",
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": {