coding-agent-sdk
Build agentic workflows that delegate to your users' existing coding agentsâClaude Code, Codex, or Gemini.
import { query } from 'coding-agent-sdk';
await query("Refactor the auth module");
Overview
This SDK enables you to build agentic workflows (code reviewers, migration tools, testing assistants) that leverage coding agents your users already have installed. Instead of embedding your own agent, delegate tasks to the user's existing setupâwhether that's Claude Code, Codex, or Gemini.
async function migrateToTypeScript() {
await query("Find all .js files in src/");
await query("Convert them to TypeScript");
await query("Fix any type errors");
await query("Run the test suite");
}
The SDK handles:
- Auto-detection of available agents (Claude, Codex, or Gemini)
- Translation of requests into the appropriate format
- Unified event streaming across different agents
- Single API that works with all supported agents
Benefits
For workflow builders:
- Users already have the agent installed
- No API costsâruns on the user's credentials
- No vendor lock-inâsupports multiple agents
- Focus on workflow logic instead of agent implementation
For users:
- Leverage agents they already use
- Works with Claude, Codex, or Gemini
- Maintains their existing setup and preferences
- No additional subscriptions or API keys
How It Works
Install the SDK:
npm install coding-agent-sdk
â ď¸ Important: Auto-Approval Mode
By default, the SDK runs in "YOLO mode" (auto-approve enabled), which means coding agents will automatically execute actions without asking for your permission. This is designed for workflow automation but means tools will run, files will be modified, and commands will be executed automatically.
If you need to control approvals, you can configure the approval policy through the underlying CLI tools.
Build your workflow:
import { query } from 'coding-agent-sdk';
const result = await query("Deploy the application");
for await (const event of result.events) {
if (event.type === 'message') {
console.log(event.content);
}
}
Your user runs it with their existing agent:
The SDK:
- Auto-detects which agent they have
- Spawns the right CLI process
- Parses the output into unified events
- Returns a clean stream you can work with
The API
One function. That's it.
query(prompt: string, options?: QueryOptions): Promise<QueryResult>
Parameters:
prompt - What you want the agent to do
options - Optional backend, session resume, working directory
Returns:
sessionId - Resume the conversation later
events - Async generator of unified events
backend - Which agent was used
Example:
import { query } from 'coding-agent-sdk';
const result = await query("Add error handling to the API routes");
for await (const event of result.events) {
switch (event.type) {
case 'message':
case 'action':
case 'progress':
case 'turn':
case 'session':
case 'error':
case 'metrics':
}
}
Real-World Example
Here's a code review workflow that works with any agent:
import { query } from 'coding-agent-sdk';
async function reviewPullRequest(prNumber: number) {
const diffResult = await query(`Get the git diff for PR #${prNumber}`);
const reviewResult = await query(
`Review this code for:
- Security vulnerabilities
- Performance issues
- Best practices
- Test coverage`
);
await query("Suggest specific improvements with code examples");
}
Your users run this with Claude, Codex, or Gemini. Same workflow. Zero changes.
Use Cases
This SDK is designed for building reusable workflows that delegate to existing agents:
- Code migration tools (e.g., "Convert this repo from JS to TS")
- Automated reviewers (e.g., "Review this PR for security issues")
- Testing assistants (e.g., "Generate e2e tests for this feature")
- Deployment orchestrators (e.g., "Deploy to staging and run smoke tests")
The SDK provides a unified interface across different agents, letting you focus on workflow orchestration rather than agent-specific implementation details.
Supported Agents
| Claude Code | claude | ANTHROPIC_API_KEY |
| OpenAI Codex | codex | OPENAI_API_KEY |
| Google Gemini | gemini | GEMINI_API_KEY |
The SDK auto-detects which one is available. Your workflow just works.
Installation
npm install coding-agent-sdk
Your users need:
- One of the supported CLIs installed (Claude Code, Codex, or Gemini)
- The corresponding API key in their environment
That's it. No SDK API keys. No additional setup.
Advanced Usage
Resume Sessions
const result1 = await query("Start the refactor");
const sessionId = result1.sessionId;
const result2 = await query("Continue", { resume: sessionId });
Specify Backend
await query("Deploy", {
backend: 'claude',
workingDir: '/path/to/project'
});
Stream Progress
const result = await query("Migrate to TypeScript");
for await (const event of result.events) {
if (event.type === 'progress' && event.todo_items) {
console.log(`Progress: ${event.todo_items.filter(t => t.status === 'completed').length}/${event.todo_items.length} tasks done`);
}
}
Monitor Actions
const result = await query("Deploy to production");
for await (const event of result.events) {
if (event.type === 'action' && event.subtype === 'tool') {
console.log(`Action: ${event.tool_name} - ${event.status}`);
}
}
See It In Action
Want to see the magic? Run this:
npx coding-agent-sdk -p "List all TypeScript files"
The SDK will:
- Auto-detect which agent you have installed (Claude, Codex, or Gemini)
- Delegate the task to that agent
- Stream back the results
No configuration. No setup. It just works.
The real value is the query() API for building workflows, but this shows you how it automatically detects and delegates to whatever agent your users have.
Contributing
We're building the interface layer between workflows and agents. PRs welcome.
npm test
npm run build
License
MIT
GitHub ⢠NPM