{"slug": "make-claude-code-compact-itself-a-claude-md-rule-plus-a-script-that-types-into", "title": "Make Claude Code compact itself: a CLAUDE.md rule plus a script that types /compact into its own tmux pane once the turn ends", "summary": "A developer published a workaround that lets Claude Code trigger its own /compact command, since the tool cannot invoke it internally. A rule added to CLAUDE.md has Claude run a compact-self script as its final action, and the script waits for the turn to end before typing /compact plus the context to keep into Claude's own tmux pane and pressing Enter. The approach requires tmux, and the author notes it will not type into a pane that has been scrolled back and can collide with user input if typing begins just as a turn ends.", "body_md": "Claude Code can't run `/compact` on itself, so this does it from outside. A rule in CLAUDE.md has Claude run\n`compact-self \"<what to keep>\"` as the last thing it does when it finishes a task. The script waits in the background\nuntil the turn is over, then types `/compact <what to keep>` into Claude's own tmux pane and presses Enter.\n\nNeeds tmux.\n\n1. Save `compact-self` as`~/.claude/bin/compact-self` and make it executable (`chmod +x` ).\n2. Merge `settings.json` into`~/.claude/settings.json` . The Stop hook records when a turn ends; the allow rule lets\nClaude run the script without asking.\n3. Add the rule in `rule-for-CLAUDE.md` to`~/.claude/CLAUDE.md` .\n\nIt won't type into a pane you've scrolled back in. It doesn't check the input line, so if you start typing in that pane just as the turn ends, the two get mixed.", "url": "https://wpnews.pro/news/make-claude-code-compact-itself-a-claude-md-rule-plus-a-script-that-types-into", "canonical_source": "https://gist.github.com/27medkamal/820124876cf750967c14b1ebe55c95f8", "published_at": "2026-11-03 10:00:39+00:00", "updated_at": "2026-11-03 15:20:05.900993+00:00", "lang": "en", "topics": ["ai-agents", "ai-tools", "developer-tools"], "entities": ["Claude Code", "Anthropic", "tmux"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/make-claude-code-compact-itself-a-claude-md-rule-plus-a-script-that-types-into", "markdown": "https://wpnews.pro/news/make-claude-code-compact-itself-a-claude-md-rule-plus-a-script-that-types-into.md", "text": "https://wpnews.pro/news/make-claude-code-compact-itself-a-claude-md-rule-plus-a-script-that-types-into.txt", "jsonld": "https://wpnews.pro/news/make-claude-code-compact-itself-a-claude-md-rule-plus-a-script-that-types-into.jsonld"}}