# Claude Code X - Autonomous Claude Code Executor
**Version**: 1.0.0
**Purpose**: Run Claude Code autonomously in background (like Codex X)
---
## 🎯 Overview
Claude Code Xは、Codex Xと同じインターフェースでClaude Codeをバックグラウンド実行するツールです。
### Codex X vs Claude Code X
| Feature | Codex X | Claude Code X |
|---------|---------|---------------|
| **Model** | GPT-5 Codex/o3 | Claude Sonnet 4.5 |
| **Speed** | 遅い (6分+) | 速い (1-2分) |
| **Quality** | バグゼロ | 高品質 (修正1回程度) |
| **Interactive** | ❌ | ✅ (別セッション) |
| **Session Resume** | ✅ `--continue` | ✅ (計画中) |
---
## 📋 Usage
### Basic Execution
```bash
/claude-code-x exec "Task description"
```
**Example**:
```bash
/claude-code-x exec "Implement a new feature: user authentication with JWT tokens"
```
### With Options
```bash
/claude-code-x exec "Task" --allowed-tools "Bash,Read,Write,Edit" --timeout 600
```
### Session Management
```bash
# List active sessions
/claude-code-x sessions
# Resume a session
/claude-code-x continue <session-id>
# Kill a session
/claude-code-x kill <session-id>
```
---
## 🔧 Implementation
Claude Code Xは以下のコマンドを内部で実行します:
```bash
claude -p "<task>" \
--allowedTools "Bash,Read,Write,Edit,Glob,Grep" \
--permission-mode acceptEdits \
> /tmp/claude-code-x-<session-id>.log 2>&1 &
```
### Session ID Format
`claude-code-x-<timestamp>-<random>`
例: `claude-code-x-20251027-a1b2c3`
---
## 📊 Comparison Test Results
**Test Date**: 2025-10-27
### Task: String Utils Implementation (191 lines)
| Metric | Claude Code | Codex X | Claude Code X (Estimated) |
|--------|-------------|---------|---------------------------|
| **Time** | 1m46s | 6m16s+ (timeout) | ~2m (estimated) |
| **Quality** | ✅ 100% | ✅ 90% (lib.rs未更新) | ✅ 100% (expected) |
| **Interactive** | ✅ Yes | ❌ No | ❌ No (別セッション) |
| **Bugs** | 1 (fixed) | 0 | 1-2 (expected) |
---
## 🚀 Optimal Workflow
### Hybrid Strategy: Claude Code + Claude Code X
```bash
# Main session: Planning & Orchestration (Current Claude Code)
> "Let's implement Feature X. First, plan the tasks..."
# Background execution: Autonomous implementation (Claude Code X)
> /claude-code-x exec "Implement Feature X based on plan"
# While Claude Code X runs in background, continue main work
> "Now let's work on Feature Y..."
# Check Claude Code X status
> /claude-code-x status
# Review results when ready
> /claude-code-x result <session-id>
```
### Benefits
1. **並列実行**: メインセッションとバックグラウンド実行を同時進行
2. **高速**: Codex Xの3倍速(1m46s vs 6m16s+)
3. **対話的**: メインセッションで修正・確認可能
4. **完全自律**: Claude Code Xは独立して実行
---
## 📝 Slash Command Implementation
```bash
#!/bin/bash
# .claude/commands/claude-code-x.sh
COMMAND="$1"
shift
case "$COMMAND" in
exec)
TASK="$1"
SESSION_ID="claude-code-x-$(date +%Y%m%d)-$(openssl rand -hex 3)"
LOG_FILE="/tmp/${SESSION_ID}.log"
echo "🚀 Starting Claude Code X session: $SESSION_ID"
claude -p "$TASK" \
--allowedTools "Bash,Read,Write,Edit,Glob,Grep" \
--permission-mode acceptEdits \
> "$LOG_FILE" 2>&1 &
echo "$!" > "/tmp/${SESSION_ID}.pid"
echo "📝 Log file: $LOG_FILE"
echo "🔗 Session ID: $SESSION_ID"
;;
sessions)
echo "📋 Active Claude Code X sessions:"
ls /tmp/claude-code-x-*.pid 2>/dev/null | while read pidfile; do
SESSION_ID=$(basename "$pidfile" .pid)
PID=$(cat "$pidfile")
if kill -0 "$PID" 2>/dev/null; then
echo " ✅ $SESSION_ID (PID: $PID) - Running"
else
echo " ❌ $SESSION_ID (PID: $PID) - Stopped"
fi
done
;;
status)
SESSION_ID="$1"
LOG_FILE="/tmp/${SESSION_ID}.log"
echo "📊 Status for $SESSION_ID:"
tail -20 "$LOG_FILE"
;;
result)
SESSION_ID="$1"
LOG_FILE="/tmp/${SESSION_ID}.log"
echo "📄 Full output for $SESSION_ID:"
cat "$LOG_FILE"
;;
kill)
SESSION_ID="$1"
PID_FILE="/tmp/${SESSION_ID}.pid"
if [ -f "$PID_FILE" ]; then
PID=$(cat "$PID_FILE")
kill "$PID" 2>/dev/null && echo "🛑 Killed session $SESSION_ID (PID: $PID)"
rm "$PID_FILE"
else
echo "❌ Session $SESSION_ID not found"
fi
;;
*)
echo "Usage: /claude-code-x {exec|sessions|status|result|kill}"
;;
esac
```
---
## 🎓 Codex Session Resume Feature
Codex Xの`--continue`機能と同等の機能を実装予定:
```bash
# Codex X (existing)
codex exec --continue <session-id> "Additional instruction"
# Claude Code X (planned)
/claude-code-x continue <session-id> "Additional instruction"
```
### Implementation Plan
1. セッションID管理
2. ログファイル保存
3. `claude -p --resume <log-file>`オプション(要確認)
---
## 📚 References
- **Benchmark Report**: `.ai/logs/claude-code-vs-codex-x-benchmark.md`
- **Integration Guide**: `docs/CODEX_X_CLAUDE_CODE_INTEGRATION.md`
- **Role Separation**: `docs/CLAUDE_CODE_CODEX_X_ROLE_SEPARATION.md`
- **Codex X Docs**: `.claude/commands/codex.md`
---
**Author**: Claude Code (Sonnet 4.5)
**Test Date**: 2025-10-27
**Status**: ✅ Proven Concept (`claude -p` works!)