
Security News
Deno 2.6 + Socket: Supply Chain Defense In Your CLI
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.
coding-agent-sdk
Advanced tools
Unified SDK for Claude Code, Codex CLI, and Gemini CLI - programmatic access to AI coding agents
Unified SDK for Claude Code, Codex CLI, and Gemini CLI - Programmatic access to AI coding agents with a consistent interface.
✅ Unified API - Single query() function works across all three backends
✅ Auto-detection - Automatically selects backend based on environment variables
✅ Streaming Events - Real-time event streaming with unified event schema
✅ Session Management - Resume previous sessions across all backends
✅ TypeScript - Full type definitions included
✅ Zero Config - Works out of the box with sensible defaults
npm install coding-agent-sdk
Each backend requires its CLI to be installed globally:
# For Claude Code
# Install from https://claude.com/code
# Verify: claude --version
# For Codex CLI
npm install -g @openai/codex
# Or: brew install --cask codex
# Verify: codex --version
# For Gemini CLI
# Install from https://github.com/google-gemini/gemini-cli
# Verify: gemini --version
Important: The SDK spawns CLI processes directly (claude, codex, gemini). Make sure the binaries are in your PATH.
The SDK auto-detects which backend to use based on environment variables:
# Use Claude Code
export ANTHROPIC_API_KEY=your_anthropic_key
# Use Codex CLI
export CODEX_API_KEY=your_codex_key
# Use Gemini CLI
export GEMINI_API_KEY=your_gemini_key
import { query } from 'coding-agent-sdk';
// Auto-detects backend from environment variables
const result = await query("Fix the failing tests");
// Stream events
for await (const event of result.events) {
if (event.type === 'message') {
console.log(`[${event.role}]:`, event.content);
}
}
console.log('Session ID:', result.sessionId);
console.log('Backend used:', result.backend);
import { query } from 'coding-agent-sdk';
const result = await query("Deploy the application", {
backend: 'claude',
workingDir: '/path/to/project',
});
import { query } from 'coding-agent-sdk';
// Initial query
const result1 = await query("Start implementing the feature");
const sessionId = result1.sessionId;
// Resume later
const result2 = await query("Continue from where we left off", {
resume: sessionId,
});
The SDK provides 7 unified event types that work across all backends:
{
type: 'session',
subtype: 'init' | 'end',
session_id: string,
backend: 'claude' | 'codex' | 'gemini',
timestamp?: string,
metadata?: { ... }
}
{
type: 'turn',
subtype: 'started' | 'completed' | 'failed',
usage?: {
input_tokens?: number,
output_tokens?: number,
cached_tokens?: number,
thinking_tokens?: number,
},
error?: string
}
{
type: 'message',
role: 'user' | 'assistant',
content: string,
is_delta?: boolean, // True for streaming chunks
content_index?: number, // For multi-block messages
parent_id?: string // For subagent messages
}
{
type: 'action',
subtype: 'tool' | 'command' | 'file_change' | 'web_search' | 'reasoning' | 'mcp_tool',
action_id?: string,
status: 'started' | 'in_progress' | 'completed' | 'failed',
// Tool-specific fields
tool_name?: string,
tool_input?: unknown,
tool_output?: unknown,
// Command-specific fields
command?: string,
command_output?: string,
exit_code?: number,
// File change-specific fields
file_path?: string,
change_type?: 'add' | 'update' | 'delete',
// And more...
}
{
type: 'progress',
subtype: 'todo_update' | 'status_update' | 'elapsed_time',
todo_items?: Array<{ title: string, status: string }>,
status_message?: string,
elapsed_ms?: number
}
{
type: 'error',
severity: 'warning' | 'error' | 'fatal',
message: string,
related_action_id?: string
}
{
type: 'metrics',
subtype: 'usage_update' | 'session_summary',
per_model?: Record<string, { ... }>,
per_tool?: Record<string, { ... }>,
files?: { ... }
}
Each backend supports custom configuration:
import { query } from 'coding-agent-sdk';
const result = await query("Complex task", {
backend: 'claude',
backendOptions: {
claude: {
maxThinkingTokens: 10000,
mcpServers: ['next-devtools-mcp'],
permissionMode: 'prompt', // Override default YOLO mode
},
},
});
import { query } from 'coding-agent-sdk';
const result = await query("Refactor the codebase");
for await (const event of result.events) {
// Only show assistant messages
if (event.type === 'message' && event.role === 'assistant') {
console.log(event.content);
}
// Track tool usage
if (event.type === 'action' && event.subtype === 'tool') {
console.log(`Tool: ${event.tool_name} (${event.status})`);
}
// Monitor errors
if (event.type === 'error') {
console.error(`[${event.severity}]`, event.message);
}
}
import { query } from 'coding-agent-sdk';
const result = await query("Analyze the project");
// Collect all events
const events: UnifiedEvent[] = [];
for await (const event of result.events) {
events.push(event);
}
// Process collected events
const messages = events.filter(e => e.type === 'message');
const actions = events.filter(e => e.type === 'action');
console.log(`Total messages: ${messages.length}`);
console.log(`Total actions: ${actions.length}`);
query(prompt, options?)Main function to query AI coding agents.
Parameters:
prompt: string - The prompt to send to the agentoptions?: QueryOptions - Optional configurationReturns: Promise<QueryResult>
QueryOptionsinterface QueryOptions {
backend?: 'claude' | 'codex' | 'gemini'; // Auto-detected if not specified
resume?: string; // Session ID to resume
workingDir?: string; // Working directory (default: cwd)
autoApprove?: boolean; // YOLO mode (default: true)
backendOptions?: {
claude?: ClaudeBackendOptions;
codex?: CodexBackendOptions;
gemini?: GeminiBackendOptions;
};
}
QueryResultinterface QueryResult {
sessionId: string; // Session ID for resumption
events: AsyncGenerator<UnifiedEvent>; // Event stream
backend: 'claude' | 'codex' | 'gemini'; // Backend used
}
isBackendAvailable(backend)Check if a specific backend is available.
import { isBackendAvailable } from 'coding-agent-sdk';
if (isBackendAvailable('claude')) {
console.log('Claude is available!');
}
| Feature | Claude Code | Codex CLI | Gemini CLI |
|---|---|---|---|
| Installation | https://claude.com/code | npm i -g @openai/codex | https://github.com/google-gemini/gemini-cli |
| Binary | claude | codex | gemini |
| API Key Env | ANTHROPIC_API_KEY | CODEX_API_KEY | GEMINI_API_KEY |
| Output Format | --output-format stream-json | --experimental-json | --output-format stream-json |
| Session Resume | ✅ --resume | ✅ resume arg | ✅ --resume |
| MCP Support | ✅ | ✅ | ✅ |
| Extended Thinking | ✅ | ✅ | ❌ |
| Structured Output | ❌ | ✅ | ❌ |
| Web Search | ✅ | ✅ | ❌ |
| Todo Tracking | ❌ | ✅ | ❌ |
import { query, BackendNotAvailableError, NoBackendFoundError } from 'coding-agent-sdk';
try {
const result = await query("Deploy the app");
for await (const event of result.events) {
if (event.type === 'error') {
console.error(`Error: ${event.message}`);
}
}
} catch (error) {
if (error instanceof NoBackendFoundError) {
console.error('No API key found. Set ANTHROPIC_API_KEY, CODEX_API_KEY, or GEMINI_API_KEY');
} else if (error instanceof BackendNotAvailableError) {
console.error(`Backend ${error.backend} is not available: ${error.message}`);
} else {
console.error('Unexpected error:', error);
}
}
import { query } from 'coding-agent-sdk';
const result = await query("Add type annotations to all functions");
for await (const event of result.events) {
if (event.type === 'message' && event.role === 'assistant') {
console.log(event.content);
}
}
import { query } from 'coding-agent-sdk';
const result = await query("Refactor the authentication module");
for await (const event of result.events) {
if (event.type === 'progress' && event.subtype === 'todo_update') {
console.log('Todo List:');
event.todo_items?.forEach(todo => {
console.log(` [${todo.status}] ${todo.title}`);
});
}
}
import { query } from 'coding-agent-sdk';
const result = await query("Optimize database queries");
for await (const event of result.events) {
if (event.type === 'turn' && event.subtype === 'completed') {
console.log('Token Usage:', event.usage);
}
}
The SDK includes a comprehensive test suite with >95% coverage.
# Run all tests
npm test
# Watch mode for development
npm run test:watch
# Generate coverage report
npm run test:coverage
src/**/*.test.ts - Unit and integration testsCurrent test coverage: 95%+
Contributions are welcome! Please open an issue or submit a pull request.
Before submitting a PR:
npm test to ensure all tests passnpm run test:coverage to verify coverage remains highnpm run build to ensure the build succeedsMIT
FAQs
Build agentic workflows that delegate to your users' existing coding agents (Claude Code, Codex, Gemini).
The npm package coding-agent-sdk receives a total of 8 weekly downloads. As such, coding-agent-sdk popularity was classified as not popular.
We found that coding-agent-sdk demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Deno 2.6 introduces deno audit with a new --socket flag that plugs directly into Socket to bring supply chain security checks into the Deno CLI.

Security News
New DoS and source code exposure bugs in React Server Components and Next.js: what’s affected and how to update safely.

Security News
Socket CEO Feross Aboukhadijeh joins Software Engineering Daily to discuss modern software supply chain attacks and rising AI-driven security risks.