Fluent, chainable TypeScript SDK: configure models, enable tools, stream events, then fetch text, JSON, run details or token stats in one call via .asText() or .allowTools('Read', 'Write'). Multi-level logging plus live onMessage/onToolUse callbacks give deep, CLI-compatible observability.
git clone https://github.com/instantlyeasy/claude-code-sdk-ts.gitFluent, chainable TypeScript SDK: configure models, enable tools, stream events, then fetch text, JSON, run details or token stats in one call via .asText() or .allowTools('Read', 'Write'). Multi-level logging plus live onMessage/onToolUse callbacks give deep, CLI-compatible observability.
[{"step":"Install the SDK and set up your project","action":"Run `npm install @anthropic-ai/claude-code-sdk-ts` in your project directory. Ensure you have a valid Anthropic API key configured in your environment variables as `ANTHROPIC_API_KEY`.","tip":"Use `tsc --init` to generate a TypeScript config if starting a new project."},{"step":"Configure the SDK for your task","action":"Set model parameters (e.g., `model`, `maxTokens`, `temperature`) and enable required tools (e.g., `Read`, `Write`, `Bash`). Chain these configurations before calling `.run()`.","tip":"Enable only the tools you need to reduce costs and improve performance. For example, omit `Bash` if you don't need shell access."},{"step":"Implement callbacks for observability","action":"Add `.onMessage()` to log streaming text and `.onToolUse()` to track tool invocations. These callbacks provide real-time feedback during execution.","tip":"Use these callbacks to update a progress bar in your CLI or write logs to a file for debugging."},{"step":"Execute your task and fetch results","action":"Call `.run()` with an async function that uses the enabled tools. Retrieve the final output with `.asText()` for text responses or `.allowTools('Read', 'Write')` to get structured tool outputs.","tip":"For complex workflows, chain multiple `.run()` calls or use the returned `tools` object to perform sequential operations."},{"step":"Analyze the results","action":"Inspect the returned object for `output`, `stats` (token usage), and `run` (execution details). Use this data to validate success or debug issues.","tip":"Log token stats to monitor API usage and costs. Compare `inputTokens` and `outputTokens` against your budget."}]
No install command available. Check the GitHub repository for manual installation instructions.
git clone https://github.com/instantlyeasy/claude-code-sdk-tsCopy the install command above and run it in your terminal.
Launch Claude Code, Cursor, or your preferred AI coding agent.
Use the prompt template or examples below to test the skill.
Adapt the skill to your specific use case and workflow.
Use the claude-code-sdk-ts to automate [TASK] in [PROJECT_PATH]. Configure the model with [MODEL_SETTINGS] and enable tools: [TOOL_LIST]. Stream events to [LOGGING_TARGET]. Fetch the final output as [OUTPUT_FORMAT] using .asText() or .allowTools('Read', 'Write'). Include token stats and run details in the response.```typescript
import { ClaudeCode } from '@anthropic-ai/claude-code-sdk-ts';
const result = await new ClaudeCode()
.configure({
model: 'claude-3-7-sonnet-20250219',
maxTokens: 4096,
temperature: 0.3,
})
.enableTools('Read', 'Write', 'Bash')
.onMessage((msg) => console.log('Streaming:', msg.text))
.onToolUse((tool) => console.log('Tool used:', tool.name))
.run(async ({ tools }) => {
await tools.Write('src/utils/helper.ts', 'export const greet = () => "Hello";');
const content = await tools.Read('src/utils/helper.ts');
return content;
})
.asText();
console.log('Output:', result.output);
console.log('Token stats:', result.stats);
console.log('Run details:', result.run);
```
**Output:**
```
Output: export const greet = () => "Hello";
Token stats: {
inputTokens: 128,
outputTokens: 45,
totalTokens: 173,
cacheCreationInputTokens: 0,
cacheReadInputTokens: 0
}
Run details: {
durationMs: 1420,
model: 'claude-3-7-sonnet-20250219',
toolsUsed: ['Write', 'Read'],
steps: 3
}
```
**Logging Output:**
```
Streaming: Starting file write operation...
Tool used: Write
Streaming: File written successfully.
Streaming: Reading file content...
Tool used: Read
Streaming: File content retrieved.
```Auto-transcribe meetings and generate action items
Unlock data insights with interactive dashboards and collaborative analytics capabilities.
Accounting software with automated invoicing and reporting
Real-time collaborative writing platform
AI assistant built for thoughtful, nuanced conversation
Automate your spreadsheet tasks with AI power
Take a free 3-minute scan and get personalized AI skill recommendations.
Take free scan