Thread Taxonomy
- Entity ID:
ent-20260410-a2047c6befad - Type:
concept - Scope:
shared - Status:
active - Aliases: query source, thread types, QuerySource
Description
The thread taxonomy classifies the different execution contexts (query sources) in Claude Code. Internally represented as the QuerySource type (src/constants/querySource.ts), each query source identifies where an API request originates — main REPL, sub-agent, compaction, session memory, etc. The community has developed a parallel framework classifying agent work patterns into 7 thread types based on orchestration strategy.
Internal query sources
The QuerySource type defines the origin of each API query:
| Source | Purpose |
|---|---|
repl_main_thread |
Primary REPL interaction — the user's conversation |
sdk |
SDK/API programmatic usage |
compact |
Context compaction (summarization) |
side_question |
Side queries |
agent |
Generic sub-agent |
agent:custom |
Custom agent type |
agent:explore |
Exploration agent (read-only) |
agent:plan |
Planning agent (read-only) |
tool_use_summary |
Tool use summary generation |
advisor |
Advisor queries |
hook |
Hook execution |
session_memory |
Session memory extraction |
magic_docs |
Magic docs generation |
skill_search |
Skill search |
classifier |
Auto-mode security classifier |
bridge |
Bridge (IDE integration) |
The type is extensible: (string & {}) allows custom query sources beyond the known set.
Query source matters for system behavior — for example, shouldAutoCompact() skips compaction for session_memory, compact, and marble_origami (context-agent) sources to prevent recursive compaction.
Community thread taxonomy
A community-developed framework classifies agent work patterns into 7 types, each optimizing along the "Core Four" dimensions: Context, Model, Prompt, Tools.
| Type | Pattern | Description |
|---|---|---|
| Base | Single prompt | One prompt, one response. No agents. |
| P-thread | Parallel (10-15 concurrent) | Multiple agents working on independent subtasks simultaneously |
| C-thread | Chained phases | Sequential phases with verification gates between each |
| F-thread | Fan-out + select | Identical prompt to multiple agents, select best result |
| B-thread | Boss/worker | Orchestrator spawns and manages sub-agents |
| L-thread | Long-running (26+ hours) | Unattended execution over extended periods |
| Z-thread | Zero-touch | Aspirational: fully autonomous with no human intervention |
How thread identity is tracked
Thread identity is established through two mechanisms:
querySource— string tag on each API query identifying the execution contextagentId+agentTypeonToolUseContext— distinguish sub-agent threads from main thread
AsyncLocalStorage provides per-thread isolation when multiple agents run concurrently in the same process. Each agent's context carries: agentId, parentSessionId, agentType, subagentName, invokingRequestId, and invocationKind (spawn vs resume).
Trade-offs
- String-typed query source — extensible but no compile-time exhaustiveness checking. New sources can be added without updating a central enum, but consumers can't pattern-match safely.
- Community taxonomy vs internal — the community taxonomy describes user-facing orchestration patterns; the internal
QuerySourcedescribes system-level execution contexts. They overlap but aren't 1:1 (e.g., P-thread maps to multiple concurrentagent:*sources). - Extensible type —
(string & {})allows any custom source but makes the known set advisory, not enforced.
Key claims
- QuerySource tracks 16+ known execution contexts
- Compaction skips certain sources to prevent recursive summarization
- AsyncLocalStorage provides thread identity for concurrent in-process agents
- Community taxonomy identifies 7 orchestration patterns (Base through Z-thread)
Relations
used_byagent-lifecycle (agent types map to query sources)used_byauto-compact (compaction skips certain sources)related_tosix-orchestration-patterns
Sources
src-20260409-a5fc157bc756, source code analysis of src/constants/querySource.ts; community analysis