Context: Studying Claude Code source code (backup branch)
How Skills Translate to What the Model Sees
Skills are injected as user-role messages with isMeta: true. The flag hides them from the user-visible transcript but the API sees them as standard user messages. There’s no weighting mechanism to deprioritize them.
getMessagesForPromptSlashCommand (processSlashCommand.tsx:827) builds multiple messages per skill invocation:
- Metadata message with
<command-name>XML tags (regular user message) - Full SKILL.md content after argument substitution (
isMeta: true) - Attachment messages for @-mentions, MCP resources
- Permission attachment granting additional tools
For SkillTool (model-driven), these become newMessages on the tool result, pushed into resultingMessages by toolExecution.ts:1566-1569, appended right after the tool_result block.
Why Skills Feel Overpowering: The Compaction Mechanism
When context is compressed (compact.ts):
- Earlier conversation gets summarized into a lossy compact summary
- Invoked skills are explicitly preserved via
createSkillAttachmentIfNeeded()(compact.ts:1494) - Skills sorted most-recent-first, each truncated to 5,000 tokens, total budget 25,000 tokens (~5 skills)
- The skill listing itself is NOT re-injected post-compact (line 524-529), but individual invoked skill content survives verbatim
Post-compaction message structure:
[system prompt]
[compact summary of prior conversation] <-- lossy
[skill content, isMeta: true] <-- preserved verbatim, up to 5K tokens each
[tool results, recent messages] <-- full fidelity
Skills are structurally privileged: injected as recent user messages, survive compaction intact, while earlier conversation context is compressed away. The model naturally treats recent user-role messages as high-priority instructions.