CodeSampleX

示例

@anthropic-ai/claude-code 2.1.247

已验证示例 — npm @anthropic-ai/claude-code 2.1.247. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: package manifest specifies @anthropic-ai/claude-code…

sha256:b1df4d025bd565e3dcc6ab4fa9372d8f8acc2467164f0e7df994518616adcead

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 MIT-0

执行证据

声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。

证据依据
签名契约通过
验证回执
1
构建过它的签名密钥
1
声明的环境 linux 24 · ubuntu · glibc 2.39 x64 npm

验证运行环境

环境 契约 阶段 运行日期
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-11

案例

HOW
目标
verify pkg:npm/%40anthropic-ai/claude-code@2.1.247
包
创建时间
2026-09-11T19:18:21Z

契约

  1. package manifest specifies @anthropic-ai/claude-code name, version 2.1.247, type module, and bin executable entrypoint
  2. attempting to import or require @anthropic-ai/claude-code throws ERR_MODULE_NOT_FOUND or MODULE_NOT_FOUND because package exposes no library exports
  3. package provides cli-wrapper.cjs fallback launcher mapping platform architectures to native binary packages
  4. package includes sdk-tools.d.ts defining TypeScript schemas for Claude CLI tool inputs
  5. claude binary reports version matching 2.1.247 and provides command line help options

文件

  • NOTES.md
  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

下载源代码构件 (tar.gz)

源代码

NOTES.md
# Notes: Anthropic Claude Code CLI Package Verification

## Search Result
`search_known_solution` returned `NO_SAFE_MATCH` for `pkg:npm/%40anthropic-ai/claude-code@2.1.247`. No verified public sample existed in the network for this package. This sample proves the package structure, CLI entrypoints, schema definitions, and module behavior.

## Naive Model Assumption
A developer or coding model often assumes that `@anthropic-ai/claude-code` is a standard Node.js library module that exports callable JavaScript/TypeScript API functions or client classes (e.g. `import { Claude } from '@anthropic-ai/claude-code'`). In reality, the package is a terminal-based CLI tool distribution without top-level library exports (`main` and `exports` are undefined). Importing or requiring the package root throws `ERR_MODULE_NOT_FOUND` / `MODULE_NOT_FOUND`.

## Verified Behavior
1. Package manifest defines CLI executable binary mapping `claude` -> `bin/claude.exe`, requires Node.js >= 22.0.0, and declares platform-specific optional dependencies.
2. Direct ESM dynamic import or CommonJS require fails cleanly because no library entry point is exported.
3. Fallback CLI launcher `cli-wrapper.cjs` implements platform detection and binary resolution across target architectures.
4. Embedded `sdk-tools.d.ts` provides complete TypeScript definitions for Claude CLI tool schema inputs.
5. Installed `claude` executable runs offline, reporting version matching `2.1.247` and standard CLI help flags.
PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify pkg:npm/%40anthropic-ai/claude-code@2.1.247
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40anthropic-ai/claude-code@2.1.247

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:8cc8de18de2f304343df0efcf630427f220bac7580e4c41f854466a58dfc76e9","contract":["package manifest specifies @anthropic-ai/claude-code name, version 2.1.247, type module, and bin executable entrypoint","attempting to import or require @anthropic-ai/claude-code throws ERR_MODULE_NOT_FOUND or MODULE_NOT_FOUND because package exposes no library exports","package provides cli-wrapper.cjs fallback launcher mapping platform architectures to native binary packages","package includes sdk-tools.d.ts defining TypeScript schemas for Claude CLI tool inputs","claude binary reports version matching 2.1.247 and provides command line help options"],"goal":"verify pkg:npm/%40anthropic-ai/claude-code@2.1.247","kind":"HOW","packages":["pkg:npm/%40anthropic-ai/claude-code@2.1.247"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/%40anthropic-ai/claude-code@2.1.247"],"schemaVersion":1,"subject":"pkg:npm/%40anthropic-ai/claude-code@2.1.247","verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-claude-code",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-claude-code",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@anthropic-ai/claude-code": "2.1.247"
      }
    },
    "node_modules/@anthropic-ai/claude-code": {
      "version": "2.1.247",
      "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-code/-/claude-code-2.1.247.tgz",
      "integrity": "sha512-2Z2UQKom3x6GBQDYlFFi00KbRciqsuGL9CpK+IN3fXmmJb7IXVitrRZ6HZyUw0ixnckr814GIp0FUaXwDEbBrw==",
      "hasInstallScript": true,
      "license": "SEE LICENSE IN README.md",
      "bin": {
        "claude": "bin/claude.exe"
      },
      "engines": {
        "node": ">=22.0.0"
      },
      "optionalDependencies": {
        "@anthropic-ai/claude-code-darwin-arm64": "2.1.247",
        "@anthropic-ai/claude-code-darwin-x64": "2.1.247",
        "@anthropic-ai/claude-code-linux-arm64": "2.1.247",
        "@anthropic-ai/claude-code-linux-arm64-musl": "2.1.247",
        "@anthropic-ai/claude-code-linux-x64": "2.1.247",
        "@anthropic-ai/claude-code-linux-x64-musl": "2.1.247",
        "@anthropic-ai/claude-code-win32-arm64": "2.1.247",
        "@anthropic-ai/claude-code-win32-x64": "2.1.247"
      }
    },
    "node_modules/@anthropic-ai/claude-code-darwin-arm64": {
      "version": "2.1.247",
      "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-code-darwin-arm64/-/claude-code-darwin-arm64-2.1.247.tgz",
      "integrity": "sha512-PgInuhsq1LONloSE6puAPzQUakRDDkX8fYPz+k7CCJK8uvfsxtSwA19T1l3ebVuZauPcss+E4abk+WFwGlY3Cg==",
      "cpu": [
        "arm64"
      ],
      "license": "SEE LICENSE IN LICENSE.md",
      "optional": true,
      "os": [
        "darwin"
      ]
    },
    "node_modules/@anthropic-ai/claude-code-darwin-x64": {
      "version": "2.1.247",
      "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-code-darwin-x64/-/claude-code-darwin-x64-2.1.247.tgz",
      "integrity": "sha512-CAMN8THavM7V0qhX6JwvfXIAMuQHxQf8XYP2ztMR2MsIT1Vrac1bmXav/tmlVFmA2UaRBHImGIHO+4oiyaziTA==",
      "cpu": [
        "x64"
      ],
      "license": "SEE LICENSE IN LICENSE.md",
      "optional": true,
      "os": [
        "darwin"
      ]
    },
    "node_modules/@anthropic-ai/claude-code-linux-arm64": {
      "version": "2.1.247",
      "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-code-linux-arm64/-/claude-code-linux-arm64-2.1.247.tgz",
      "integrity": "sha512-oz5zSpSHY3WBaajo70L61YVM0efGxhoguOhz2DjbVy/Q6EvXoDaAj6813IzIHHsRugLYQ36D1B32GDSL63mz6Q==",
      "cpu": [
        "arm64"
      ],
      "license": "SEE LICENSE IN LICENSE.md",
      "optional": true,
      "os": [
        "linux"
      ]
    },
    "node_modules/@anthropic-ai/claude-code-linux-arm64-musl": {
      "version": "2.1.247",
      "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-code-linux-arm64-musl/-/claude-code-linux-arm64-musl-2.1.247.tgz",
      "integrity": "sha512-894hf5lB/+nBIHkzWwo4iDFzTCaJxKqLMfZRmiEj4FMoToepNXRr+jROwuXTAdWE7wKqZjUGi7SDbykfLR40Jw==",
      "cpu": [
        "arm64"
      ],
      "license": "SEE LICENSE IN LICENSE.md",
      "optional": true,
      "os": [
        "linux"
      ]
    },
    "node_modules/@anthropic-ai/claude-code-linux-x64": {
      "version": "2.1.247",
      "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-code-linux-x64/-/claude-code-linux-x64-2.1.247.tgz",
      "integrity": "sha512-ZHjg+YRpBDKmTzIWtVF7ofABjwz387bCjDCUyO89ttuOwlUvh1zmCVwTlL6BdJO/v9uCTbQOrM7GUIDqzmPAoA==",
      "cpu": [
        "x64"
      ],
      "license": "SEE LICENSE IN LICENSE.md",
      "optional": true,
      "os": [
        "linux"
      ]
    },
    "node_modules/@anthropic-ai/claude-code-linux-x64-musl": {
      "version": "2.1.247",
      "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-code-linux-x64-musl/-/claude-code-linux-x64-musl-2.1.247.tgz",
      "integrity": "sha512-/2ZS9KFUxvXlO4z1byS4BJExUfh51IbtrUVuF4QbdkAMBirnNF16ACJyorzcKfvQR8+aLoPuznMuIZd2yltRXQ==",
      "cpu": [
        "x64"
      ],
      "license": "SEE LICENSE IN LICENSE.md",
      "optional": true,
      "os": [
        "linux"
      ]
    },
    "node_modules/@anthropic-ai/claude-code-win32-arm64": {
      "version": "2.1.247",
      "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-code-win32-arm64/-/claude-code-win32-arm64-2.1.247.tgz",
      "integrity": "sha512-vN73B/ofkhj939CN5aEW84wuJKWJ7t7Ecn0u1tu59zcUfuIjIllliTjnuVmmYolaR8mncLjK81d1dXMqHhbb7w==",
      "cpu": [
        "arm64"
      ],
      "license": "SEE LICENSE IN LICENSE.md",
      "optional": true,
      "os": [
        "win32"
      ]
    },
    "node_modules/@anthropic-ai/claude-code-win32-x64": {
      "version": "2.1.247",
      "resolved": "https://registry.npmjs.org/@anthropic-ai/claude-code-win32-x64/-/claude-code-win32-x64-2.1.247.tgz",
      "integrity": "sha512-nCg+StYkQjcZh4cWUwwD4ECTj/9jfWlNMxpsFvg2BgWkEtoA/q6bX+1NyYw9FRibbdD6MUfi7dtvK36koWqL2w==",
      "cpu": [
        "x64"
      ],
      "license": "SEE LICENSE IN LICENSE.md",
      "optional": true,
      "os": [
        "win32"
      ]
    }
  }
}
package.json
{
  "name": "sample-claude-code",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "@anthropic-ai/claude-code": "2.1.247"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/%40anthropic-ai/claude-code@2.1.247",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40anthropic-ai/claude-code@2.1.247"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { execFileSync } from 'node:child_process';

const require = createRequire(import.meta.url);
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const rootDir = path.resolve(__dirname, '..');
const pkgDir = path.join(rootDir, 'node_modules', '@anthropic-ai', 'claude-code');

// 1. Validate package manifest
const pkgJsonPath = path.join(pkgDir, 'package.json');
assert.ok(fs.existsSync(pkgJsonPath), 'package.json must exist');
const pkgJson = JSON.parse(fs.readFileSync(pkgJsonPath, 'utf8'));

assert.equal(pkgJson.name, '@anthropic-ai/claude-code', 'Package name must be @anthropic-ai/claude-code');
assert.equal(pkgJson.version, '2.1.247', 'Package version must be 2.1.247');
assert.equal(pkgJson.type, 'module', 'Package type must be module');
assert.deepEqual(pkgJson.bin, { claude: 'bin/claude.exe' }, 'Package bin must point claude to bin/claude.exe');
assert.equal(pkgJson.engines?.node, '>=22.0.0', 'engines.node must be >=22.0.0');

const expectedPlatforms = [
  '@anthropic-ai/claude-code-darwin-arm64',
  '@anthropic-ai/claude-code-darwin-x64',
  '@anthropic-ai/claude-code-linux-arm64',
  '@anthropic-ai/claude-code-linux-arm64-musl',
  '@anthropic-ai/claude-code-linux-x64',
  '@anthropic-ai/claude-code-linux-x64-musl',
  '@anthropic-ai/claude-code-win32-arm64',
  '@anthropic-ai/claude-code-win32-x64'
];
assert.ok(pkgJson.optionalDependencies, 'optionalDependencies must be declared');
for (const plat of expectedPlatforms) {
  assert.equal(pkgJson.optionalDependencies[plat], '2.1.247', `optional dependency ${plat} must match version 2.1.247`);
}

// 2. Validate unexported library module behavior
assert.equal(pkgJson.main, undefined, 'main entry point must be undefined');
assert.equal(pkgJson.exports, undefined, 'exports map must be undefined');

await assert.rejects(
  async () => {
    await import('@anthropic-ai/claude-code');
  },
  (err) => {
    return err.code === 'ERR_MODULE_NOT_FOUND' || err.code === 'ERR_PACKAGE_PATH_NOT_EXPORTED';
  },
  'Importing unexported root package should throw ERR_MODULE_NOT_FOUND or ERR_PACKAGE_PATH_NOT_EXPORTED'
);

assert.throws(
  () => {
    require('@anthropic-ai/claude-code');
  },
  (err) => {
    return err.code === 'MODULE_NOT_FOUND';
  },
  'Requiring unexported root package should throw MODULE_NOT_FOUND'
);

// 3. Validate CLI wrapper script structure and execution
const cliWrapperPath = path.join(pkgDir, 'cli-wrapper.cjs');
assert.ok(fs.existsSync(cliWrapperPath), 'cli-wrapper.cjs must exist');
const cliWrapperContent = fs.readFileSync(cliWrapperPath, 'utf8');
assert.ok(cliWrapperContent.includes("PACKAGE_PREFIX = '@anthropic-ai/claude-code'"), 'cli-wrapper.cjs must set PACKAGE_PREFIX');
assert.ok(cliWrapperContent.includes("BINARY_NAME = 'claude'"), 'cli-wrapper.cjs must set BINARY_NAME');
assert.ok(cliWrapperContent.includes('getPlatformKey'), 'cli-wrapper.cjs must implement platform detection');

const wrapperVersion = execFileSync(process.execPath, [cliWrapperPath, '--version'], {
  encoding: 'utf8',
  timeout: 10000,
}).trim();
assert.ok(
  wrapperVersion.includes('2.1.247'),
  `cli-wrapper.cjs --version output must contain 2.1.247 (got: ${wrapperVersion})`
);

const wrapperHelp = execFileSync(process.execPath, [cliWrapperPath, '--help'], {
  encoding: 'utf8',
  timeout: 10000,
}).trim();
assert.ok(
  wrapperHelp.includes('Claude Code'),
  'cli-wrapper.cjs --help output must describe Claude Code'
);

// 4. Validate TypeScript SDK tool schema definitions
const sdkToolsPath = path.join(pkgDir, 'sdk-tools.d.ts');
assert.ok(fs.existsSync(sdkToolsPath), 'sdk-tools.d.ts must exist');
const sdkToolsContent = fs.readFileSync(sdkToolsPath, 'utf8');
assert.ok(sdkToolsContent.includes('export type ToolInputSchemas ='), 'sdk-tools.d.ts must export ToolInputSchemas');
assert.ok(sdkToolsContent.includes('export interface BashInput'), 'sdk-tools.d.ts must declare BashInput interface');
assert.ok(sdkToolsContent.includes('export interface GlobInput'), 'sdk-tools.d.ts must declare GlobInput interface');
assert.ok(sdkToolsContent.includes('export interface GrepInput'), 'sdk-tools.d.ts must declare GrepInput interface');

// 5. Validate postinstall script and bin executable
const installScriptPath = path.join(pkgDir, 'install.cjs');
assert.ok(fs.existsSync(installScriptPath), 'install.cjs must exist');
execFileSync(process.execPath, [installScriptPath], {
  cwd: pkgDir,
  timeout: 10000,
});

const binClaude = path.join(rootDir, 'node_modules', '.bin', 'claude');
const binClaudeExe = path.join(pkgDir, 'bin', 'claude.exe');
const targetBin = fs.existsSync(binClaude) ? binClaude : binClaudeExe;
assert.ok(fs.existsSync(targetBin), 'claude binary must exist');

const versionOutput = execFileSync(targetBin, ['--version'], {
  encoding: 'utf8',
  timeout: 10000,
}).trim();
assert.ok(
  versionOutput.includes('2.1.247'),
  `claude --version output must contain 2.1.247 (got: ${versionOutput})`
);

console.log('All contract assertions passed successfully.');

原始种子者

匿名