morph-claude-code-plugin
A Claude Code marketplace that houses Morph integration plugins. There is currently only one plugin:
- Compaction — 25,000+ tok/s context compression in sub-2s, +0.6% on SWE-Bench Pro
[!IMPORTANT]
This plugin enables morph's Flash Compact, but does NOT provide warpgrep OR fast apply. Those are available through the mcp. We strongly reccomend having BOTH the MCP and Plugin installed.
Compaction
The morph-compact plugin hooks parts of the compaction lifecycle in order to inject Morph Compact into its context.
How it works
- Pre compact hook -> Use flash compact to compact context at 33,000 tps
- Post Compact hook -> inject this context into your claude code's context (status)
- Start session hook -> This fires on session state, resume or compact. Claude will read our compacted context out of its start session context
[!IMPORTANT]
Currently there is no way to make the default calude code compaction NOT run. So we prompt inject, asking claude's own summarization model to not waste time summarizing, instead only output a few words. Your claude will use morph's provided context instead. Prompt injection is not a fool proof method, we're working on making this more reliable and consisten. We are open to PRs for this. More detailes below
The former uses the PreCompact hook and the latter uses the SessionStart hook.
Installation
Run the install skill to set up your API key and compact instructions:
/morph-compact:install
This will:
- Prompt for your Morph API key and store it in
~/.claude/morph/.env
- Add compact instructions to your global
~/.claude/CLAUDE.md
To remove:
/morph-compact:uninstall
The API key can also be provided via the MORPH_API_KEY environment variable, which takes precedence over the file.
Requirements
- Node.js 18 or newer on your
PATH, plus one of npm, pnpm or bun. The hooks are plain Node scripts; the one runtime dependency (@morphllm/morphsdk) is installed into the plugin directory automatically the first time a hook runs, using the first of those package managers found, and skipped on every run after that. Set MORPH_PACKAGE_MANAGER=npm|pnpm|bun to force one.
- Works on macOS, Linux and Windows. On Windows the hooks run under Git Bash if it is installed, otherwise PowerShell; no POSIX shell features are required either way. The key file lives at
%USERPROFILE%\.claude\morph\.env.
What gets sent to Morph
The hook does not send the raw transcript. Before the API call it:
- keeps only
user and assistant entries (Claude Code also logs its full API request bodies, system prompt included, into the same file);
- drops subagent traffic,
<system-reminder> blocks, slash-command envelopes, ANSI colour codes and the post-compaction placeholder message;
- strips the
N<tab> line-number prefixes the Read tool adds to file dumps;
- truncates each tool result to
MORPH_COMPACT_MAX_RESULT_CHARS (default 3000), keeping the head and tail;
- records tool calls as
[tool: Name] {input} with the input capped at MORPH_COMPACT_MAX_TOOL_INPUT_CHARS (default 400);
- merges the several transcript entries that make up one assistant turn back into one message.
On a session that has already been compacted once, only the entries since the last compaction are parsed and the previous Morph summary is prepended, so summaries accumulate and each call works on a small slice.
The compression ratio is capped so the result fits MORPH_COMPACT_MAX_CONTEXT_CHARS (default 40000, about 10K tokens). Claude Code does not inline hook output much larger than that; it writes it to a file and shows a short preview instead. If the summary still overshoots, it is cut at the budget and the full text is saved under <tmp>/compact-hook/<session_id>.full-summary.txt with a note in the injected context pointing to it.
Tunables (environment variables): MORPH_COMPACT_TIMEOUT (ms, default 60000), MORPH_COMPACT_RATIO (default 0.3, the ceiling), MORPH_COMPACT_PRESERVE_RECENT (default 1), MORPH_COMPACT_MAX_CONTEXT_CHARS, MORPH_COMPACT_MAX_RESULT_CHARS, MORPH_COMPACT_MAX_TOOL_INPUT_CHARS.
Debugging
Set MORPH_COMPACT_DEBUG=1 to persist what each hook saw and produced. Files are written per session under <tmp>/compact-hook/debug/<session_id>/ (override the root with MORPH_COMPACT_DEBUG_DIR):