I have two PCs and I use Claude Code on both. I wanted the second one to keep the same prompt diary as the first. I could have copied files by hand. Instead I asked Claude Code to write down, in one file, what the other PC’s Claude Code should do. Then I gave that file to it.
This post explains the hook and the request file. The hook is now running on the other PC, and the last section lists what I still have not checked.
The Need: Good Prompts Disappear
Claude Code keeps a session history, but it is mixed with everything else and tied to one project. I wanted something simpler: when I type a prompt that matters, I want one line in a text file, with the time and the project name. Later I can search that file for “when did I ask for this?”
I use that file for my blog. When I write about a feature, I look for the real prompt that started it and the time between asking and finishing. That makes the post honest, because I quote what I really typed.
The Proof: What It Does
I type // at the start or the end of a prompt:
//the commentary books do not appear as sources?
The prompt still goes to Claude as normal. At the same time, one line is appended to a diary file:
[2026-10-23 07:28] [logosgraph] the commentary books do not appear as sources?
Claude Code shows a small message, “saved → path”. The file is one per month and per PC, for example 2026-10__think.txt. At the time of writing, my October file has 1,188 lines.
I tested the edge cases by sending JSON into the script by hand. A normal prompt, a prompt starting with /// (a different hook of mine), and a bare // with no text all give {"continue": true} and write nothing.
The Story: Why a Hook and Not a Skill
I first thought of a skill. But a skill runs because the model decides to run it, or because I call it by name. I do not want the model involved in a diary entry. If it forgot once, I would lose a prompt and not know.
A hook is different. Claude Code runs it itself, as a program, every time I press Enter. The model never sees it. Claude Code has an event for this, UserPromptSubmit. The program gets the prompt as JSON on standard input and prints JSON back.
This is the third or fourth form of this idea. An earlier version of it, and why I moved it to the NAS, is in a post from June. This post is about the part I had not done: giving it to a PC that did not have it yet.
The How
The hook, in short
The whole thing is one Python file, ~/.claude/hooks/save_prompt.py. The core is this:
data = json.loads(raw.decode("utf-8-sig"))
prompt = data.get("prompt", "")
if prompt.startswith("//") and not prompt.startswith("///"):
text = prompt[2:].strip()
elif prompt.endswith("//") and not prompt.startswith("///"):
text = prompt[:-2].strip()
else:
print(json.dumps({"continue": True}))
return
project = Path(data.get("cwd", os.getcwd())).name
line = f"[{datetime.now():%Y-%m-%d %H:%M}] [{project}] {text}"
Three choices matter here:
- Exit quietly. On any error, print
{"continue": true}and stop. A broken diary must never block a prompt. ///is not mine. I use three slashes for a different hook, which reads messages between my sessions. The two scripts are separate on purpose.- Where to write. The script writes to a shared folder on my NAS. If the NAS cannot be reached, it writes to a local folder and moves those lines to the NAS the next time it can. The file name carries a sender name from a small text file, so two PCs never write to the same file.
It is registered in ~/.claude/settings.json:
{
"hooks": {
"UserPromptSubmit": [
{ "hooks": [ { "type": "command",
"command": "python \"C:\\Users\\<user>\\.claude\\hooks\\save_prompt.py\"" } ] }
]
}
}
The request file
For the other PC I did not want to explain the same thing in chat. I asked my Claude Code to write a request file that the other Claude Code can follow alone.
💬 Prompt that worked (2026-10-25 06:14) “I want to apply the coding-history skill or hook that works with ‘//’ to Claude Code on another PC. Please write a file with what to ask that PC’s Claude Code.”
My Claude Code did not guess. It read my own settings.json and my hook script first, and found out that mine is a hook, not a skill. Then it wrote a file with these parts:
- What the hook must do. Plain rules: when it fires, the line format, where it saves, what to do when the NAS is not reachable.
- What to install. The sender-name file, the full script, and the
settings.jsonentry. - What to check first. Does
python --versionwork? Can it reach the shared folder? - How to test. Send fake JSON into the script and look at the output. Do one real
//test and delete that one line. - What not to do. Do not overwrite the existing
settings.json. Do not touch other people’s diary files.
The part I like most is the last one. A request that only says “do this” is risky on someone else’s machine. A request that also says “do not do that” makes the helper careful.
🗂 Claude.md Rule When you give Claude Code a task for a PC you cannot see, write what it must not touch, and make it merge into
settings.json, never replace it.
Traps from my own PCs
These are in the request file because they have already bitten me:
pythonmay not run. On some Windows PCs,pythonis a Microsoft Store stub that does nothing. The Python Launcherpyworks there. If a hook silently does nothing, check this first.- No BOM. If you create the sender-name file with PowerShell’s
Out-File -Encoding utf8, it adds a byte-order mark and the file name in the diary gets strange characters. The script reads withutf-8-sigto be safe, and the file should be written without BOM. - Restart Claude Code. Hooks are read at start. A new hook does nothing in a session that was already open.
A PC that is not mine
One honest limit. The request file I wrote has my NAS path inside the script. That is right for my two PCs. On a PC that is not on my network, the NAS path does not exist, so the script would fall back to the local folder every time. The diary would still work, but only on that PC.
If I give it to a friend, I would change two lines: the diary folder (a normal local folder) and the sender name. I would also remove the part that syncs to the NAS. I have not done that version.
Cost
$0. The hook is a small Python script. Writing the request file used my existing Claude subscription, with nothing extra.
Result and what is still open
- The install worked. The hook runs on the other PC and saves the
//lines there. The quick check is the same for any PC: restart Claude Code, type//test, and look for “saved → …” in the reply. - I have not tested the hook on a PC without Python at all.
Why I like it
Before this, when a prompt turned out to be important, I copied it into Notepad by hand and saved it somewhere. Now I add // and it is saved, with the time and the project name. I don’t have to stop and do the copying.
This is the part of my setup I value most. Another person who uses Claude Code a lot also told me it is a good idea.