# Claude Code Touchpoints in InfiniBot

> Generated: 2026-05-26 — branch feat/opencode-swappable-backend  
> Purpose: Drive the CoderBackend abstraction. Every site listed here is a candidate for routing through the factory.

---

## 1. Direct Spawn / Exec Calls

| File | Lines | Role |
|---|---|---|
| `src/agents/claude-code/launcher.ts` | 234, 342, 500, 533 | Core launcher — `spawnClaudeCodeAgent`, `spawnClaudeCodeAgentBackground`, `runClaudeCodeWithMCPs`, `runClaudeCodeWithMCPsBackground`. **Primary refactor target.** |
| `src/agents/tools/claude-coder-tool.ts` | 29–30, 404, 560 | Imports and calls both sync + background launchers. **Routes through registry after refactor.** |
| `src/design/runner.ts` | 16, 156 | Calls `runClaudeCodeWithMCPsBackground` for design artifact generation. **Routes through registry after refactor.** |
| `src/gateway/server-voice-stream.ts` | 16, 207, 209, 436, 444 | Imports `createClaudeCoderTool`; voice-mode route dispatching. No direct spawn — routes through tool. |
| `src/agents/cli-backends.ts` | 30, 35 | `--dangerously-skip-permissions` in CLI backend args. Low-level; untouched by abstraction. |
| `src/terminal/agent-cli-integration-handler.ts` | 17, 99 | `DANGEROUSLY_SKIP_PERMISSIONS_FLAG` constant. Unchanged — terminal integration. |

---

## 2. Config / Settings References

| File | Lines | Role |
|---|---|---|
| `src/agents/types/agent-types.ts` | 51 | `CLIAgentConfig.autoApprove` (maps to `--dangerously-skip-permissions`). Shared by both backends. |
| `src/config/types.infinibot.ts` | 265–274 | `claudeCoder.skillSystem` config block. **Extended with `coder.backend` in this PR.** |
| `src/config/paths.ts` | 67 | Comment re workspace dir for claude_coder spawns. Unchanged. |
| `src/gateway/server-startup.ts` | 228–256, 438–445 | Calls `registerInfinibotInClaudeCode()` + watcher. **Needs dual-backend registration.** |
| `src/gateway/server-voice-config.ts` | 117–122, 178 | `getVoiceRoute()` returns `"claude_code" | "gateway_agent"`. Unchanged. |

---

## 3. MCP Install Flow

| File | Lines | Role |
|---|---|---|
| `src/mcp/claude-code-register.ts` | 111–215 | `registerInfinibotInClaudeCode` — writes `~/.claude.json` `mcpServers`. **Backend-specific; CC writes `mcpServers`, OC writes `mcp` to `~/.config/opencode/opencode.json`.** |
| `src/agents/claude-code/mcp-bridge.ts` | 96–197 | `generateMCPConfig` — scoped temp config in `~/.claude/mcp-infinibot-{id}.json`. **OC equivalent uses `OPENCODE_CONFIG_CONTENT` env injection — no temp file needed.** |
| `src/mcp/internal-servers.ts` | 20 | References `INFINIBOT_MCP_ENTRY_KEY`. Unchanged. |
| `src/cli/mcp-stdio.ts` | 2, 9 | Standalone stdio MCP server entry. Unchanged — shared across both backends. |

---

## 4. Setup UI / Wizard

| File | Role |
|---|---|
| `src/wizard/onboarding.finalize.ts` | Ensures claude_coder skill+memory paths. Unchanged — shared infrastructure. |
| `ui/src/ui/app-settings.ts` | App-level UI settings store. **Extended with `coderBackend` UI state.** |
| `ui/src/ui/views/setup.ts` | Setup wizard entry. **New "Choose your coding agent" step added.** |
| `ui/src/ui/views/setup-wizard.ts` | Multi-step wizard controller. **Plumbed for new step.** |

---

## 5. Tools / Subagents / Skills

| File | Lines | Role |
|---|---|---|
| `src/agents/infinibot-tools.ts` | 7 | Imports + registers `createClaudeCoderTool`. Unchanged — tool name stable. |
| `src/agents/run-id.ts` | 2, 42 | Human-friendly run ID generation. Unchanged. |
| `src/agents/subagent-progress.ts` | 85 | Progress tracking. Unchanged. |
| `src/agents/subagent-registry.ts` | 1–100 | Lifecycle management. Unchanged. |
| `src/agents/claude-code/transcript.ts` | whole file | Transcript append. Unchanged — works for any backend's stdout. |
| `src/agents/claude-code/subagent-broadcast.ts` | 52 | Tool-event broadcast. Unchanged. |
| `src/agents/claude-code/skill-system.ts` | 5, 114 | Preamble injection. Unchanged — both backends get the same preamble. |

---

## 6. Session Watcher

| File | Lines | Role |
|---|---|---|
| `src/gateway/claude-code-watcher.ts` | 264–421 | Watches `~/.claude/projects/**/*.jsonl`. **CC-only feature.** OC writes to `~/.local/share/opencode/`. Watcher continues to run for CC sessions regardless of configured backend. |
| `src/budget/subscriptions.ts` | 26 | `cliTool: "claude-code"`. Unchanged. |

---

## 7. Refactor Summary

After the `feat/opencode-swappable-backend` changes:

```
claude-coder-tool.ts
  └── getCoderBackend()           ← NEW factory (reads coder.backend config)
       ├── ClaudeCodeBackend      ← wraps existing launcher.ts (zero behavior change)
       └── OpenCodeBackend        ← new; wraps `opencode run` CLI
```

The following files are **modified** (call sites redirected through factory):
- `src/agents/tools/claude-coder-tool.ts`
- `src/design/runner.ts`

The following files are **new** (abstraction layer):
- `src/agents/coder-backend/types.ts`
- `src/agents/coder-backend/claude-code.ts`
- `src/agents/coder-backend/opencode.ts`
- `src/agents/coder-backend/registry.ts`
- `src/agents/coder-backend/mcp-install.ts`
- `src/agents/coder-backend/opencode-mcp-bridge.ts`

The following files are **extended** (config schema + UI):
- `src/config/types.infinibot.ts` — adds `coder?: { backend?: "claude-code" | "opencode" }`
- `ui/src/ui/app-settings.ts` — adds `coderBackend` UI state key
- `ui/src/ui/views/setup.ts` — adds wizard step
- `src/gateway/server-http.ts` — adds `GET /api/coder/backend` + `POST /api/coder/backend`

---

## 8. Key Constants

| Constant | File | Value |
|---|---|---|
| `INFINIBOT_MCP_ENTRY_KEY` | `src/mcp/claude-code-register.ts:18` | `"infinibot"` |
| CC config path | `src/mcp/claude-code-register.ts:63` | `~/.claude.json` |
| CC legacy config | `src/mcp/claude-code-register.ts:67` | `~/.claude/mcp.json` |
| CC session watcher | `src/gateway/claude-code-watcher.ts:264` | `~/.claude/projects/**/*.jsonl` |
| OC config path | (new) | `~/.config/opencode/opencode.json` |
| OC session data | (new) | `~/.local/share/opencode/` |
| Default backend | (new) | `"claude-code"` — zero change for existing users |
