Feature request: Allow skills to trigger /compact programmatically
Summary
Skills (SKILL.md) currently have no way to programmatically trigger the built-in /compact command. This means a skill that saves a snapshot and wants to compact the context must ask the user to manually type /compact — breaking the single-command UX.
Use Case
I maintain AuraKit, a Claude Code skill with 33 modes. We have an /aura-compact command that:
- Saves a snapshot of the current work state to
.aura/snapshots/current.md - Should trigger
/compactto reduce context
Step 2 is currently impossible. We've tried:
echo '/compact' | claude --resume— starts a new process, doesn't affect current sessionexport CLAUDE_AUTOCOMPACT_PCT_OVERRIDE=1— only affects Bash child process, not parent harness- PowerShell
SendKeys— unreliable, platform-specific hack
None of these work because /compact is handled by the harness, and skills/AI have no API to trigger it.
Proposed Solution
One of these would solve the problem:
Option A: Add a compact field to skill/hook output JSON:
{ "compact": true }
When the harness sees this from a skill or hook, it triggers compaction after the current turn.
Option B: Add a triggerCompact() function accessible from hooks:
// In a PostToolUse or Stop hook
const { triggerCompact } = require('claude-code-hooks');
triggerCompact(); // Signals harness to compact after this hook
Option C: Allow the Skill tool to invoke built-in commands:
skill: "compact" // Currently blocked: "Do not use this tool for built-in CLI commands"
Environment
- Claude Code v2.1.84
- Windows 11
- AuraKit v6.2.1
Impact
This affects any skill that wants to offer a "save + compact" workflow. The current workaround (asking users to manually type /compact) breaks the seamless automation that skills are supposed to provide.
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗