# Curly Threading
<!--
ref: @protocol/curly-threading
type: protocol
tags: [threading, curly, sessions, observability, forensics, reference]
aliases: [curly-threading, thread-tracking, x-thread-id, request-thread, http-thread]
triggers: [thread tracking, x-thread-id, group requests, forensic trail, what calls did, curly threading, debug agent, trace requests]
trigger_prompt: When you need to maintain continuity across multiple API calls or troubleshoot issues in a sequence of requests, reach for this protocol.
category: meta
last_reviewed: 2026-05-09
complements: [@integrations/curly, @protocol/api-reference, @protocol/install, @protocol/onboarding]
audience: [agent-author, claude-code-user, openclaw-user, terminal-only]
version: 7
updated_at: 2026-07-16T23:28:24.295Z
-->

Group a sequence of API calls from one shell (and its subagents) into

Every API call to `protocol.supply` is tagged with two correlation IDs in the response headers:

- `X-Thread-Id: tid_<id>` — stable across a sequence of related calls when you send the same value back
- `X-Response-Id: rsp_<id>` — unique per call; forensic citation for any individual response

The server reconstructs the trail for you — `GET /thread/{tid}` returns the chronological list of calls.

> Same `X-Thread-Id` on outgoing requests = same thread. Skip the header (or change it) = different thread. Bare `curl` without the header = no thread.

---

## How `curly` participates

The current `curly` script (https://github.com/wildeagency/curly) is deliberately stateless — it just turns one command into one `curl` call. It does **not** auto-capture or auto-replay `X-Thread-Id`. If you want a thread that spans multiple calls in a shell, you wire it up yourself in two steps:

```bash
# 1. Pull X-Thread-Id from a response. `curly -i` prints response
#    headers; awk picks the line we care about.
TID=$(curly protocol bootstrap -i -o /dev/null -D /dev/stdout \
  | awk 'tolower($1)=="x-thread-id:"{gsub(/\r/,""); print $2; exit}')
echo "TID=$TID"

# 2. Replay it on every subsequent call
curly protocol "@protocol/loop"        -H "X-Thread-Id: $TID" -o /dev/null
curly protocol "@protocol/orchestrate" -H "X-Thread-Id: $TID" -o /dev/null

# 3. Pull the trace
curly protocol "/thread/$TID"
```

Subshells (including agent subagents spawned via `bash -c '...'` or Claude Code's Task tool) inherit `$TID` from the parent env — they participate in the same thread automatically.

---

## See your thread

```bash
curly protocol "/thread/$TID"
```

Returns `{ threadId, calls: [{ responseId, event, targetRef, createdAt }, ...] }` in chronological order.

---

## Forensic worked example

Your agent has been retrying a fetch and you're not sure why. Pull the trace:

```bash
$ curly protocol "/thread/$TID"
{
  "threadId": "tid_1kr6abc...",
  "calls": [
    { "responseId": "rsp_1kr6...", "event": "bootstrap", "targetRef": "repo:protocol",            "createdAt": "..." },
    { "responseId": "rsp_1kr6...", "event": "fetch",     "targetRef": "@protocol/getting-started", "createdAt": "..." },
    { "responseId": "rsp_1kr6...", "event": "fetch",     "targetRef": "@protocol/loop",            "createdAt": "..." },
    { "responseId": "rsp_1kr6...", "event": "fetch",     "targetRef": "@protocol/loop",            "createdAt": "..." },
    { "responseId": "rsp_1kr6...", "event": "fetch",     "targetRef": "@protocol/loop",            "createdAt": "..." }
  ]
}
```

Three identical fetches of `@protocol/loop` at the end — the agent loaded the same protocol three times instead of caching it. Surface that to the user; consider whether the agent harness needs a fetch cache.

---

*Related: `@content/web/github/2026-11-27-resume-command-osc-7577-issue-112408` · `@content/web/github/2026-11-25-followups-scope-issue-112120` · `@content/web/github/2026-11-23-claude-code-v2-1-331` · `@content/youtube/cole-medin/my-ai-software-factory-ships-hundreds-of-prs-a-week-heres-how-i-manage-it` · `@content/youtube/indy-dev-dan/claude-code-multi-agent-orchestration-with-opus-4-6-tmux-and-agent-sandboxes`*

---

*You're reading a protocol on [protocol.supply](https://protocol.supply) — hosted, searchable knowledge for AI agents. Think Agent Skills, as an API: bootstrap once (`curl -sL https://api.protocol.supply/bootstrap`), search (`/search?q=…`), fetch (`/@repo/slug`).*

*Any skill can become a protocol, and any protocol installs as a local skill — tell your agent "install this as a skill" or see [`@protocol/protocol-to-skill`](https://api.protocol.supply/@protocol/protocol-to-skill).*