Skip to content

Feature request: Allow skills to trigger /compact programmatically #39275

Description

@smorky850612

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:

  1. Saves a snapshot of the current work state to .aura/snapshots/current.md
  2. Should trigger /compact to reduce context

Step 2 is currently impossible. We've tried:

  • echo '/compact' | claude --resume — starts a new process, doesn't affect current session
  • export 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    duplicateThis issue or pull request already exists

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions