# Tree Of Thoughts

> Multi-path investigation with parallel agents. Use when researching complex questions requiring breadth-first exploration with verification.

- Skill: `nikketryhard/tree-of-thoughts` (Agent Skill)
- Install (CLI): `npx get-skill add nikketryhard/tree-of-thoughts`
- Raw SKILL.md: https://api.skillmd.com/api/skills/nikketryhard/tree-of-thoughts/raw
- Safety review: pending
- Works with: any agent that reads SKILL.md (Claude Code, Claude.ai, Cursor, Codex, Windsurf, 60+ more)
- Category: Coding & Dev Tools
- Author: NikkeTryHard (https://skillmd.com/u/nikketryhard)
- Updated: 2026-11-30
- Page: https://skillmd.com/skills/nikketryhard/tree-of-thoughts

---

---
name: tree-of-thoughts
description: Multi-path investigation with parallel agents. Use when researching complex questions requiring breadth-first exploration with verification.
---

# Tree of Thoughts

## CRITICAL: Protocol Completion is MANDATORY

**You MUST complete the FULL protocol. Presenting results without calling `tot_end` is FORBIDDEN.**

- You MUST reach Round 5 minimum
- You MUST have FOUND nodes at R4+ with VERIFY children
- You MUST call `tot_end` to finalize - NO exceptions
- Stopping early and writing your own summary is PROTOCOL VIOLATION
- **DO NOT present findings to user until `tot_end` returns OK**

## CRITICAL: Agent Spawning is MANDATORY

**You MUST spawn a FRESH Haiku Task agent for EVERY proposed node.** The MCP tracks timing and agentId.

| Violation | Result |
|-----------|--------|
| Missing agentId | **REJECTED** - commit fails |
| Reused agentId | **REJECTED** - each node needs NEW agent |
| Fake agentId | **REJECTED** - verified against ~/.claude/projects/ |
| Commit < 10s after propose | WARNING - looks like gaming |

**Each node = One fresh Haiku Task agent. No exceptions. No reuse.**

**ALWAYS use model: haiku** - Tree of Thoughts is a research protocol, not implementation. Haiku agents are faster, cheaper, and sufficient for investigation tasks.

## Agent Verification

**agentIds are verified against Claude Code's session files AND tracked for reuse.**

When calling tot_start, you MUST provide your project directory:
```javascript
tot_start({
  query: "...",
  projectDir: "/home/user/myproject"  // REQUIRED: Run `pwd` to get this
})
```

When you spawn a Task agent, you get an agentId (e.g., `a977616`).
- tot_commit verifies this agent file exists in ~/.claude/projects/
- tot_commit tracks all used agentIds - **reusing one is REJECTED**

**Fake or reused agentIds will be REJECTED.** You cannot fabricate or recycle agent IDs.

## Workflow (Single Root Paradigm)

```
1. tot_start → get sessionId
2. tot_propose → declare single root R1.A
3. **SPAWN Task agent for R1.A** ← REQUIRED
4. tot_commit → submit findings as EXPLORE
5. tot_propose → branch into 3-5 children at R2
6. Repeat spawning agents and committing
7. At R4+ you can use FOUND state
8. Add VERIFY child for each FOUND
9. Continue until R5+ and canEnd=true
10. tot_end → get final results with references
```

## States (5 states)

| State   | Meaning              | Children   | Terminal | Min Round | Valid Child States |
| ------- | -------------------- | ---------- | -------- | --------- | ------------------ |
| EXPLORE | Dig deeper           | 2+ (R1-R2), 1+ (R3+) | No | R1 | Any |
| FOUND   | Provisional solution | 1+ any     | No       | R4        | EXPLORE, FOUND, VERIFY |
| VERIFY  | Confirms FOUND       | 0          | Yes      | R4        | - |
| EXHAUST | Exhausted path       | 1+ any     | No       | R4        | EXPLORE, EXHAUST, DEAD |
| DEAD    | Confirmed dead end   | 0          | Yes      | R4        | - |

**Key Changes:**
- FOUND needs only 1+ child (any of: EXPLORE, FOUND, VERIFY)
- EXHAUST needs only 1+ child (any of: EXPLORE, EXHAUST, DEAD)
- EXPLORE at R3+ needs only 1+ child (relaxed from 2+)
- R3 must be EXPLORE only (forces deeper investigation)
- R2 should have 5+ nodes (warning if fewer)

**Invalid Transitions (Semantic Conflicts):**
| From | Cannot Go To | Why |
|------|--------------|-----|
| FOUND | EXHAUST, DEAD | Found something → can't be exhausted/dead |
| EXHAUST | FOUND, VERIFY | Exhausted path → can't suddenly find/verify |

## Node IDs

Format: `R[round].[suffix]`

```
Round 1: R1.A (single root, parent: null)
Round 2: R2.A1, R2.A2, R2.A3 (branch wide from R1.A)
Round 3: R3.A1a, R3.A1b (parent: R2.A1)
Round 4: R4.A1a1 (parent: R3.A1a) - can use FOUND here
Round 5: R5.A1a1a (parent: R4.A1a1) - VERIFY node
```

## Rules

1. **Single root R1.A** - then branch wide at R2 (5+ nodes recommended)
2. **Cannot end before round 5** - forces thorough investigation
3. **EXPLORE nodes need 2+ children at R1-R2, 1+ at R3+** - relaxed requirements later
4. **R3 must be EXPLORE only** - forces deeper investigation before conclusions
5. **FOUND only at Round 4+** - Earlier rounds auto-convert to EXPLORE
6. **FOUND needs 1+ child** (EXPLORE, FOUND, or VERIFY) - Cannot end until verified
7. **EXHAUST only at Round 4+** - Earlier rounds auto-convert to EXPLORE
8. **EXHAUST needs 1+ child** (EXPLORE, EXHAUST, or DEAD) - Cannot end unconfirmed
9. **DEAD only at Round 4+** - R1-R3 converts to EXPLORE
10. Each node requires a real Task agent - no fabrication

## Auto-Conversion Rules

| Attempt | At Round | Converts To |
|---------|----------|-------------|
| EXHAUST | R1-R3    | EXPLORE     |
| DEAD    | R1-R3    | EXPLORE     |
| FOUND   | R1-R3    | EXPLORE     |

## Subagent Prompt Requirements

**CRITICAL:** When spawning Task agents, include in the prompt:

```
At the end of your response, include a REFERENCES section with:
- URLs you visited
- Documentation you read
- Code files you analyzed (with paths)
- Any external sources

Format:
## References
- [title](url) - brief description
- path/to/file.ts - what you found
```

## Example

```javascript
// Start - MUST include projectDir
tot_start({ query: "...", projectDir: "/home/user/myproject" })

// Round 1: Single root
tot_propose({ sessionId, nodes: [
  { id: "R1.A", parent: null, title: "Main query", plannedAction: "Analyze problem" }
]})
tot_commit({ sessionId, results: [
  { nodeId: "R1.A", state: "EXPLORE", findings: "...", agentId: "abc-123" }
]})

// Round 2: Branch wide
tot_propose({ sessionId, nodes: [
  { id: "R2.A1", parent: "R1.A", title: "Path 1", plannedAction: "..." },
  { id: "R2.A2", parent: "R1.A", title: "Path 2", plannedAction: "..." },
  { id: "R2.A3", parent: "R1.A", title: "Path 3", plannedAction: "..." }
]})

// Continue through R3, R4...

// Round 4+: Can use FOUND
tot_commit({ sessionId, results: [
  { nodeId: "R4.A1a1", state: "FOUND", findings: "Solution found...", agentId: "..." }
]})

// Round 5: VERIFY the FOUND
tot_propose({ sessionId, nodes: [
  { id: "R5.A1a1a", parent: "R4.A1a1", title: "Verify solution", plannedAction: "Confirm findings" }
]})
tot_commit({ sessionId, results: [
  { nodeId: "R5.A1a1a", state: "VERIFY", findings: "Confirmed: ...", agentId: "..." }
]})

// Now canEnd=true
tot_end({ sessionId })
```

## Errors

| Error           | Fix                                            |
| --------------- | ---------------------------------------------- |
| NOT_PROPOSED    | Call tot_propose first                         |
| TERMINAL_PARENT | Use tot_reclassify to change parent to EXPLORE |

## Warnings (Anti-Gaming)

| Warning          | Meaning                                             |
| ---------------- | --------------------------------------------------- |
| SUSPICIOUS       | Commit too fast after propose - no real research    |
| DEPTH_ENFORCED   | State before R4 converted to EXPLORE - add children |
| LOW_BRANCHING    | R2 has fewer than 5 nodes - consider adding more    |
| UNVERIFIED_AGENT | Could not verify agentId (no sessions found)        |

## Errors (Rejection)

| Error         | Meaning                                        |
| ------------- | ---------------------------------------------- |
| MISSING_AGENT | No agentId provided - you MUST spawn an agent  |
| REUSED_AGENT  | agentId already used for another node          |
| FAKE_AGENT    | agentId not found in Claude Code sessions      |
| NOT_PROPOSED  | Node was not proposed before commit            |

## CRITICAL: EXPLORE Nodes Need Children

**EXPLORE nodes MUST have children (2+ at R1-R2, 1+ at R3+).** This is ENFORCED:

- `tot_commit` will warn: `CRITICAL [INCOMPLETE_EXPLORE]`
- `tot_end` will REJECT with: `BLOCKED: X EXPLORE nodes need more children`

If you create an EXPLORE node, you MUST branch it before moving on. No exceptions.

