Skip to content

Commit 8bf44bd

Browse files
snomiaoclaude
andcommitted
feat: refactor ccx.ts to use esMain check and export function
- Add esMain check to properly handle module vs script execution - Export claudeCodeExec function for programmatic use - Update shebang to use tsx for TypeScript execution - Minor test comment improvement for clarity 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 54c5a63 commit 8bf44bd

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

ccx.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
1+
#!/usr/bin/env tsx
12
// ccx = claude code execution
23

4+
import esMain from "es-main"
35
import yesClaude from "."
46

5-
const prompt = process.argv.slice(2)
6-
console.log("Claude Code Exec: ", prompt.join(" "))
7+
if (esMain(import.meta)) {
8+
const prompt = process.argv.slice(2).join(' ')
9+
console.log("Claude Code Exec: ", prompt)
10+
11+
await claudeCodeExec(prompt)
12+
}
13+
14+
export default async function claudeCodeExec(prompt: string) {
15+
await yesClaude({ claudeArgs: [prompt], exitOnIdle: true })
16+
}
717

8-
await yesClaude({ claudeArgs: [prompt.join(" ")], exitOnIdle: true })

index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,6 @@ it('Write file with auto bypass permission prompt', async () => {
4242

4343
expect(p.exitCode).toBe(0); // expect the process to exit successfully
4444

45-
// 30 seconds timeout for this test, it usually takes 13s to run (10s for claude to respond, 3s for idle watcher to exit)
45+
// 30 seconds timeout for this test, it usually takes 13s to run (10s for claude to solve this problem, 3s for idle watcher to exit)
4646
}, 30e3);
4747

0 commit comments

Comments
 (0)