// Build autonomous coding agents with CLI integration. Use when creating automated coding workflows, managing multi-session development, or building CI/CD code generation pipelines.
| name | autonomous-coding-agent |
| description | Build autonomous coding agents with CLI integration. Use when creating automated coding workflows, managing multi-session development, or building CI/CD code generation pipelines. |
| allowed-tools | Bash, Read, Write, Grep, Glob |
Version: 1.0.0 Purpose: Build autonomous coding agents and workflows
| Trigger | Examples |
|---|---|
| Autonomous | "autonomous coding", "自律コーディング" |
| Agent | "coding agent", "コーディングエージェント" |
| Automation | "automate coding tasks", "コーディング自動化" |
Create MCP servers that can:
# Start interactive session
claude
# One-shot prompt
claude -p "explain this code"
# With specific model
claude --model claude-sonnet-4-20250514
# Print mode (no streaming)
claude --print "generate a function"
# Resume last session
claude --resume
# Continue specific session
claude --continue abc123
# Non-interactive mode
claude --no-interactive
# JSON output for parsing
claude --output-format json -p "list files"
# Stream JSON for real-time processing
claude --output-format stream-json -p "explain"
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
const server = new McpServer({ name: 'codex-connector' });
// Define tool
server.tool(
'codex_execute',
'Execute a Claude Code command',
{
prompt: { type: 'string', description: 'The prompt to execute' },
workdir: { type: 'string', description: 'Working directory' },
timeout: { type: 'number', description: 'Timeout in ms', default: 300000 }
},
async ({ prompt, workdir, timeout }) => {
const result = await executeCodex(prompt, workdir, timeout);
return { content: [{ type: 'text', text: JSON.stringify(result) }] };
}
);
import { spawn } from 'child_process';
async function executeCodex(
prompt: string,
workdir: string,
timeout: number = 300000
): Promise<CodexResult> {
return new Promise((resolve, reject) => {
const proc = spawn('claude', [
'--print',
'--output-format', 'json',
'-p', prompt
], {
cwd: workdir,
timeout,
env: { ...process.env, FORCE_COLOR: '0' }
});
let stdout = '';
let stderr = '';
proc.stdout.on('data', (data) => { stdout += data; });
proc.stderr.on('data', (data) => { stderr += data; });
proc.on('close', (code) => {
if (code === 0) {
resolve({ success: true, output: JSON.parse(stdout) });
} else {
reject(new Error(`Exit code ${code}: ${stderr}`));
}
});
proc.on('error', reject);
});
}
async function executeWithAbort(
prompt: string,
signal: AbortSignal
): Promise<CodexResult> {
const proc = spawn('claude', ['--print', '-p', prompt], {
signal // Node.js 16+ supports this
});
// ... handle output
}
class CodingSession {
private sessionId?: string;
async start(initialPrompt: string): Promise<void> {
const result = await executeCodex(initialPrompt);
this.sessionId = result.sessionId;
}
async continue(prompt: string): Promise<string> {
if (!this.sessionId) throw new Error('No session');
return executeCodex(prompt, { continue: this.sessionId });
}
async end(): Promise<void> {
// Session cleanup
this.sessionId = undefined;
}
}
- name: Run Claude Code
run: |
claude --print --output-format json \
-p "Fix the failing test in ${{ github.event.issue.body }}" \
> result.json
- name: Parse Result
run: |
jq '.result' result.json
// Sanitize user input
function sanitizePrompt(prompt: string): string {
return prompt
.replace(/[`$]/g, '') // Remove shell metacharacters
.slice(0, 10000); // Limit length
}
// Validate working directory
function validateWorkdir(dir: string): boolean {
const resolved = path.resolve(dir);
const allowed = ['/home/user/projects', '/tmp/sandbox'];
return allowed.some(a => resolved.startsWith(a));
}
try {
const result = await executeCodex(prompt, workdir);
return { success: true, ...result };
} catch (error) {
if (error.message.includes('timeout')) {
return { success: false, error: 'TIMEOUT', message: 'Execution timed out' };
}
if (error.message.includes('ENOENT')) {
return { success: false, error: 'NOT_FOUND', message: 'Claude CLI not installed' };
}
return { success: false, error: 'UNKNOWN', message: error.message };
}