mcp: lines of Claude Code's own prompts in small print (#8205)

This commit is contained in:
Evgeny @ SimpleX Chat authored and GitHub committed 2026-11-14 18:04:54 +00:00
1 parent 1b64f7a46e
commit e64c2279af
6 files changed
+10 -7

No files matched your search

+1 -1
View File
@@ -648,7 +648,7 @@ With the channel, a message from a member of a session's group, other than `User
- Claude's replies to a prompt, its answer included, are posted without the quote when the prompt was deleted or the quote makes the message too large. An answer is also posted without the quote when the quote leaves no room for its first character.
- While the plugin is enabled, Claude Code shows Claude's text in the terminal by whole lines, after the plugin's MessageDisplay hook passes each batch of lines to the service, about 0.1 s later.
- `User` posts only the prompts a person typed, also one typed while Claude works. `User` skips commands such as `/compact`, empty prompts such as one with images only, and prompts made only of the plugin's `<channel source="plugin:simplex:simplex" ...>` tags. `User`'s posts are never commands of the group, even a part that starts with `/`.
- Claude posts one line for each of Claude Code's own prompts, without a quote. The line starts with an emoji for the prompt's kind:
- Claude posts one line in small print for each of Claude Code's own prompts, without a quote, so it reads apart from the prompts of people. A `!` in it is shown as `ǃ`, because `!` would end the small print. The line starts with an emoji for the prompt's kind:
- a notification of a background task, a subagent, a workflow or a monitor: its summary, such as `✅ Background command "Build" completed (exit code 0)`, and the first line of its event, when it has one, such as `📡 Monitor event: "Builds": serverpg exit 0`. The emoji is ✅ for a task that completed, ❌ for one that failed and ⏹️ for one that was stopped or killed. A notification without a status gets 📡 when it has an event, as a monitor event or the end of an artifact watch, and 🔔 otherwise. A notification in plain text, such as `3 background agents were stopped by the user: ...`, gets 🔔 and its first line;
- a message of another Claude session: `✉️ Message from NAME: ` and its first line;
- a message of a teammate in an agent team: `✉️ Message from NAME: ` and its summary, or its first line without one. A prompt with several teammate messages gets the line of the first one that is not an idle notification, and a prompt of idle notifications only gets no line;
+1 -1
View File
@@ -205,7 +205,7 @@ In a session started as in step 2 above:
1. At the session start, Claude Code shows `SimpleX MCP: scan this QR code with the SimpleX app and tap Join to supervise your agents in "Claude Control":`, a QR code and the link. Ask Claude which link was shown at the session start. Claude doesn't know it. If Claude Code refuses `plugin:simplex@inline` with the development flag, checks 3, 5, 6, 7, 8 and 21 wait for the published plugin and `plugin:simplex@simplex-chat`.
2. Scan the QR code in the SimpleX app and tap Join. In "Claude Control", tap the invitation to "1 · <folder>" and join it.
3. Send `Reply with the word ready.` in "1 · <folder>". The answer comes from Claude, as a reply to your message. In an app that shows peer types in groups, Claude has the agent placeholder, three dots, and `User` the person placeholder.
4. Type a prompt in the terminal. It appears in the group from `User`, and the answer appears from Claude. Record whether a prompt from the group also appears from `User`, because Claude Code's documentation does not say whether a channel prompt runs the UserPromptSubmit hook. Ask Claude to run `sleep 5` with Bash in the background. When the task ends, its notification does not appear from `User`; Claude posts a line that starts with ✅ instead. Ask Claude to start a background agent that replies with one word, and to schedule a one-time prompt with CronCreate two minutes ahead. Each appears as one line from Claude. While Claude runs a foreground command, type a prompt in the terminal: it appears from `User`. Ask Claude to read a file and run `sleep 12` with Bash. A line from Claude appears for each step when it starts, `📖 Read PATH` and `💻 ...`, shown as live while the step runs, all in small print, and each is completed with its duration, `12 s` for the sleep, without ✅ and without an edited mark. With an app that supports silent messages, the lines, the notes and Claude's texts do not alert, and an answer posted as a new message, with its end line, does.
4. Type a prompt in the terminal. It appears in the group from `User`, and the answer appears from Claude. Record whether a prompt from the group also appears from `User`, because Claude Code's documentation does not say whether a channel prompt runs the UserPromptSubmit hook. Ask Claude to run `sleep 5` with Bash in the background. When the task ends, its notification does not appear from `User`; Claude posts a line in small print that starts with ✅ instead. Ask Claude to start a background agent that replies with one word, and to schedule a one-time prompt with CronCreate two minutes ahead. Each appears as one line in small print from Claude. While Claude runs a foreground command, type a prompt in the terminal: it appears from `User`. Ask Claude to read a file and run `sleep 12` with Bash. A line from Claude appears for each step when it starts, `📖 Read PATH` and `💻 ...`, shown as live while the step runs, all in small print, and each is completed with its duration, `12 s` for the sleep, without ✅ and without an edited mark. With an app that supports silent messages, the lines, the notes and Claude's texts do not alert, and an answer posted as a new message, with its end line, does.
5. Send `Count from 1 to 300, one number per line.` in the group, and at once send `Reply with the word two.` The second prompt waits in Claude Code's queue. Claude quotes the first message in the answer with the numbers, and the second message in the answer `two`. Neither prompt appears from `User`. The hub chooses the quote of each answer by the start times of the Stop and UserPromptSubmit hooks, and this check confirms that. Then reply to Claude's answer of check 3 with `Say it again in capitals.` Claude answers in capitals with the word of check 3, as a reply to your message. Send a photo, and reply to it with `What is in this photo?` In the transcript, the tag of the first reply contains `reply_to_from="Claude"`, and its content starts with `> ` and that answer; the content of the second starts with `> image: ` and the photo's file name.
6. React 👍 to Claude's answer of check 3. Claude answers as a reply to that answer, and `User` posts nothing. In the transcript, the tag has `reply_to` equal to `item`, and its content is `> ` and that answer, with 👍 on the next line. Remove the reaction, and nothing happens. Send `Count from 1 to 300, one number per line.`, and react ❤ to that message while Claude counts. Claude answers the reaction in the next turn, as a reply to that message.
7. Send `//help` in the group. A one-line message that starts with `/` is a command of the group, so Claude replies `Unknown command.`, and the session gets nothing. Send `!git status`. The session gets it as a prompt, and Claude answers it. Claude Code never runs a command from a channel prompt. Claude Code 2.1.319 was checked on 2026-11-08 with a test channel. It ran neither a command nor a shell command from a channel prompt that started with `/` or `!`, and it passed the text to Claude in the `<channel>` tag. After `/model sonnet`, the model was unchanged, and after `!echo`, no file was written. In the code of Claude Code 2.1.322, a channel message is queued as a prompt with `skipSlashCommands` set. Claude may act on such a text with its tools, such as Bash, under the tool-use approval of check 8.
+1 -1
View File
@@ -1158,7 +1158,7 @@ Claude Code runs the person's `statusLine` command through a shell after each re
The UserPromptSubmit hook finds the prompt's record among the last entries of the transcript. A record is a user entry, without subagent entries and tool results, or a `queued_command` attachment, the record of a prompt that Claude Code added to a running turn. The record is the newest one whose text equals the prompt: the entry whose `promptId` equals the hook's `prompt_id`, or a record after the first entry with that ID. Claude Code gives the hook of a prompt added to a running turn that turn's prompt ID, and the turn's tool results carry it too, so the first entry with that ID is found also when the turn's first entry is out of the tail. Until an entry with `prompt_id` is in the tail, the hook waits for it, and at the last read it takes any record with the prompt's text. While a `queue-operation` `enqueue` entry with the prompt's text follows the record, the hook waits too: the prompt is a later one with the same text, still queued. Without `prompt_id`, as in older Claude Code, it takes any record at once. `typed` is true when the record's `origin.kind` is `human`, and `midTurn` is true when the record is not the entry with `prompt_id`. Claude Code writes the entry only after the synchronous UserPromptSubmit hooks end, and it creates the transcript file with the session's first entry. So the hook reads the transcript up to 600 times, 100 ms apart. A missing transcript is read again, as a transcript without the entry is. Claude Code runs the hook of a person's prompt when it is submitted, and of its own prompts only when they are taken. So at the last read, the hook classifies a record still followed by such an `enqueue` entry by the record, and marks a typed one mid-turn: the queued prompt is the typed prompt itself, or a later prompt with the text of Claude Code's own prompt. When no record is found within these reads, an `enqueue` entry with the prompt's text after the entry with `prompt_id`, or anywhere without that entry, makes the prompt typed and mid-turn. Otherwise `typed` is true when an entry with `prompt_id` has the origin `human` ([`promptReads`, `transcriptReadMs`, `promptKind`, `findInTranscript`, `promptRecord`, `isPrompt`, `recordText`, `recordKind`](../src/hook.ts)).
The UserPromptSubmit hook's `note` is a line of at most 200 characters; a longer one is cut to 199 and ends with `…`. A typed prompt, a channel prompt, a teammate's prompt of idle notifications only and another record without origin that is not scheduled have no note ([`recordKind`, `noteOf`, `taskNote`, `teammateNote`, `idleNotification`, `peerName`, `firstLine`, `decoded`, `stringOf`, `shortened`](../src/hook.ts)):
The UserPromptSubmit hook's `note` is a line of at most 200 characters; a longer one is cut to 199 and ends with `…`. It is sent in small print, `!- NOTE!`, with each `!` of NOTE replaced with `ǃ` (`small`). A typed prompt, a channel prompt, a teammate's prompt of idle notifications only and another record without origin that is not scheduled have no note ([`recordKind`, `noteOf`, `taskNote`, `teammateNote`, `idleNotification`, `peerName`, `firstLine`, `decoded`, `stringOf`, `shortened`](../src/hook.ts)):
| Kind | Record | Line |
|---|---|---|
+1 -1
View File
@@ -375,7 +375,7 @@ function recordKind(record: TranscriptEntry, id: string | undefined, text: strin
const origin = record.type === "attachment" ? (record.attachment?.origin ?? (record.attachment?.commandMode === "task-notification" ? {kind: "task-notification"} : undefined)) : record.origin
const note = noteOf(origin, record.turnOrigin, text)
const midTurn = record.type !== "user" || (id !== undefined && record.promptId !== id)
return {typed: origin?.kind === "human", ...(note === undefined ? {} : {note: shortened(note)}), ...(midTurn ? {midTurn} : {})}
return {typed: origin?.kind === "human", ...(note === undefined ? {} : {note: small(shortened(note))}), ...(midTurn ? {midTurn} : {})}
}
// spec: spec/architecture.md#hook-noteof
@@ -456,12 +456,12 @@ test("the hooks post a prompt typed in the terminal as User, also the session's
await hook({hook_event_name: "Stop", last_assistant_message: "Tests pass."})
await passed
const notification = '<task-notification>\n<task-id>b1</task-id>\n<status>completed</status>\n<summary>Background command "Build" completed (exit code 0)</summary>\n</task-notification>'
const noted = received(alice.chat, message('✅ Background command "Build" completed (exit code 0)', "Claude"))
const noted = received(alice.chat, message('!- ✅ Background command "Build" completed (exit code 0)!', "Claude"))
appendFileSync(transcript, userEntry("p2", notification, "task-notification"))
await hook({hook_event_name: "UserPromptSubmit", transcript_path: transcript, prompt_id: "p2", prompt: notification})
await noted
const midTurn = '<task-notification>\n<task-id>b2</task-id>\n<status>failed</status>\n<summary>Background command "Lint" failed with exit code 1</summary>\n</task-notification>'
const midTurnNoted = received(alice.chat, message('❌ Background command "Lint" failed with exit code 1', "Claude"))
const midTurnNoted = received(alice.chat, message('!- ❌ Background command "Lint" failed with exit code 1!', "Claude"))
appendFileSync(transcript, `${JSON.stringify({type: "attachment", attachment: {type: "queued_command", prompt: midTurn, origin: {kind: "task-notification"}, commandMode: "task-notification"}})}\n`)
await hook({hook_event_name: "UserPromptSubmit", transcript_path: transcript, prompt_id: "p2", prompt: midTurn})
await midTurnNoted
@@ -300,7 +300,8 @@ describe("turn hooks", () => {
const userEntry = (promptId: string, content: unknown, extra: object = {}) => `${JSON.stringify({type: "user", promptId, ...extra, message: {role: "user", content}})}\n`
const queuedEntry = (prompt: string, origin: object) => `${JSON.stringify({type: "attachment", attachment: {type: "queued_command", prompt, origin, commandMode: "prompt"}})}\n`
const enqueueEntry = (content: string) => `${JSON.stringify({type: "queue-operation", operation: "enqueue", content})}\n`
const kinds = (requests: unknown[]) => requests.map(request => (request as {body: {note?: string; typed: boolean; midTurn?: boolean}}).body).map(({note, typed, midTurn}) => [note, typed, midTurn])
const notes = (requests: unknown[]) => requests.map(request => (request as {body: {note?: string; typed: boolean; midTurn?: boolean}}).body)
const kinds = (requests: unknown[]) => notes(requests).map(({note, typed, midTurn}) => [note?.replace(/^!- ([\s\S]*)!$/, "$1"), typed, midTurn])
it("send a one-line note of each kind of Claude Code's own prompt, from the origin of its transcript entry, and none for a typed or a channel prompt", async () => {
const folder = mkdtempSync(join(tmpdir(), "simplex-mcp-transcript-"))
@@ -345,6 +346,8 @@ describe("turn hooks", () => {
[undefined, false, undefined],
[`${prefix}${"x".repeat(199 - [...prefix].length)}…`, false, undefined],
])
expect(notes(requests).flatMap(({note}) => (note === undefined ? [] : [note.startsWith("!- ") && note.endsWith("!")]))).toEqual(Array(12).fill(true))
expect(notes(requests)[5].note).toBe("!- ✉️ Message from mcp-impl2: I read the evidence.!")
} finally {
rmSync(folder, {recursive: true, force: true})
}