Skip to content

feat: /context command + /compress focus — inspired by Claude Code#7459

Closed
teknium1 wants to merge 1 commit into
mainfrom
claude-code-inspired/context-breakdown
Closed

feat: /context command + /compress focus — inspired by Claude Code#7459
teknium1 wants to merge 1 commit into
mainfrom
claude-code-inspired/context-breakdown

Conversation

@teknium1

Copy link
Copy Markdown
Contributor

Summary

Two features inspired by Claude Code's recent releases (v2.1.89–v2.1.101):

1. /context command (alias: /ctx)

Shows a live breakdown of context window usage by component, matching Claude Code's /context feature:

◎ Context Window — claude-sonnet-4.6
  ██████████░░░░░░░░░░░░░░░░░░░░  52.3K / 200.0K tokens (26%)

  ◆ System Prompt              18.2K
      Identity (SOUL.md)        1.5K
      Memory                    0.8K
      User profile              0.3K
      Skills index              8.4K
      Context files             5.2K
      Other (guidance, hints)   2.0K
  ◆ Tool Schemas (42 tools)     8.1K
  ◆ Conversation (24 msgs)     26.0K
      User messages (8)         4.2K
      Assistant messages (8)    6.8K
      Tool results (8)         15.0K

  ⚙ Auto-compress at: ~160.0K tokens (107.7K remaining)

Source: Claude Code /context

2. /compress <focus> — guided compression

The existing /compress command now accepts an optional focus topic:

/compress database schema

When provided, the summariser prioritises preserving information related to the focus topic (60-70% of summary budget) while being more aggressive about compressing everything else.

Source: Claude Code /compact

Implementation Details

  • /context: New _show_context_breakdown() method in cli.py that analyses the cached system prompt, conversation messages, and tool schemas
  • /compress focus: focus_topic flows through _manual_compress_compress_contextContextCompressor.compress_generate_summary, where it's appended to the LLM summarisation prompt
  • CommandDef added to commands.py with alias ctx
  • 15 new tests covering both features

What's NOT changed

  • No changes to prompt caching
  • No changes to message flow invariants
  • No changes to system prompt assembly
  • The /compress command without arguments works exactly as before

Files changed

  • hermes_cli/commands.py — CommandDef for /context + args_hint for /compress
  • cli.py_show_context_breakdown() + enhanced _manual_compress()
  • run_agent.pyfocus_topic parameter on _compress_context()
  • agent/context_compressor.pyfocus_topic flows to _generate_summary()
  • tests/cli/test_context_breakdown.py — 15 tests

Test results

576 passed, 0 failures (cli + commands + context_compressor tests)

Two features inspired by Claude Code's recent releases (v2.1.89–v2.1.101):

1. /context command (alias: /ctx)
   Shows a live breakdown of context window usage by component:
   - System prompt (identity, memory, skills index, context files, guidance)
   - Tool schemas (count and token estimate)
   - Conversation messages (by role: user, assistant, tool results)
   - Compaction summaries
   - Auto-compress threshold and remaining tokens
   - Visual progress bar

   This gives users visibility into what is consuming their context window,
   matching Claude Code's /context feature.

2. /compress <focus> — guided compression
   The existing /compress command now accepts an optional focus topic:
   /compress database schema
   When provided, the summariser prioritises preserving information related
   to the focus topic (60-70% of summary budget) while being more aggressive
   about compressing everything else.

   Inspired by Claude Code's /compact <focus> feature.

Implementation details:
- /context: new _show_context_breakdown() method in cli.py
- /compress focus: focus_topic flows through _manual_compress → _compress_context
  → ContextCompressor.compress → _generate_summary, where it's appended to the
  LLM summarisation prompt
- 15 new tests covering both features
- No changes to prompt caching, message flow, or system prompt assembly
teknium1 added a commit that referenced this pull request Apr 12, 2026
Adds an optional focus topic to /compress: `/compress database schema`
guides the summariser to preserve information related to the focus topic
(60-70% of summary budget) while compressing everything else more aggressively.
Inspired by Claude Code's /compact <focus>.

Changes:
- context_compressor.py: focus_topic parameter on _generate_summary() and
  compress(); appends FOCUS TOPIC guidance block to the LLM prompt
- run_agent.py: focus_topic parameter on _compress_context(), passed through
  to the compressor
- cli.py: _manual_compress() extracts focus topic from command string,
  preserves existing manual_compression_feedback integration (no regression)
- gateway/run.py: _handle_compress_command() extracts focus from event args
  and passes through — full gateway parity
- commands.py: args_hint="[focus topic]" on /compress CommandDef

Salvaged from PR #7459 (CLI /compress focus only — /context command deferred).
15 new tests across CLI, compressor, and gateway.
teknium1 added a commit that referenced this pull request Apr 12, 2026
Adds an optional focus topic to /compress: `/compress database schema`
guides the summariser to preserve information related to the focus topic
(60-70% of summary budget) while compressing everything else more aggressively.
Inspired by Claude Code's /compact <focus>.

Changes:
- context_compressor.py: focus_topic parameter on _generate_summary() and
  compress(); appends FOCUS TOPIC guidance block to the LLM prompt
- run_agent.py: focus_topic parameter on _compress_context(), passed through
  to the compressor
- cli.py: _manual_compress() extracts focus topic from command string,
  preserves existing manual_compression_feedback integration (no regression)
- gateway/run.py: _handle_compress_command() extracts focus from event args
  and passes through — full gateway parity
- commands.py: args_hint="[focus topic]" on /compress CommandDef

Salvaged from PR #7459 (CLI /compress focus only — /context command deferred).
15 new tests across CLI, compressor, and gateway.
@teknium1

Copy link
Copy Markdown
Contributor Author

The /compress feature from this PR was salvaged and merged via PR #8017 — rebased onto current main with no regressions (preserved manual_compression_feedback integration) and added full gateway parity. The /context command was deferred — context breakdown will be folded into /usage instead.

@teknium1 teknium1 closed this Apr 12, 2026
Tommyeds pushed a commit to Tommyeds/hermes-agent that referenced this pull request Apr 12, 2026
…search#8017)

Adds an optional focus topic to /compress: `/compress database schema`
guides the summariser to preserve information related to the focus topic
(60-70% of summary budget) while compressing everything else more aggressively.
Inspired by Claude Code's /compact <focus>.

Changes:
- context_compressor.py: focus_topic parameter on _generate_summary() and
  compress(); appends FOCUS TOPIC guidance block to the LLM prompt
- run_agent.py: focus_topic parameter on _compress_context(), passed through
  to the compressor
- cli.py: _manual_compress() extracts focus topic from command string,
  preserves existing manual_compression_feedback integration (no regression)
- gateway/run.py: _handle_compress_command() extracts focus from event args
  and passes through — full gateway parity
- commands.py: args_hint="[focus topic]" on /compress CommandDef

Salvaged from PR NousResearch#7459 (CLI /compress focus only — /context command deferred).
15 new tests across CLI, compressor, and gateway.
ulasbilgen pushed a commit to ulasbilgen/hermes-adhd-agent that referenced this pull request May 1, 2026
…search#8017)

Adds an optional focus topic to /compress: `/compress database schema`
guides the summariser to preserve information related to the focus topic
(60-70% of summary budget) while compressing everything else more aggressively.
Inspired by Claude Code's /compact <focus>.

Changes:
- context_compressor.py: focus_topic parameter on _generate_summary() and
  compress(); appends FOCUS TOPIC guidance block to the LLM prompt
- run_agent.py: focus_topic parameter on _compress_context(), passed through
  to the compressor
- cli.py: _manual_compress() extracts focus topic from command string,
  preserves existing manual_compression_feedback integration (no regression)
- gateway/run.py: _handle_compress_command() extracts focus from event args
  and passes through — full gateway parity
- commands.py: args_hint="[focus topic]" on /compress CommandDef

Salvaged from PR NousResearch#7459 (CLI /compress focus only — /context command deferred).
15 new tests across CLI, compressor, and gateway.
aj-nt pushed a commit to aj-nt/hermes-agent that referenced this pull request May 1, 2026
…search#8017)

Adds an optional focus topic to /compress: `/compress database schema`
guides the summariser to preserve information related to the focus topic
(60-70% of summary budget) while compressing everything else more aggressively.
Inspired by Claude Code's /compact <focus>.

Changes:
- context_compressor.py: focus_topic parameter on _generate_summary() and
  compress(); appends FOCUS TOPIC guidance block to the LLM prompt
- run_agent.py: focus_topic parameter on _compress_context(), passed through
  to the compressor
- cli.py: _manual_compress() extracts focus topic from command string,
  preserves existing manual_compression_feedback integration (no regression)
- gateway/run.py: _handle_compress_command() extracts focus from event args
  and passes through — full gateway parity
- commands.py: args_hint="[focus topic]" on /compress CommandDef

Salvaged from PR NousResearch#7459 (CLI /compress focus only — /context command deferred).
15 new tests across CLI, compressor, and gateway.
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…search#8017)

Adds an optional focus topic to /compress: `/compress database schema`
guides the summariser to preserve information related to the focus topic
(60-70% of summary budget) while compressing everything else more aggressively.
Inspired by Claude Code's /compact <focus>.

Changes:
- context_compressor.py: focus_topic parameter on _generate_summary() and
  compress(); appends FOCUS TOPIC guidance block to the LLM prompt
- run_agent.py: focus_topic parameter on _compress_context(), passed through
  to the compressor
- cli.py: _manual_compress() extracts focus topic from command string,
  preserves existing manual_compression_feedback integration (no regression)
- gateway/run.py: _handle_compress_command() extracts focus from event args
  and passes through — full gateway parity
- commands.py: args_hint="[focus topic]" on /compress CommandDef

Salvaged from PR NousResearch#7459 (CLI /compress focus only — /context command deferred).
15 new tests across CLI, compressor, and gateway.
olympus-terminal pushed a commit to olympus-terminal/hermes-agent that referenced this pull request May 16, 2026
…search#8017)

Adds an optional focus topic to /compress: `/compress database schema`
guides the summariser to preserve information related to the focus topic
(60-70% of summary budget) while compressing everything else more aggressively.
Inspired by Claude Code's /compact <focus>.

Changes:
- context_compressor.py: focus_topic parameter on _generate_summary() and
  compress(); appends FOCUS TOPIC guidance block to the LLM prompt
- run_agent.py: focus_topic parameter on _compress_context(), passed through
  to the compressor
- cli.py: _manual_compress() extracts focus topic from command string,
  preserves existing manual_compression_feedback integration (no regression)
- gateway/run.py: _handle_compress_command() extracts focus from event args
  and passes through — full gateway parity
- commands.py: args_hint="[focus topic]" on /compress CommandDef

Salvaged from PR NousResearch#7459 (CLI /compress focus only — /context command deferred).
15 new tests across CLI, compressor, and gateway.
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
…search#8017)

Adds an optional focus topic to /compress: `/compress database schema`
guides the summariser to preserve information related to the focus topic
(60-70% of summary budget) while compressing everything else more aggressively.
Inspired by Claude Code's /compact <focus>.

Changes:
- context_compressor.py: focus_topic parameter on _generate_summary() and
  compress(); appends FOCUS TOPIC guidance block to the LLM prompt
- run_agent.py: focus_topic parameter on _compress_context(), passed through
  to the compressor
- cli.py: _manual_compress() extracts focus topic from command string,
  preserves existing manual_compression_feedback integration (no regression)
- gateway/run.py: _handle_compress_command() extracts focus from event args
  and passes through — full gateway parity
- commands.py: args_hint="[focus topic]" on /compress CommandDef

Salvaged from PR NousResearch#7459 (CLI /compress focus only — /context command deferred).
15 new tests across CLI, compressor, and gateway.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant