charleszhou 0.1.0

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Anwith Telluri
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,75 @@
1
+ # charleszhou
2
+
3
+ Open Charles Zhou whenever Claude Code or Codex receives a new prompt.
4
+
5
+ ## Install
6
+
7
+ ```sh
8
+ bun add -g charleszhou
9
+ ```
10
+
11
+ Or run it directly:
12
+
13
+ ```sh
14
+ bunx charleszhou show
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ Open the picture once:
20
+
21
+ ```sh
22
+ charleszhou show
23
+ ```
24
+
25
+ Install prompt-submit hooks for both Claude Code and Codex:
26
+
27
+ ```sh
28
+ charleszhou install
29
+ ```
30
+
31
+ Install only one integration:
32
+
33
+ ```sh
34
+ charleszhou install --claude
35
+ charleszhou install --codex
36
+ ```
37
+
38
+ Remove the hooks:
39
+
40
+ ```sh
41
+ charleszhou uninstall
42
+ ```
43
+
44
+ ## What It Changes
45
+
46
+ `charleszhou install` adds a `UserPromptSubmit` command hook that runs:
47
+
48
+ ```sh
49
+ charleszhou show --quiet
50
+ ```
51
+
52
+ For Claude Code, it updates:
53
+
54
+ ```text
55
+ ~/.claude/settings.json
56
+ ```
57
+
58
+ For Codex, it updates:
59
+
60
+ ```text
61
+ ~/.codex/hooks.json
62
+ ~/.codex/config.toml
63
+ ```
64
+
65
+ Codex may ask you to review and trust the hook with `/hooks` the next time it starts. That is expected for new or changed Codex hooks.
66
+
67
+ ## Publish
68
+
69
+ From this directory:
70
+
71
+ ```sh
72
+ bun publish
73
+ ```
74
+
75
+ The package includes the bundled image at `assets/charleszhou.png`.
Binary file
@@ -0,0 +1,302 @@
1
+ #!/usr/bin/env node
2
+ import { spawn } from "node:child_process";
3
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
4
+ import { homedir, platform } from "node:os";
5
+ import { dirname, join, resolve } from "node:path";
6
+ import { fileURLToPath } from "node:url";
7
+
8
+ const packageRoot = resolve(dirname(fileURLToPath(import.meta.url)), "..");
9
+ const imagePath = join(packageRoot, "assets", "charleszhou.png");
10
+ const hookEvent = "UserPromptSubmit";
11
+
12
+ const usage = `charleszhou
13
+
14
+ Usage:
15
+ charleszhou show [--quiet] Open the Charles Zhou image
16
+ charleszhou path Print the bundled image path
17
+ charleszhou install [targets] Install Claude/Codex prompt hooks
18
+ charleszhou uninstall [targets] Remove Claude/Codex prompt hooks
19
+
20
+ Targets:
21
+ --claude Only update ~/.claude/settings.json
22
+ --codex Only update ~/.codex/hooks.json
23
+
24
+ Examples:
25
+ bunx charleszhou show
26
+ bunx charleszhou install
27
+ bunx charleszhou uninstall --codex
28
+ `;
29
+
30
+ function quoteShell(value) {
31
+ return `"${value.replaceAll("\\", "\\\\").replaceAll('"', '\\"')}"`;
32
+ }
33
+
34
+ function hookCommand() {
35
+ return `${quoteShell(process.execPath)} ${quoteShell(fileURLToPath(import.meta.url))} show --quiet`;
36
+ }
37
+
38
+ function readJsonFile(filePath) {
39
+ if (!existsSync(filePath)) {
40
+ return {};
41
+ }
42
+
43
+ const source = readFileSync(filePath, "utf8").trim();
44
+
45
+ if (!source) {
46
+ return {};
47
+ }
48
+
49
+ return JSON.parse(source);
50
+ }
51
+
52
+ function writeJsonFile(filePath, value) {
53
+ mkdirSync(dirname(filePath), { recursive: true });
54
+ writeFileSync(filePath, `${JSON.stringify(value, null, 2)}\n`);
55
+ }
56
+
57
+ function isRecord(value) {
58
+ return typeof value === "object" && value !== null && !Array.isArray(value);
59
+ }
60
+
61
+ function withCharlesHook(config, command) {
62
+ const next = isRecord(config) ? config : {};
63
+
64
+ if (!isRecord(next.hooks)) {
65
+ next.hooks = {};
66
+ }
67
+
68
+ const groups = Array.isArray(next.hooks[hookEvent]) ? next.hooks[hookEvent] : [];
69
+ next.hooks[hookEvent] = groups;
70
+
71
+ const alreadyInstalled = groups.some(
72
+ (group) =>
73
+ isRecord(group) &&
74
+ Array.isArray(group.hooks) &&
75
+ group.hooks.some(
76
+ (hook) =>
77
+ isRecord(hook) &&
78
+ typeof hook.command === "string" &&
79
+ hook.command.includes("charleszhou")
80
+ )
81
+ );
82
+
83
+ if (alreadyInstalled) {
84
+ return { changed: false, config: next };
85
+ }
86
+
87
+ groups.push({
88
+ hooks: [
89
+ {
90
+ type: "command",
91
+ command,
92
+ timeout: 5,
93
+ },
94
+ ],
95
+ });
96
+
97
+ return { changed: true, config: next };
98
+ }
99
+
100
+ function withoutCharlesHook(config) {
101
+ const next = isRecord(config) ? config : {};
102
+
103
+ if (!isRecord(next.hooks) || !Array.isArray(next.hooks[hookEvent])) {
104
+ return { changed: false, config: next };
105
+ }
106
+
107
+ const previousLength = next.hooks[hookEvent].length;
108
+ next.hooks[hookEvent] = next.hooks[hookEvent]
109
+ .map((group) => {
110
+ if (!isRecord(group) || !Array.isArray(group.hooks)) {
111
+ return group;
112
+ }
113
+
114
+ return {
115
+ ...group,
116
+ hooks: group.hooks.filter(
117
+ (hook) =>
118
+ !(
119
+ isRecord(hook) &&
120
+ typeof hook.command === "string" &&
121
+ hook.command.includes("charleszhou")
122
+ )
123
+ ),
124
+ };
125
+ })
126
+ .filter(
127
+ (group) =>
128
+ !(isRecord(group) && Array.isArray(group.hooks) && group.hooks.length === 0)
129
+ );
130
+
131
+ return {
132
+ changed: previousLength !== next.hooks[hookEvent].length,
133
+ config: next,
134
+ };
135
+ }
136
+
137
+ function enableCodexHooksFeature(configPath) {
138
+ const existing = existsSync(configPath) ? readFileSync(configPath, "utf8") : "";
139
+ const eol = existing.includes("\r\n") ? "\r\n" : "\n";
140
+ const lines = existing ? existing.split(/\r?\n/) : [];
141
+ const featureIndex = lines.findIndex((line) => /^\s*\[features\]\s*$/.test(line));
142
+
143
+ if (featureIndex === -1) {
144
+ const prefix = existing && !existing.endsWith(eol) ? eol : "";
145
+ const next = `${existing}${prefix}[features]${eol}hooks = true${eol}`;
146
+ mkdirSync(dirname(configPath), { recursive: true });
147
+ writeFileSync(configPath, next);
148
+ return true;
149
+ }
150
+
151
+ const nextSectionIndex = lines.findIndex(
152
+ (line, index) => index > featureIndex && /^\s*\[[^\]]+\]\s*$/.test(line)
153
+ );
154
+ const endIndex = nextSectionIndex === -1 ? lines.length : nextSectionIndex;
155
+ const hooksIndex = lines.findIndex(
156
+ (line, index) =>
157
+ index > featureIndex && index < endIndex && /^\s*hooks\s*=/.test(line)
158
+ );
159
+
160
+ if (hooksIndex !== -1) {
161
+ if (/^\s*hooks\s*=\s*true\s*$/.test(lines[hooksIndex])) {
162
+ return false;
163
+ }
164
+
165
+ lines[hooksIndex] = "hooks = true";
166
+ } else {
167
+ lines.splice(featureIndex + 1, 0, "hooks = true");
168
+ }
169
+
170
+ mkdirSync(dirname(configPath), { recursive: true });
171
+ writeFileSync(configPath, lines.join(eol));
172
+ return true;
173
+ }
174
+
175
+ function selectedTargets(args) {
176
+ const wantsClaude = args.includes("--claude");
177
+ const wantsCodex = args.includes("--codex");
178
+
179
+ if (!(wantsClaude || wantsCodex)) {
180
+ return { claude: true, codex: true };
181
+ }
182
+
183
+ return { claude: wantsClaude, codex: wantsCodex };
184
+ }
185
+
186
+ function updateHookFile(filePath, updater) {
187
+ const config = readJsonFile(filePath);
188
+ const result = updater(config);
189
+
190
+ if (result.changed) {
191
+ writeJsonFile(filePath, result.config);
192
+ }
193
+
194
+ return result.changed;
195
+ }
196
+
197
+ function install(args) {
198
+ const targets = selectedTargets(args);
199
+ const command = hookCommand();
200
+ const results = [];
201
+
202
+ if (targets.claude) {
203
+ const path = join(homedir(), ".claude", "settings.json");
204
+ const changed = updateHookFile(path, (config) => withCharlesHook(config, command));
205
+ results.push(`Claude: ${changed ? "installed" : "already installed"} (${path})`);
206
+ }
207
+
208
+ if (targets.codex) {
209
+ const hooksPath = join(homedir(), ".codex", "hooks.json");
210
+ const configPath = join(homedir(), ".codex", "config.toml");
211
+ const hooksChanged = updateHookFile(hooksPath, (config) =>
212
+ withCharlesHook(config, command)
213
+ );
214
+ const featureChanged = enableCodexHooksFeature(configPath);
215
+ results.push(
216
+ `Codex: ${hooksChanged ? "installed" : "already installed"} (${hooksPath})`
217
+ );
218
+ results.push(
219
+ `Codex hooks feature: ${featureChanged ? "enabled" : "already enabled"} (${configPath})`
220
+ );
221
+ }
222
+
223
+ console.log(results.join("\n"));
224
+ }
225
+
226
+ function uninstall(args) {
227
+ const targets = selectedTargets(args);
228
+ const results = [];
229
+
230
+ if (targets.claude) {
231
+ const path = join(homedir(), ".claude", "settings.json");
232
+ const changed = updateHookFile(path, withoutCharlesHook);
233
+ results.push(`Claude: ${changed ? "removed" : "not installed"} (${path})`);
234
+ }
235
+
236
+ if (targets.codex) {
237
+ const path = join(homedir(), ".codex", "hooks.json");
238
+ const changed = updateHookFile(path, withoutCharlesHook);
239
+ results.push(`Codex: ${changed ? "removed" : "not installed"} (${path})`);
240
+ }
241
+
242
+ console.log(results.join("\n"));
243
+ }
244
+
245
+ function showImage(args) {
246
+ if (!existsSync(imagePath)) {
247
+ throw new Error(`Could not find bundled image at ${imagePath}`);
248
+ }
249
+
250
+ const currentPlatform = platform();
251
+ const opener =
252
+ currentPlatform === "darwin"
253
+ ? { command: "open", args: [imagePath] }
254
+ : currentPlatform === "win32"
255
+ ? { command: "cmd", args: ["/c", "start", "", imagePath] }
256
+ : { command: "xdg-open", args: [imagePath] };
257
+
258
+ const child = spawn(opener.command, opener.args, {
259
+ detached: true,
260
+ stdio: "ignore",
261
+ });
262
+ child.unref();
263
+
264
+ if (!args.includes("--quiet")) {
265
+ console.log(`Opened ${imagePath}`);
266
+ }
267
+ }
268
+
269
+ function main() {
270
+ const [command = "help", ...args] = process.argv.slice(2);
271
+
272
+ switch (command) {
273
+ case "show":
274
+ showImage(args);
275
+ break;
276
+ case "path":
277
+ console.log(imagePath);
278
+ break;
279
+ case "install":
280
+ install(args);
281
+ break;
282
+ case "uninstall":
283
+ uninstall(args);
284
+ break;
285
+ case "help":
286
+ case "--help":
287
+ case "-h":
288
+ console.log(usage);
289
+ break;
290
+ default:
291
+ console.error(`Unknown command: ${command}\n`);
292
+ console.error(usage);
293
+ process.exitCode = 1;
294
+ }
295
+ }
296
+
297
+ try {
298
+ main();
299
+ } catch (error) {
300
+ console.error(error instanceof Error ? error.message : String(error));
301
+ process.exitCode = 1;
302
+ }
package/package.json ADDED
@@ -0,0 +1,33 @@
1
+ {
2
+ "name": "charleszhou",
3
+ "version": "0.1.0",
4
+ "description": "Open Charles Zhou whenever Claude Code or Codex receives a prompt.",
5
+ "type": "module",
6
+ "bin": {
7
+ "charleszhou": "./bin/charleszhou.js"
8
+ },
9
+ "files": [
10
+ "assets/charleszhou.png",
11
+ "bin/charleszhou.js",
12
+ "README.md",
13
+ "LICENSE"
14
+ ],
15
+ "scripts": {
16
+ "check": "bun run bin/charleszhou.js --help && bun run bin/charleszhou.js path",
17
+ "prepublishOnly": "bun run check"
18
+ },
19
+ "keywords": [
20
+ "claude",
21
+ "codex",
22
+ "hooks",
23
+ "charles",
24
+ "zhou"
25
+ ],
26
+ "license": "MIT",
27
+ "publishConfig": {
28
+ "access": "public"
29
+ },
30
+ "engines": {
31
+ "node": ">=20"
32
+ }
33
+ }