Skip to content

Instantly share code, notes, and snippets.

@natew
Last active May 13, 2026 20:37
Show Gist options
  • Select an option

  • Save natew/862adc0deae26816ebb44199266f4025 to your computer and use it in GitHub Desktop.

Select an option

Save natew/862adc0deae26816ebb44199266f4025 to your computer and use it in GitHub Desktop.
manager.md
#!/bin/bash
# checks for manager feedback addressed to this session
# writes additionalContext into the conversation without blocking
INPUT=$(cat)
SESSION_ID=$(echo "$INPUT" | jq -r '.session_id // empty')
if [ -z "$SESSION_ID" ]; then
exit 0
fi
FEEDBACK_FILE="$HOME/.claude/feedback/${SESSION_ID}.md"
if [ -f "$FEEDBACK_FILE" ]; then
FEEDBACK=$(cat "$FEEDBACK_FILE")
rm "$FEEDBACK_FILE"
# escape for json
FEEDBACK_JSON=$(echo "$FEEDBACK" | jq -Rs .)
jq -n --argjson fb "$FEEDBACK_JSON" '{
"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"permissionDecision": "allow",
"additionalContext": ("⚡ MANAGER FEEDBACK ⚡\n\n" + $fb + "\n\n— This message was sent by another session via /manager. Acknowledge it briefly and adjust your work accordingly.")
}
}'
exit 0
fi
exit 0
---
description: Review and manage active Claude Code sessions in the current directory. Lists sessions, summarizes their work, and can send feedback.
---
You are the session manager. Your job is to discover, summarize, and interact with all active Claude Code sessions working in this project directory.
## Step 1: Discover active sessions
Read all session tracking files:
```
cat ~/.ccs/instances/work/sessions/*.json
```
For each session:
- Check if the PID is still alive: `kill -0 <pid> 2>/dev/null && echo alive || echo dead`
- Filter to only sessions whose `cwd` matches or is under the current working directory
- Identify YOUR OWN session by matching the current session_id — mark it as "(this session)" and skip it in summaries
The session JSON format is:
```json
{"pid": 1234, "sessionId": "uuid", "cwd": "/path", "startedAt": epoch_ms, "kind": "interactive", "name": "optional-name"}
```
## Step 2: Summarize each active session
For each alive session in this directory, read recent conversation from its JSONL log:
```
~/.ccs/instances/work/projects/<encoded-cwd>/<sessionId>.jsonl
```
Where `<encoded-cwd>` is the cwd with `/` replaced by `-` (e.g. `/Users/n8/soot` → `-Users-n8-soot`).
Extract the **last 3-5 user messages and last few assistant text blocks** to understand:
- What task the session is working on
- What it's currently doing (last tool calls, last status)
- How long it's been active
Use python3 or tail + jq to parse the JSONL efficiently — these files can be large, so read from the tail end (last ~100 lines). Use `tail -c 50000` then parse.
## Step 3: Present the report
Format output as a clear table/list:
For each session:
- **Session ID** (short: first 8 chars)
- **PID**
- **Name** (if set via `--name`)
- **Started** (human-readable relative time)
- **Last activity** (from JSONL mtime or last message timestamp)
- **Working on** (1-2 sentence summary from conversation)
- **Status** (active/idle/dead based on PID check + recency of JSONL writes)
## Step 4: Handle actions
### Sending feedback to a specific session
A PreToolUse hook (`~/.claude/hooks/check-feedback.sh`) runs on EVERY tool call in EVERY session. It checks for a feedback file at:
```
~/.claude/feedback/<session_id>.md
```
If found, the hook reads the content, injects it as `additionalContext` into the session's conversation (the agent WILL see it on its next tool call), and deletes the file.
**To send feedback to session `abcd1234-...`:**
```bash
mkdir -p ~/.claude/feedback
cat > ~/.claude/feedback/<full-session-id>.md << 'EOF'
<your feedback message here>
EOF
```
The target session will see the feedback on its very next tool call as a "MANAGER FEEDBACK" message injected into its context. No need to restart or interrupt — it's delivered automatically.
**You can also send to ALL sessions in this directory** by writing feedback files for each active session ID at once.
### Other actions
1. **Check for conflicts** — scan if multiple sessions are editing the same files (check git status from each session's recent tool calls, look for overlapping file edits)
2. **Kill a stuck session** — `kill <pid>` if a PID is alive but the session hasn't had activity in a long time
3. **Continue monitoring** — keep watching with periodic checks using /loop
## Arguments
If the user provides arguments, handle them directly:
- `/manager` — full report of all sessions
- `/manager feedback <pid-or-session-prefix> "<message>"` — send feedback to that session
- `/manager kill <pid>` — kill a stuck session
- `/manager conflicts` — check for file conflicts between sessions
When matching by PID or session prefix, look up the full session ID from the session tracking files.
## Important notes
- When showing "working on", extract the actual user prompt and recent assistant actions, not internal tool metadata.
- Skip sessions that are subagents (isSidechain=true in JSONL) — those are children of other sessions.
- Be concise. The point is a quick overview, not a deep dive into each session's full history.
- **GitHub API budget**: If checking CI status for context, use ONE `gh run list --limit 5` call. NEVER poll or loop `gh` commands — the 60 req/hr limit is shared across all sessions and burns out fast. See the GitHub API section in CLAUDE.md.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment