m4rs0n on Discord: since #2432 (eb8b840dd) a Claude subscription conversation in the interactive mode broke the prompt cache as it grew. The same body sent again read 100% from the cache, but the same body plus an assistant "ok" and a new user turn read only 1,273 of 8,565 tokens and wrote 7,290. A tool loop read a constant 1,273 every call (opus 1,273, sonnet 1,197, haiku 2,000: Claude Code's own system prompt). Cause:eb8b840ddgave a one-off ask (no tools, no reply) its caller's instructions with --append-system-prompt-file, after Claude Code's own prompt, and lets that run go after its reply. Every other run (with tools, with a reply, a resumed or replayed session) kept them in the first pasted message. So the conversation's next request started a run whose system block ended at Claude Code's prompt and whose first message held the instructions. The cached prefix broke right after Claude Code's prompt, and the rest was written again. A tool loop's runs did the same: a pasted first message loses magpie's mark (the paste is one text). The bisect v0.1.2676..v0.1.2677 has only541102eba(the onboarding mark), which doesn't touch the request. Before it, those runs were -p, which keeps the marks. Change: - appendsPrompt no longer requires no tools and no reply. Every interactive run that isn't lean and has no client cache marks appends the instructions. -p keeps them in the first message, where its mark holds. - A run that resumes a session (shelved, branched, branchAt, or a replaySession transcript) is given the file again when the session's run had it (savedSession.appended). Sessions keep no system prompt, and every run key holds the system prompt, so the file is the one the session's run had. Appended runs can now be shelved and branched, which they couldn't before. - replaySession leaves the instructions out of the transcript's user line when they are appended. - docs/subsystems/claude-subscription-bridge.md says so. Tests: - TestClaudeTUIConversationKeepsItsInstructionsWhereTheFirstAskHadThem is the reporter's sequence: A, then A + "ok" + "Now say two words." Both runs are given the same append file, which starts with the rules. No run is typed them, and no session file holds them. - TestClaudeTUIResumedSessionIsGivenItsInstructions: a shelved session is resumed with its append file. - TestClaudeAppendInTheInteractiveMode replaces TestClaudeAppendOnlyForInteractiveOneOffs. Tools and reply append in the interactive mode; client marks and -p don't. - TestClaudeTUIReplayGoesInATranscript now expects the rules out of the transcript's user line and the append flag on the run. Run at the pushed head, on mote: - go test ./internal/gateway -run 'Claude|TUI|Subscription|Replay|Branch|Lean|Append|Shelve|Resume': ok. - GOOS=linux and GOOS=windows go vet ./internal/gateway: ok. - gofmt -l: clean. - The full internal/gateway package was red once, before the replay test was updated, with the failing test cut off by a tail. A rerun with the whole log is under way. Its result goes in the report and, if red, in an issue. Broken by hand: the new tests on origin/main's code fail. - TestClaudeAppendInTheInteractiveMode/tools and /reply fail. - The conversation test fails ("given ... and <none> after Claude Code's system prompt, want the same instructions"). - The resumed test fails. - With only the savedSession.appended carry removed, the resumed test fails ("<none> ... want A's instructions"). Not tried: - A real Claude account. The sandbox recipe needs a live login's OAuth token copied out, and rotated tokens written back, which this session's rules forbid. The prefix claim rests on Claude Code 2.1.316 marking the end of its system block itself (recorded 2026-11-03 for #2432), not on a new real request. - Windows and WSL runs of the interactive mode. Sibling paths: - Streaming and non-streaming both start runs through startRun. - count_tokens doesn't write the cache. - An API-key Claude request is passed through with the client's own marks, outside this bridge.
Subsystem design references
These pages describe current responsibilities, runtime paths, state, and contracts. Start with the subsystem relevant to your task, then follow its source links to verify the implementation you change.
| Subsystem | Reference |
|---|---|
| Built-in subscriptions moving to plugins | Provider and plugin ownership |
| Built-in plugins: registry, lifecycle, plugins.yml, presets, settings schemas, the window's kernel (slots, error boundary, kit) | Plugin runtime |
| Plugins that run on the gateway's requests and replies | Gateway middleware |
| Tools that plugins give, offered to every agent as an MCP server | Plugin tools |
| Plugins that await context recall and observe completed replies | Asynchronous gateway request hooks |
| Claude subscription turns across Claude Code runs | Claude subscription bridge |
| How the gateway picks a provider, key or account, and falls back | Gateway routing and fallback |
| Gateway Session Aggregation | Gateway Session Aggregation |
| Connecting an agent's config to the gateway, drift, disconnect, WSL twins | Agent wiring |
| Providers, keys, subscription accounts, refresh and allowance | Providers and accounts |
| Instructions, MCP servers, skills and RTK written into agents | Library |
| One MCP server, magpie, given to every agent in place of the Library's servers | MCP router |
Tray, panel, window, magpie web and the page's JSON API |
GUI app shell |
| Encrypted backups and setup synchronization over WebDAV, S3 or GitHub | Sync and backup |
A subsystem can span several packages or repositories. Its reference describes the behavior those parts provide together; it does not need to list every function.
Maintain a reference
Update the owning reference in the same PR when a change alters a documented responsibility, interface, state transition, runtime path, compatibility rule, or failure behavior. An internal refactor that preserves these contracts does not require a prose change.
Keep each fact in one reference and link to it from agent instructions or other pages. Link to source files and named symbols rather than copying implementation details that change frequently. Explain field meanings and constraints that signatures alone do not express.
For a new reference, include the responsibilities and boundaries, source of truth, main runtime paths, state transitions, important constraints, and existing verification commands. Include failure and compatibility behavior where relevant. Document current behavior separately from proposed changes; the proposal belongs in its issue or PR.
Describe a PR's semantic changes
For each affected subsystem, explain the observable change with its trigger and before/after behavior. Include changes to interfaces, state, compatibility, and failure behavior when relevant. Link the affected reference, implementation, and verification evidence. State when a refactor preserves the documented behavior.
For example, a change to plugin adoption should explain which migration state and account condition trigger it, which implementation handles requests before and after adoption, and which test exercises that transition.
This is an author-provided explanation that a reviewer verifies against the diff and surrounding code. It is not an automatically proven compatibility verdict.
Review a change
- Identify the affected subsystem and the actual runtime path, including plugin or built-in ownership.
- Compare the claimed before/after behavior with the base and head implementation. Trace relevant callers and state transitions beyond the changed lines.
- Check that changed contracts appear in the owning reference and that source links still resolve.
- Check that the cited tests or runtime evidence exercise the claimed behavior. Report checks that were not run.
A documentation update alone does not prove the implementation. Existing tests and runtime evidence remain necessary for behavior changes.