Track every prompt you send in Cursor, analyze patterns, and use the results to fill in CLAUDE.md (or .cursor/rules) so you stop re-explaining the same things. Documentation driven by what you actually ask, not guesswork.
- beforeSubmitPrompt (Cursor hooks) runs when you hit send. A script reads the prompt and metadata, appends one JSON line to
.cursor/prompt-log.jsonl, and always returnscontinue: trueso the request is never blocked. - You run
scripts/analyze-prompts.pywhen you want a report. It reads the log, extracts phrases from full prompt text, counts how often each phrase appears across prompts, and prints a summary plus suggested sections for CLAUDE.md from the most recurring topics. - You add those sections to CLAUDE.md (or
.cursor/rules) and fill in 1–2 sentences each. Future prompts in that area get the context automatically.
No AI memory store, no MCP—just logging and a local analyzer.
- Cursor with this project (or your project) open.
- Python 3 for the analyzer.
- jq for the log script (used to read
workspace_rootsand build the log entry). Install with e.g.brew install jq(macOS) or your package manager.
You can run the hook from your user Cursor config so it applies to every project without copying files into each repo.
-
Create
~/.cursor/hooks.jsonwith:{ "version": 1, "hooks": { "beforeSubmitPrompt": [ { "command": "./hooks/log-prompt.sh" } ] } }User hooks run from
~/.cursor/, so the command is./hooks/log-prompt.sh(not.cursor/hooks/...). -
Copy the log script into your home config:
mkdir -p ~/.cursor/hooks cp /path/to/cursor-postmortem/.cursor/hooks/log-prompt.sh ~/.cursor/hooks/ chmod +x ~/.cursor/hooks/log-prompt.sh
-
Restart Cursor. The hook runs for every project. The script uses workspace_roots from the hook payload, so logs are still written per project to
<project-root>/.cursor/prompt-log.jsonl, not to a single global file. -
Run the analyzer from whichever project you want to analyze (or use
--logto point at a project’s log):cd /path/to/some-project python3 /path/to/cursor-postmortem/scripts/analyze-prompts.py
- Open the
cursor-postmortemproject in Cursor. Hooks run automatically; no install step. - Use Cursor as usual (Agent, Composer, etc.). Every prompt is appended to
.cursor/prompt-log.jsonlin this repo. - From the project root, run:
You’ll see:
python3 scripts/analyze-prompts.py
- Total prompts, how many had attachments, average prompt length.
- Most frequent phrases across full prompts (recurring topics).
- Suggested additions for CLAUDE.md: headings plus
<!-- Add 1–2 sentences -->placeholders.
- Create or edit
CLAUDE.md(or a rule in.cursor/rules/) and add the suggested sections. Replace the placeholders with the real context (stack, convention, or decision). Re-run the analyzer anytime to get fresh suggestions.
Option A — install script (recommended)
From this repo, run:
./scripts/install.sh /path/to/other-projectThe script will:
- Copy
.cursor/hooks/log-prompt.shinto the target and make it executable - Create or merge
.cursor/hooks.jsonsobeforeSubmitPromptruns that script (existing hooks are preserved) - Add
.cursor/prompt-log.jsonlto the target’s.gitignoreif present - Copy
scripts/analyze-prompts.pyinto the target so you can run the analyzer from that project
Then open the target project in Cursor and use it as usual; run python3 scripts/analyze-prompts.py from the target’s root when you want suggestions.
Option B — manual copy
- Copy into that project:
.cursor/hooks.json(or add abeforeSubmitPromptentry) and.cursor/hooks/log-prompt.sh;chmod +x .cursor/hooks/log-prompt.sh. - Copy
scripts/analyze-prompts.pyinto that project, or run it from here with--log /path/to/that/project/.cursor/prompt-log.jsonl. - Open that project in Cursor; prompts log to that project’s
.cursor/prompt-log.jsonl.
| Command | Effect |
|---|---|
python3 scripts/analyze-prompts.py |
Full report: summary stats, frequent first lines, then suggested CLAUDE.md sections. |
python3 scripts/analyze-prompts.py --suggest-only |
Only the suggested doc sections (no stats). |
python3 scripts/analyze-prompts.py --log path/to/log.jsonl |
Use a different log file (e.g. another project or a backup). |
Suggestions are based on phrase frequency over full prompt text: 2–5 word n-grams are extracted from each prompt (excluding generic boilerplate like “can you”, “how to”), counted across all prompts, and the most repeated become suggested headings. Fill in the body yourself.
- Location:
<project-root>/.cursor/prompt-log.jsonl(created automatically). With global hooks the script still writes to the active project’s.cursor/usingworkspace_roots. Add to.gitignoreso prompts aren’t committed. - Format: One JSON object per line:
ts,conversation_id,prompt,first_line,prompt_length,attachment_count,attachment_types.
This repo also includes a sessionStart hook that injects content from .cursor/memory/store.json into new sessions (for use with the separate memory MCP server). If you only want prompt tracking, you can remove the sessionStart entry from .cursor/hooks.json; the beforeSubmitPrompt hook will keep working. The sessionStart script requires jq.
| Path | Role |
|---|---|
.cursor/hooks.json |
Registers beforeSubmitPrompt (and optionally sessionStart). |
.cursor/hooks/log-prompt.sh |
Logs each prompt to .cursor/prompt-log.jsonl. |
.cursor/prompt-log.jsonl |
Append-only log (one JSON line per prompt). |
scripts/analyze-prompts.py |
Reads the log and prints summary + suggested CLAUDE.md sections. |
scripts/install.sh |
Installs prompt tracking into another project (hooks + analyzer + .gitignore). |
docs/prompt-tracking-for-claude-md.md |
Longer description and log format. |
docs/cursor-memory-plugin-design.md |
Design notes and optional memory-store approach. |