Query Claude Code agent history for a project path
You are using the claude-history CLI tool to query Claude Code's agent history storage.
Note: If
claude-historyis not installed or you encounter issues, see README.md for installation and troubleshooting instructions.
This skill must delegate all tool use to the history-search agent. Do not call claude-history directly from the skill.
history-search agent (from .claude/agents/registry.yaml).list - List projects or sessions
claude-history list [path]
query - Query history with filters
claude-history query <path> [flags]
tree - Show agent hierarchy
claude-history tree <path> --session <session-id>
find-agent - Find agents by task description
claude-history find-agent <path> [search-terms...]
export - Export session to HTML
claude-history export <path> --session <session-id> [flags]
resolve - Resolve paths (debugging)
claude-history resolve <path> [flags]
--session <id> - Filter by session ID (supports git-style prefixes)--agent <id> - Filter by agent ID (supports git-style prefixes)--type <types> - Filter by entry types (user,assistant,system,etc.)--start <date> - Filter entries after date (YYYY-MM-DD)--end <date> - Filter entries before date--tool <name> - Filter by tool name (exact match)--tool-match <pattern> - Filter by tool name pattern (regex)--format <fmt> - Output format: text, json, tree, html (default: text)--output <file> - Write output to fileWhen user provides a path:
list to the agent to see available sessionstree to see agent hierarchyquery with appropriate filters to get detailed informationfind-agent to search for agents working on specific topicsWhen user wants to search for specific work:
find-agent with search termsquery to get detailstree to understand the agent hierarchyWhen user wants to export:
export with session ID to create HTML filesquery --format html to generate and auto-open HTML report in browserThese command examples are executed by the history-search agent on the skill's behalf.
# List all sessions for a project
claude-history list /path/to/project
# Show agent tree for a session
claude-history tree /path/to/project --session abc123
# Query all user messages in a session
claude-history query /path/to/project --session abc123 --type user
# Find agents working on "authentication"
claude-history find-agent /path/to/project authentication
# Export session to HTML
claude-history export /path/to/project --session abc123
# Generate and auto-open HTML report
claude-history query /path/to/project --session abc123 --format html
# Query specific agent's work (supports git-style prefixes)
claude-history query /path/to/project --session abc123 --agent def456
claude-history query /path/to/project --session 8c43ec8 --agent ac8c7ba
# Query agent by full ID
claude-history query /path/to/project --session 8c43ec84-09ad-4dc7-bcf7-17f209e983f0 --agent ac8c7ba
# Find agent in tree, then query it
claude-history tree /path/to/project --session abc123 # Shows agent IDs
claude-history query /path/to/project --session abc123 --agent a059688
# Search for tool usage
claude-history query /path/to/project --tool Read --format json
# Filter by date range
claude-history query /path/to/project --start 2026-01-01 --end 2026-01-31
# Query specific agent with type filter
claude-history query /path/to/project --session abc123 --agent def456 --type assistant
user - User messages (prompts or tool results)assistant - Claude responses with text and tool_use blockssystem - System events and hook summariesqueue-operation - Subagent spawn triggersprogress - Status updatesfile-history-snapshot - File state capturessummary - Conversation summariesUse Case: Share the results of a previous agent's work with new agents without duplicating the analysis.
Instead of re-analyzing a repository or re-exploring code, you can pass a reference to an agent that already did the work. New agents can query the previous agent's findings directly.
claude-history query <project-path> --session <session-id> --agent <agent-id> --type assistant --format json | jq -r '.[-1].message.content[0].text'
What this does:
assistant messages only (the agent's responses)jq to extract just the text from the final messageResult: Gets the complete final analysis (e.g., ~26,000 token comprehensive report) without re-analyzing.
✅ Use pass-by-reference when:
❌ Don't use when:
When giving this pattern to subagents, provide:
Template:
Use the Bash tool to run this exact command:
```bash
claude-history query <project-path> --session <session-id> --agent <agent-id> --type assistant --format json | jq -r '.[-1].message.content[0].text'
This returns the complete analysis from agent
CRITICAL: Stop immediately if command fails or returns empty output.
## Your Task
Based on the user's request parameters:
- **action**: ${action}
- **path**: ${path} (or use current working directory if not provided)
- **session**: ${session}
- **agent**: ${agent}
Construct and execute the appropriate `claude-history` command(s) to fulfill the user's request.
**Important:**
1. Use `claude-history` from PATH (see README.md if not installed)
2. Parse the output and present it in a clear, readable format
3. For large outputs, consider using pagination or filtering
4. Session and agent IDs support git-style prefixes (first 7+ characters)
5. When showing results, explain what you found in context
## Response Format
After executing the command:
1. Summarize what you searched for
2. Present the key findings
3. Suggest follow-up queries if relevant
4. Explain any interesting patterns or insights