Skip to content

fix(mcp): slim instructions to <2KB, enrich tool descriptions, add IDs to hook#139

Merged
wcatz merged 2 commits intomainfrom
fix/mcp-prompt-overhaul
Apr 1, 2026
Merged

fix(mcp): slim instructions to <2KB, enrich tool descriptions, add IDs to hook#139
wcatz merged 2 commits intomainfrom
fix/mcp-prompt-overhaul

Conversation

@wcatz
Copy link
Copy Markdown
Owner

@wcatz wcatz commented Apr 1, 2026

Problem

mcpInstructions was 3,232 bytes. Claude Code truncates at 2KB, silently dropping the Project IDs, Cross-Project, and Tasks sections. This is why Claude never knows how to handle project_id or cross-project saves.

Changes

Instructions (3,232 → 1,625 bytes):

  • Moved category list + importance scale to ghost_memory_save description
  • Moved cross-project guidance into instructions (was being truncated)
  • Added explicit project_id anchor ("use project name from hook heading")
  • Added "never pass raw filesystem paths" guidance

Tool descriptions:

  • Added concrete examples to memory_save, memory_search, save_global, decision_record
  • Added FTS5 syntax examples to search query schema
  • Improved all project_id schemas with examples (e.g. 'ghost', 'infra')
  • Differentiated ghost_memories_list from ghost_memory_search
  • Added when-to-use guidance to delete, pin, decisions_list

Hook output:

  • Added Use project_id: "ghost" for all ghost_* tool calls.
  • Memory IDs now shown ([architecture] \6BDC098A` ...`)
  • Task IDs now shown ([active] \F2A46791` P3 ...`)
  • Memory count shown ("25 shown")

Bug fix:

  • ghost_task_create priority defaulted to P0 (critical) when omitted due to Go int zero value. Now uses *int pointer, defaults to P2 (normal).

Test plan

  • go test ./... — all pass
  • Hook output verified: project_id anchor, memory IDs, task IDs
  • Instructions measured at 1,625 bytes (under 2KB limit)

Summary by CodeRabbit

  • New Features

    • Task creation accepts optional priority with automatic defaulting when omitted.
  • Improvements

    • Memory listings now show identifiers and visibility counts for easier reference.
    • Open tasks display identifiers and include optional description lines when present.
    • System guidance and tool documentation updated for clearer cross-project and workflow behavior.

…s to hook

mcpInstructions was 3,232 bytes — Claude Code truncates at 2KB,
silently dropping the Project IDs, Cross-Project, and Tasks sections.

Changes:
- Slim instructions from 3,232 to 1,625 bytes (under 2KB limit)
- Move category list, importance scale to ghost_memory_save description
- Add concrete examples to 5 most-used tool descriptions
- Add FTS5 syntax examples to search query jsonschema
- Improve all project_id jsonschema tags with examples
- Add explicit project_id anchor to hook output header
- Include memory IDs and task IDs in hook output
- Show memory count in hook ("25 shown")
- Add cross-project save guidance to instructions
- Fix priority zero-value bug: omitted priority now defaults to P2
  (was silently P0 critical due to Go int zero value)
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 1, 2026

Caution

Review failed

Pull request was closed or merged during review

📝 Walkthrough

Walkthrough

SessionStart hook output and session-context loading were changed: the hook emits a "## Ghost context" header with project_id guidance and reformats memories/tasks to include truncated IDs; loadSessionContext now returns memories and tasks tuples with added ID/description elements. MCP server instructions and tool schemas were updated; task priority became optional.

Changes

Cohort / File(s) Summary
Hook Output & Context Loading
internal/mcpinit/hook.go
Rewrote HandleSessionStartHook to emit the "## Ghost context" header (no trailing blank line), add a project_id instruction line for ghost_* tool calls, render memories as (`shortID`) with category/content and label as Memories (N shown), and render tasks with truncated id and optional description only when present. loadSessionContext tuple shapes changed: memories tuples now include id as the first element; tasks tuples include a fourth element for optional description. Added shortID helper.
MCP Instructions & Tool Schemas
internal/mcpserver/mcpserver.go
Replaced mcpInstructions content to emphasize proactive ghost_memory_save, clarify SessionStart context loading, and update project_id guidance (use project name vs paths; examples). Updated JSON schema descriptions across multiple ghost_* tools to reflect "project_id as project name" guidance. Changed ghost_task_create priority parameter from int to *int (optional) and added local defaulting before passing to s.store.CreateTask.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐇 I hopped in with IDs trimmed to eight,

Memories lined up, tidy and straight.
Tasks with whispers of descriptions small,
Project names guiding each ghostly call.
A carrot for code — organized, not late.

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the three main changes: reducing MCP instructions to under 2KB, enriching tool descriptions, and adding IDs to the hook output.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/mcp-prompt-overhaul

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@internal/mcpinit/hook.go`:
- Line 62: The code is slicing IDs with m[0][:8] (seen in the fmt.Fprintf call
that formats "- [%s] `%s` %s\n") which will panic for IDs shorter than 8; update
both occurrences (the one using m[1], m[0][:8], m[2] and the similar occurrence
around line 198) to safely compute a prefix: if len(m[0]) >= 8 use m[0][:8] else
use m[0] (or a small helper like shortID(id string) string) and use that value
in the fmt.Fprintf calls so short IDs do not cause runtime panics.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: d17b37d9-97f7-41de-af61-92b3d7d87561

📥 Commits

Reviewing files that changed from the base of the PR and between 2ce4edf and 3f67c80.

📒 Files selected for processing (2)
  • internal/mcpinit/hook.go
  • internal/mcpserver/mcpserver.go

Comment thread internal/mcpinit/hook.go Outdated
@wcatz wcatz merged commit 738ada6 into main Apr 1, 2026
4 of 5 checks passed
@wcatz wcatz deleted the fix/mcp-prompt-overhaul branch April 1, 2026 12:24
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