npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

ccapi-server

v0.0.6

Published

Core HTTP server that wraps Claude Code CLI as an API endpoint

Readme

ccapi-server

English

ccapi 的核心 HTTP 服务包。将 Claude Code CLI 封装为 HTTP 端点 —— 接收 prompt,在 workspace 目录中运行 Claude,返回结果。

安装

该包通常作为 ccapi-cli 的依赖使用。也可以直接编程调用:

npm install ccapi-server

编程调用

startServer(options?)

启动一个由 Claude Code 驱动的 HTTP 服务。

import { startServer } from 'ccapi-server';

startServer({
  workspaceDir: './my-workspace', // 包含 CLAUDE.md 的目录
  port: 3000,
  maxTurns: 1,
  timeoutMs: 60000,
});

也可以通过环境变量配置:

| 选项 | 环境变量 | 默认值 | | -------------- | --------------- | --------------- | | workspaceDir | WORKSPACE_DIR | .(当前目录) | | port | PORT | 3000 | | maxTurns | MAX_TURNS | 1 | | timeoutMs | TIMEOUT_MS | 60000 |

callClaude(options)

直接调用 Claude Code CLI 的底层函数。

import { callClaude } from 'ccapi-server';

const result = await callClaude({
  prompt: 'Hello World',
  cwd: './my-workspace',
  maxTurns: 1,
  timeoutMs: 60000,
});

console.log(result.result); // Claude 的回复
console.log(result.cost); // 费用(美元)
console.log(result.duration_ms); // 耗时(毫秒)

HTTP API

POST /

请求:

{ "prompt": "Hello World" }

响应:

{
  "result": "你好世界",
  "cost": 0.001,
  "duration_ms": 1234
}

GET /health

返回 { "status": "ok" }

Workspace 目录

workspaceDir 是 Claude Code 的运行目录。在该目录下放置 CLAUDE.md 来定义 Claude 的行为(系统提示词),可选放置 .claude/settings.json 来限制可用工具��

my-workspace/
├── CLAUDE.md
└── .claude/
    └── settings.json