Summary
render_inline_compact_with_registry (in plugin/src/claude_smart/context_format.py) builds a single citation marker that concatenates every injected memory's linked title+URL and instructs the model to "copy this final marker exactly." This has two costs that grow with the number of injected memories (N):
- Token scaling. The marker is O(N) — it embeds every item's title and URL, and each URL also already appears inline in the item's
open: segment (duplicated). The normal (render_inline_with_registry) path instead gives an example marker and lets the model format only what it used.
- Over-citation (correctness). Because the pre-built marker lists all N memories and the instruction says to copy it exactly, the model is nudged to cite memories it did not actually use — regardless of the
WHEN_TO_CITE_COMPACT counterfactual gate above it.
This is deliberate (there is an explicit test: tests/test_context_format.py asserts "copy this final marker exactly with markdown links"), so this is a design-tradeoff report, not a bug claim — presumably the determinism helps citation reliability on hosts like the Codex TUI.
Evidence
Measured with the repo's real renderers (tiktoken cl100k_base), synthetic playbooks/preferences at defaults (citations on, markdown links):
| N |
normal render |
compact render |
delta |
| 5 |
693 |
582 |
compact −16% (smaller) |
| 20 |
1797 |
2022 |
compact +12.5% (larger) |
| 50 |
4005 |
4902 |
compact +22.4% (larger) |
With CLAUDE_SMART_CITATIONS=off (marker removed) compact is consistently ~14% smaller at all N — i.e. the crossover is entirely the citation marker, and past ~5 injected memories the "compact" path is larger than the normal one it is meant to compress.
(Full write-up + reproducible scripts in a downstream analysis; happy to share.)
Proposed direction
Mirror the normal path in the compact citation instruction: provide an example marker + the | separator guidance (as citation_instruction already does) instead of a pre-concatenated all-N "copy exactly" marker. The model then cites only the memories it used, the marker is O(used) not O(N), and URLs are not duplicated. The WHEN_TO_CITE_COMPACT gate stays.
If the determinism is intentional for a specific host, an alternative is to cap the pre-built marker (e.g. only when N ≤ small threshold) and fall back to example-guidance beyond it.
Glad to open a PR if this direction is welcome.
Summary
render_inline_compact_with_registry(inplugin/src/claude_smart/context_format.py) builds a single citation marker that concatenates every injected memory's linked title+URL and instructs the model to "copy this final marker exactly." This has two costs that grow with the number of injected memories (N):open:segment (duplicated). The normal (render_inline_with_registry) path instead gives an example marker and lets the model format only what it used.WHEN_TO_CITE_COMPACTcounterfactual gate above it.This is deliberate (there is an explicit test:
tests/test_context_format.pyasserts"copy this final marker exactly with markdown links"), so this is a design-tradeoff report, not a bug claim — presumably the determinism helps citation reliability on hosts like the Codex TUI.Evidence
Measured with the repo's real renderers (tiktoken
cl100k_base), synthetic playbooks/preferences at defaults (citations on, markdown links):With
CLAUDE_SMART_CITATIONS=off(marker removed) compact is consistently ~14% smaller at all N — i.e. the crossover is entirely the citation marker, and past ~5 injected memories the "compact" path is larger than the normal one it is meant to compress.(Full write-up + reproducible scripts in a downstream analysis; happy to share.)
Proposed direction
Mirror the normal path in the compact citation instruction: provide an example marker + the
|separator guidance (ascitation_instructionalready does) instead of a pre-concatenated all-N "copy exactly" marker. The model then cites only the memories it used, the marker is O(used) not O(N), and URLs are not duplicated. TheWHEN_TO_CITE_COMPACTgate stays.If the determinism is intentional for a specific host, an alternative is to cap the pre-built marker (e.g. only when N ≤ small threshold) and fall back to example-guidance beyond it.
Glad to open a PR if this direction is welcome.