KO EN
CS&NEWS — Field Note
2026 / SEOUL

No API Key,
Just AI Features.

Call the claude CLI already installed on your machine, straight from server code. No signup, no billing, no SDK.

Local Tooling · Claude Code & Codex CLI · Zero API Key
Read time 4 MIN Topic Claude Code · Codex CLI · Local Tooling · Node/Bun Author CS
Background
WHY THIS WORKS

While building a personal local tool — a “port manager” app — I wanted to add an AI feature that suggests project names. The first roadblock hit immediately: getting an API key, registering a payment method, and tracking usage felt like way too much overhead for a side project.

Then I realized: if Claude Code is already installed on your machine, you can call Claude straight from a local server (Node.js, Bun, PHP — anything) without a separate API key. The port manager’s AI name-suggestion feature runs on exactly this pattern today. This post breaks down the mechanism so anyone can apply it to their own project.

Run one command,
parse the output.
— treating the claude CLI like any other program
Part A

What a human should understand

Why this works, and when to use it (or not) — the judgment calls before you write any code

§ 01

The core ideaclaude is just a command-line program

Extra API keys
to issue
0
Reuses your already
authenticated CLI session
Steps to
implement
3
Find path → run
→ parse, that’s it
Recommended
timeout
30s
Guards against a
hung subprocess
SDKs
required
0
Just call the
installed CLI

Installing Claude Code gives you a claude executable in your terminal. It’s the same tool you chat with every day — but it’s also just a regular CLI program, which means any other program can launch it too.

Terminal · one-shot with -p
# No interactive session — one question in, one answer out, exit claude -p “Summarize this text in one sentence: …”

Add the -p (or --print) flag and Claude skips the interactive session entirely: take one prompt → print the answer to stdout → exit. From your server code’s point of view, that’s nothing more than “run an external program, read back some text.”

Terminal · Codex CLI, same pattern
# Codex CLI (OpenAI) works the same way if it’s already installed and logged in codex exec “Summarize this text in one sentence: …”

This isn’t unique to Claude Code. Codex CLI works on the same principle once it’s installed locally and logged in. Instead of an interactive session, its exec subcommand (alias e) plays the same role as -p — “one prompt in → one final answer → exit.”

My first attempt just used which claude to find the path. Worked fine in a terminal. But once I launched the port manager as a GUI app, that function kept returning null. GUI apps usually start in a non-login shell that never reads .zshrc, so the PATH entry for a claude installed via nvm/homebrew was simply empty. Only after wrapping the lookup in a login shell (zsh -l -c) did it reproduce the same PATH you get in a normal terminal — that’s exactly why Part B’s resolveClaudePath() bothers with zsh -l -c. codex hits the identical problem when launched from a GUI app, so it needs the same path-resolution trick.

§ 02

When to use itPros, caveats, and the call to make before you write code

CriterionOfficial Anthropic APILocal claude CLI call (this post’s approach)
SetupRequires an API key + billing methodNone — reuses your already-authenticated CLI session
CostBilled separately by token usageCovered by your Claude Code subscription, no extra charge
Deployment targetA service deployed to the web for many usersA personal local tool that only runs on your own machine
Pros
WHEN TO USE

No API key management — reuses the already-installed, already-authenticated claude CLI session as-is.

No extra cost (for personal use) — covered by your Claude Code subscription/usage, with no separate server-side API billing.

A great fit for local-only tools — not a deployed multi-user web service, but a personal tool (like a port manager) that only runs on your own machine.

Caveats
WHEN NOT TO

Not a fit for a production service with multiple users. This is fundamentally “my local server calls the CLI installed on my machine” — if you’re deploying to the web for the general public, the official Anthropic API + a real API key is the right choice.

Fails outright without the CLI. If resolveClaudePath() returns null (Claude Code isn’t installed, etc.), that feature should degrade to a 503 error.

Always set a timeout. A subprocess call may never respond, so you need a kill switch (proc.kill()) to force it to terminate.

Part B

What to hand straight to an AI

Copy the prompt below into Claude Code (or any AI coding assistant) and it builds the feature

§ 03

The implementation promptCopy, paste into your AI assistant

PROMPT · copy verbatim
Build two TypeScript (Bun runtime) utilities to this spec: resolveClaudePath() and callClaude(). 1. resolveClaudePath(): string | null – Look up the claude executable’s path via `zsh -l -c ‘which claude’` (a login shell, so PATH is fully loaded). – If not found, check these paths directly in order: /opt/homebrew/bin/claude /usr/local/bin/claude ${HOME}/.npm-global/bin/claude – If still not found, return null. 2. callClaude(prompt: string, model = ‘haiku’): Promise<any> – If resolveClaudePath() is null, throw a 503 error immediately. – Run via Bun.spawn with [claudePath, ‘–safe-mode’, ‘-p’, ‘–model’, model, prompt] (stdout/stderr set to ‘pipe’). – 30-second timeout: if there’s no response in time, force-kill via proc.kill(). – Read stdout as a string and extract only the JSON block via the regex /\{[\s\S]*\}/, then JSON.parse it. – If no JSON block is found, return a safe default (e.g. { name: null, category: null }). Constraints: – Always include –safe-mode so the call returns pure text with no file/command access. – Pin lightweight tasks like name/category suggestions to –model haiku. – Never use this pattern in a production server handling multiple users (local personal tools only).

This prompt already encodes the implementation order, fallback paths, timeout value, and error handling. If you’re curious why it’s built this way, see Part A above.

§ 04

Reference implementationWhat the AI will generate (Bun-based)

Find the path
GUI/background processes often have an empty PATH, so re-query via a login shell.
zsh -l -c ‘which claude’
Run the subprocess
Build the prompt and run with –safe-mode, -p, –model haiku.
Bun.spawn([…])
Timeout
The response may never arrive, so force-kill after a set duration.
setTimeout(kill, 30_000)
Parse the response
Extract just the JSON block from the natural-language output via regex.
raw.match(/\{[\s\S]*\}/)
resolveClaudePath.ts
function resolveClaudePath(): string | null { // Query via a zsh login shell — PATH and aliases are fully loaded here const r = Bun.spawnSync([‘zsh’, ‘-l’, ‘-c’, ‘which claude’]); const path = r.stdout.toString().trim(); if (path && existsSync(path)) return path; // Fall back to checking common install locations directly for (const p of [ ‘/opt/homebrew/bin/claude’, ‘/usr/local/bin/claude’, `${process.env.HOME}/.npm-global/bin/claude`, ]) { if (existsSync(p)) return p; } return null; }
callClaude.ts
const prompt = `Analyze this project and answer with JSON only (no explanation): Files: ${files} package.json excerpt: ${pkgJson} {“name”:”2-4 word English alias”,”category”:”one-word category”}`; const proc = Bun.spawn( [CLAUDE_PATH, ‘–safe-mode’, ‘-p’, ‘–model’, ‘haiku’, prompt], { stdout: ‘pipe’, stderr: ‘pipe’ } ); const timeoutId = setTimeout(() => proc.kill(), 30_000); // 30-second timeout await proc.exited; clearTimeout(timeoutId); const raw = (await new Response(proc.stdout).text()).trim(); const match = raw.match(/\{[\s\S]*\}/); if (!match) return { name: null, category: null }; const parsed = JSON.parse(match[0]);
§ 05

Three flagsWhy the prompt’s combination is safe and cheap

FlagRole
-pRun as “one question → one answer” instead of an interactive session
–safe-modeBlocks file read/write and command execution — returns pure text only, safe for handling untrusted input server-side
–model haikuThe fastest, cheapest model is plenty for lightweight tasks like name/category suggestions

Want the same thing with Codex CLI? Here are the equivalent flags. They’re not a perfect 1:1 match, so the differences are noted too.

Codex flagClaude equivalentRole · difference
exec “…”-pRun as “one prompt → one final answer” instead of an interactive session
–sandbox read-only–safe-modeBlocks writes and command execution. Codex still permits read access, though, so it’s not as fully locked down as --safe-mode — keep that in mind with untrusted input.
-o <file>Regex-parsing stdout--output-last-message writes the final answer straight to a file — no need to scrape a JSON block out of stdout with regex, which is arguably simpler.
-m <model>–model haikuPin a low-cost model for lightweight work. Exact model names change often — check codex --help or ~/.codex/config.toml.
§ 06 · Wrap-up

Reuse what you
already have.

No API key to issue, no separate SDK to install — you’re simply repurposing the Claude Code already on your machine as an “AI engine.” It’s an especially useful pattern for personal local tools, so next time you want to bolt an AI feature onto a side project, just hand it the Part B prompt.

Reusing auth you already have beats building a new API.

© 2026 · CS&NEWS · Local Tooling
NODE · BUN · CLAUDE CODE · CODEX CLI

댓글 남기기


Hey!

Hey there, fellow Robloxian! Whether you’re here to discover hidden gem games, level up your building skills, or just stay in the loop with the latest events, you’re in the right place. This blog is all about sharing the coolest things in the Roblox universe—from developer tips to epic game reviews. So grab your Bloxy Cola, hit that follow button, and let’s explore the world of Roblox together! 🚀


Join the Club

Stay updated with our latest tips and other news by joining our newsletter.


Categories

CS&NEWS에서 더 알아보기

지금 구독하여 계속 읽고 전체 아카이브에 액세스하세요.

계속 읽기