# Skill: 3p

Third-party delegation. Routes mechanical, high-volume, low-judgment code work to Codex CLI (or a local LLM) so Claude tokens stay reserved for work that actually needs a brain.

## To install

1. Install Codex CLI: `npm install -g @openai/codex@latest` then `codex login`.
2. (Optional) Install Ollama for the local-LLM tier — pull a small code model, e.g. `ollama pull qwen2.5-coder:7b`.
3. Save this file to `~/.claude/skills/3p/SKILL.md`.
4. Restart Claude Code.
5. Trigger with `/3p <task>` — or let Claude self-trigger when it detects mechanical work.

---

---
name: 3p
description: "Dispatch mechanical, high-volume, low-judgment code work to a third-party executor (Codex CLI, local LLM, or Claude Haiku for non-code) so Claude tokens stay reserved for high-judgment work. Triggered by /3p, 'delegate this', 'send to codex', or auto when a task fits the profile."
user-invocable: true
trigger: /3p
---

# 3P — Third-Party Delegation

**Trigger:** `/3p`, `delegate this`, `send to codex`, `3p this`, `offload this`

Dispatch mechanical, high-volume, low-judgment tasks to a third-party executor. Claude writes the prompt, runs the executor, verifies the output.

**Purpose:** Preserve Claude tokens for high-judgment work. Route grunt work (inline style migration, design-token replacement, import path updates, dead code deletion) to cheaper / free executors.

---

## Executor priority (try in order)

| Executor | Command | When to use | Cost |
|----------|---------|-------------|------|
| **Codex CLI** | `codex exec --full-auto --sandbox workspace-write` | Default. Mechanical code changes. | Subscription |
| **Local LLM** | `codex exec --oss --local-provider ollama` | Simple find-replace, linting, classification. Local hardware only. | Free |
| **Claude Haiku** | Anthropic API via `curl` | Quick classification / summarization, no code changes. | ~$0.001/call |

### Executor selection logic

1. **Check Codex CLI available:** `which codex` — if installed + authenticated, use Codex.
2. **Check local LLM available:** `curl -s http://localhost:11434/api/tags` — if Ollama responds, use local for simple tasks.
3. **Fallback:** If neither available, report: "No 3P executor available. Run this manually or approve Claude execution."

---

## How to invoke

### Automatic (Claude decides)
When Claude encounters a task that fits the 3P criteria (see below), it should:
1. Tell the user: "This is mechanical work — delegating to Codex."
2. Write the prompt
3. Run the executor
4. Verify the result (diff + build)
5. Report back

### Manual (user triggers)
User says `/3p migrate <component> to <design-system>` and Claude:
1. Reads the target file(s)
2. Writes a precise prompt with the token map and rules
3. Runs `codex exec`
4. Verifies and reports

---

## Task criteria — what goes to 3P

### YES — delegate these
- Inline `style={{}}` → utility-class / design-token conversion
- Hardcoded values (hex, px, rem) → design token import replacement
- Import path renames across multiple files
- Dead code / orphan component deletion (confirmed orphans only)
- Comment cleanup (stale references)
- Boilerplate page generation from a template
- CSS module → utility-first migration
- Mechanical test generation for pure functions

### NO — keep in Claude
- Architecture decisions
- Data model changes
- Security-sensitive code (auth, tokens, RLS)
- External API integrations
- Novel feature implementation
- Anything requiring judgment about business logic
- Anything touching credentials or env vars

---

## Prompt template

Every 3P prompt MUST include:

```
1. EXACT file path(s) to modify
2. The specific transformation to perform
3. A token / mapping table (if applicable)
4. What to KEEP as-is (dynamic values, computed styles, etc.)
5. What NOT to change (logic, data fetching, state)
6. Verification command: <your project's build / lint / test command>
```

### Example token map

Replace the contents below with your project's actual design system. The structure is the part that matters — explicit source → destination mappings, with categories grouped (backgrounds, text, borders, font sizes, spacing) and an explicit "keep as inline" list for dynamic values the executor must not touch.

```
Design Token Map (EXAMPLE — replace with your own):

BACKGROUNDS:
  THEME.base / #08090B → bg-base
  THEME.section / #111318 → bg-section
  THEME.card / #16181F → bg-card

TEXT:
  THEME.primary / #F0F2F5 → text-primary
  THEME.secondary / #A0A8B4 → text-secondary

BORDERS:
  rgba(255,255,255,0.06) → border (default)
  borderRadius 6-8 → rounded-lg
  borderRadius 999 → rounded-full

FONT SIZES:
  12px → text-xs
  14px → text-sm
  16px → text-base

SPACING:
  4px → p-1 / gap-1
  8px → p-2 / gap-2
  16px → p-4 / gap-4

KEEP AS INLINE:
  - Dynamic / computed colors from variables
  - borderLeft accent patterns with dynamic color
  - Charting library props
  - CSS custom property assignments
```

---

## Execution protocol

```bash
# Step 1: Run Codex
codex exec \
  --full-auto \
  --sandbox workspace-write \
  -C "$PROJECT_DIR" \
  -o /tmp/3p-result.md \
  "$PROMPT"

# Step 2: Verify
npm run build 2>&1 | grep -E "error|Error|Failed"
git diff --stat <target-files>
grep -c 'style={{' <target-files>  # for UI migrations

# Step 3: Report
# If build passes: summarize changes, target metric before/after
# If build fails: read error, attempt fix, or roll back with git checkout
```

### For local LLM (Ollama):
```bash
codex exec \
  --oss \
  --local-provider ollama \
  --full-auto \
  --sandbox read-only \
  -C "$PROJECT_DIR" \
  -o /tmp/3p-result.md \
  "$PROMPT"
```

### Timeout handling
- Codex exec: 10 minute timeout (600000ms)
- Local LLM: 5 minute timeout
- If timeout: report, suggest breaking task into smaller files

---

## Batch mode

For multi-file migrations (e.g., 30-page UI overhaul):

1. Claude generates the file list and per-file prompts
2. Runs Codex sequentially on each file (not parallel — avoids conflicts)
3. After each file: verify build, count target-metric reduction
4. After all files: full build + summary report
5. Single commit for the batch

---

## Verification checklist

After every 3P execution:
- [ ] Build / lint / test passes
- [ ] `git diff` shows only expected changes
- [ ] No logic / state / fetch changes (spot-check)
- [ ] Target metric improved (inline style count reduced, dead imports gone, etc.)
- [ ] No new hardcoded values introduced
- [ ] Dynamic values preserved as inline styles

---

## Error handling

| Error | Action |
|-------|--------|
| Codex CLI not found | `npm install -g @openai/codex@latest` |
| Auth expired | `codex login` |
| Model not supported | Upgrade CLI: `npm install -g @openai/codex@latest` |
| Build fails after changes | Read error, fix if trivial, `git checkout <file>` if not |
| Ollama not running | Skip local, use Codex CLI |
| Timeout | Break task into smaller files |
| Codex makes logic changes | `git checkout <file>`, re-prompt with stricter constraints |
