framework/core/commands/flowai-reflect-by-history/SKILL.md
Analyze previous IDE session history to find recurring patterns in agent behavior, identify systemic issues, and propose improvements to project primitives (rules, skills, hooks). Use when the user asks to review past sessions, find recurring problems, or improve development workflow based on historical data.
npx skillsauth add korchasa/flowai flowai-reflect-by-historyInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Analyze previous IDE session transcripts (not the current session) to identify recurring behavioral patterns, systemic issues, and propose improvements to project primitives (rules, skills, hooks, project docs).
Unlike flowai-reflect (which analyzes the current session), this skill works with historical data across multiple past sessions to find cross-session patterns.
Session history is stored as JSONL files:
.claude/projects/ relative to project root (if present)~/.claude/projects/{project-path-with-dashes}/ — each .jsonl file is one session~/.claude/history.jsonl (prompt text, timestamp, project path, session ID per line)JSONL format — each line is a JSON object with type field:
type: "user" — user messages (message.content has the text)type: "assistant" — agent responses (may contain tool_use in message.content[])type: "progress" — hook/tool progress eventstype: "ai-title" — session title (aiTitle field)type: "queue-operation" — internal queue events (skip)type: "file-history-snapshot" — file backup metadata (skip)~/.cursor/projects/{project_name}/agent-transcripts/~/Library/Application Support/Cursor/User/workspaceStorage/<hash>/state.vscdb (macOS)~/.local/share/opencode/opencode.db.claude/, .cursor/, .opencode/).claude/projects/ (or .cursor/projects/, .opencode/) within the project root. List all subdirectories and .jsonl files. If session files are found here, use them.~/.claude/projects/, ~/.cursor/projects/, etc.Decide how many sessions to analyze based on the user's request:
| User Request | Scope | Sessions | |---|---|---| | "Find recurring issues" / "patterns" | Deep | All available or last 10-20 | | "What went wrong recently?" | Recent | Last 3-5 sessions | | "Review last session" | Single | Last 1 | | "How has X improved?" | Trend | All sessions mentioning X | | Unspecified | Default | Last 5-10 sessions |
If more than 20 sessions available, analyze the most recent 10-20 unless user specifies otherwise. Explain the scope chosen and why.
For each session, extract:
ai-title and first user message)Compare across sessions to find:
When proposing a fix, classify where it belongs:
Initialize
Locate History
Determine Scope
Read & Parse Sessions
queue-operation, file-history-snapshot, and progress type entries (unless they contain hook errors).Analyze Individual Sessions
Cross-Session Pattern Analysis
Formulate Report Present findings in this structure:
Section structure per item:
N. **[Recurring|Isolated] <clear problem title> (N/M sessions)**
**What happened**: Full story across sessions. For each session where the issue appeared:
what was the task, what actions did the agent take, what went wrong? Quote error messages
and tool calls. A reader who never saw the sessions must get the complete picture.
**Impact**: Measurable cost per occurrence and total. How many steps/tokens were wasted
each time? What errors or regressions were introduced? What is the cumulative cost across
all affected sessions?
**Root cause**: Why does this keep happening (recurring) or why did it happen (isolated)?
What knowledge, rule, or automation is missing? Why haven't previous fixes resolved it?
**Proposed fix**:
- **Where**: Exact file path and section (e.g., `CLAUDE.md` § "TDD Flow", after rule 4;
or new file `test/helpers.ts`).
- **Draft content**: The actual text to add — a rule, code, hook config, or skill
description. Ready to paste. In a quote block or code block.
- **Why this works**: How this fix addresses the root cause. Why will the agent behave
differently with this artifact in place?
**Recurrence risk**: HIGH/MEDIUM/LOW. What specific scenarios trigger this issue?
How often do they occur? For isolated issues — under what conditions should this be
escalated to a systemic fix?
Quality bar: If you remove the title, a reader should still understand what happened, why it matters, and what to do about it. If any section would make a reader ask "what does this mean?" or "why?" — expand it.
Anti-patterns (avoid):
Impact: 4-6 wasted steps — doing what? With what consequence?Evidence: sessions 2026-03-15, 2026-03-20 — describe what happened in each session.Fix: add rule "mock before import" — what is the full rule text? Where exactly to add it?Where: CLAUDE.md — which section? After which existing rule?Examples (desired detail level):
[Recurring] JWT mock ordering breaks on every refactor (3/4 sessions)
What happened: In three out of four analyzed sessions, the agent hit the same TypeError: jwtVerifier is not a function when working with test files. Session 2026-03-15: agent refactored imports in auth.test.ts, moved the import { authenticate } from './auth' line above the mock setup call. Test failed at line 12 with TypeError: jwtVerifier is not a function. Agent spent 3 steps trying different import orders before discovering the cause. Session 2026-03-20: identical error in user.test.ts:8 after restructuring test setup. Agent spent 4 steps reordering imports. Session 2026-03-28: same error in admin.test.ts:15, resolved in 6 steps by trial-and-error. In all three cases the root cause was identical: the module under test captures the JWT verifier at import time, so setupMockJwt() must be called before the import statement, not after.
Impact: 13 wasted agent steps across 3 sessions (3 + 4 + 6). Each occurrence adds ~5 minutes of trial-and-error debugging with identical symptoms. The pattern is invisible — nothing in project docs or code explains the import-time binding behavior of the JWT module.
Root cause: The auth module calls getJwtVerifier() at module load time and caches the result. If the mock is set up after import, the module already holds a reference to the real (undefined) verifier. No rule or code comment documents this constraint. The agent rediscovers it from scratch each session.
Proposed fix:
CLAUDE.md § "Test Rules", after "No stubs or mocks for internal code." (2) New file test/helpers.ts.setupMockJwt() from test/helpers.ts BEFORE importing the module under test. The auth module captures the JWT verifier at import time — mocking after import has no effect."
Helper file test/helpers.ts:
export function setupMockJwt() {
globalThis.jwtVerifier = (token: string) => ({ sub: "test-user", exp: Date.now() + 3600 });
}
Recurrence risk: HIGH — triggers on every refactor that touches import order in test files. Without the fix, each occurrence costs ~5 minutes and 4-6 agent steps.
[Isolated] Agent wrote custom auth check instead of using existing middleware
What happened: In session 2026-03-25, the user asked to "just add a quick admin check to the dashboard endpoint." The agent wrote a custom checkAdmin() function directly in dashboard_handler.ts that reads the user role from the request and returns 403 if not admin. However, the project already has a requireRole('admin') middleware in src/middleware/auth.ts:34 that does exactly this — including proper error formatting, audit logging, and role hierarchy support. The agent never read the src/middleware/ directory in this session, likely because the user's framing ("just add a quick check") implied a small inline solution.
Impact: The custom checkAdmin() duplicates existing functionality but lacks audit logging and role hierarchy support that the middleware provides. This creates a security inconsistency — the dashboard endpoint silently bypasses the audit trail that all other admin endpoints use.
Root cause: One-off skip — in all other analyzed sessions, the agent read src/middleware/ before adding auth logic. The user's urgency framing ("just add a quick check") likely biased the agent toward an inline solution.
Proposed fix:
checkAdmin() in dashboard_handler.ts with app.use('/dashboard', requireRole('admin')) and delete the custom function. This is a one-time code fix, not a rule.Recurrence risk: LOW — occurred in 1/4 sessions. Escalation trigger: if the same skip appears in 2+ future sessions, add a rule to CLAUDE.md § "Core Project Rules": "Before adding auth/validation logic, read src/middleware/ for existing patterns. Do not write inline auth checks."
Self-Criticism Before presenting the report, critically examine your own cross-session analysis:
Present & Confirm
development
Use when the user asks to add TypeScript strict-mode code-style rules to AGENTS.md for a TypeScript project using strict mode. Do NOT trigger for Deno projects (use setup-agent-code-style-deno) or non-strict TS configurations.
development
Use when the user asks to add Deno/TypeScript code-style rules to AGENTS.md, or during initial Deno project setup when code-style guidelines need to be established. Do NOT trigger for non-Deno TypeScript projects (use setup-agent-code-style-strict), or for runtime-agnostic style advice.
testing
Use when the user provides a source (URL, file path, or free text) to save into the project's memex — a long-term knowledge bank for AI agents. Stores the raw source, extracts entities into cross-linked pages, runs a backlink audit, and updates the index and activity log. Do NOT trigger on casual reads; only when the intent is to persist a source into the memex.
development
Use when the user asks to audit a memex (long-term knowledge bank for AI agents) for orphans, dead SALP REFs, missing sections, contradictions, or index drift. Runs a deterministic structural check, layers LLM-judgement findings, optionally auto-fixes trivial issues with `--fix`. Do NOT trigger on general code linting.