claude-code-mods
Claude Code mods and themes: lines above the prompt, guards, panes, games and Desktop themes.
Safety scan
A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.
Check it deeper on your machine
It has changed since its scan on 17 Nov 2026.
As a Claude Code plugin, install it and then ask Claude Code:
/plugin marketplace add keithmackay/mackayi/plugin install scanskillsafety@mackayiDo a deep scan of https://github.com/hamzafer/claude-code-mods with scanskillsafety
Or from a terminal, clone it and run it:
git clone https://github.com/keithmackay/scanskillsafety-skill ~/.claude/skills/scanskillsafetynode ~/.claude/skills/scanskillsafety/cli.cjs --deep 'https://github.com/hamzafer/claude-code-mods'
It checks the exact commit: every file, its packages against OSV (api.osv.dev), how it compares with this page's scan (findsafeskills.com receives the repository's address), and, if you agree, Claude reading every file with your own Claude subscription. It never runs the code.
Badge for your README
Markdown
[](/listings/hamzafer--claude-code-mods)HTML
<a href="/listings/hamzafer--claude-code-mods"><img src="/api/listings/hamzafer--claude-code-mods/badge.svg" alt="findsafeskills safety rating" /></a>Install
Install instructions from the README
As written by the repo's author. findsafeskills has not verified these steps.
npx claude-code-mods@latest
Tick the mods you want, press Enter, restart Claude Code. Needs Claude Code 2.1.287+. [Flags and other ways to install](docs/install.md).
<table> <tr> <td align="center" width="33%"><a href="docs/mods.md#-context-bar"><img src="images/context-bar.png" alt="context-bar: Claude Code context window usage as a stacked bar, a color per category" width="260"></a><br><b>context-bar</b><br>what fills your context</td> <td align="center" width="33%"><a href="docs/mods.md#-review-watch"><img src="images/review-watch.png" alt="review-watch: live lines for running Codex and subagent code reviews in Claude Code" width="260"></a><br><b>review-watch</b><br>running code reviews, live</td> <td align="center" width="33%"><a href="docs/mods.md#-md-preview"><img src="images/md-preview.png" alt="md-preview: Markdown that Claude Code edits, rendered like GitHub next to the diff" width="260"></a><br><b>md-preview</b><br>Markdown rendered like GitHub</td> </tr> <tr> <td align="center" width="33%"><a href="docs/mods.md#-blast-radius"><img src="images/gallery/blast-radius.png" alt="blast-radius: a Claude Code hook holds rm -rf and lists the files it would delete" width="260"></a><br><b>blast-radius</b><br>see what <code>rm -rf</code> would delete</td> <td align="center" width="33%"><a href="docs/mods.md#-switchboard"><img src="images/switchboard.png" alt="switchboard: subagents routed from opus to sonnet and haiku, with confidence and cost" width="260"></a><br><b>switchboard</b><br>cheaper models for subagents</td> <td align="center" width="33%"><a href="docs/mods.md#-now-playing"><img src="images/now-playing.png" alt="now-playing: Spotify track, progress bar and synced lyrics inside Claude Code" width="260"></a><br><b>now-playing</b><br>Spotify and its lyrics, live</td> </tr> </table>
<a id="-the-mods"></a>
What was scanned
The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.
.claude-plugin/marketplace.json · Manifest · 406 lines
- {
- "name": "claude-code-mods",
- "description": "Claude Code mods and themes: lines above the prompt, guards, panes, games and Desktop themes.",
- "owner": {
- "name": "hamzafer"
- },
- "plugins": [
- {
- "name": "agent-radar",
- "description": "One live line above the prompt per running subagent or background shell: its model, time, tool count and what it's doing. /radar shows every agent and its messages.",
- "version": "0.3.3",
- "source": "./mods/agent-radar",
- "category": "See what's happening",
- "tags": [
- "band",
- "pane",
- "toast",
- "command"
- ]
- },
- {
- "name": "blast-radius",
- "description": "Holds risky Bash commands and shows what they would change before they run.",
- "version": "0.2.6",
- "source": "./mods/blast-radius",
- "category": "Guard your repo",
- "tags": [
- "band",
- "pane",
- "guard",
- "command"
- ]
- },
- {
- "name": "secret-guard",
- "description": "Keeps API keys and tokens out of Claude's context, your files and your commits: hides them in tool output, and asks before a write, commit or push adds one.",
- "version": "0.1.3",
- "source": "./mods/secret-guard",
- "category": "Guard your repo",
- "tags": [
- "guard",
- "toast",
- "command"
- ]
- },
- {
- "name": "context-bar",
- "description": "Your context window as a stacked bar above the prompt, a color per category, with token counts and the compaction point. /context-bar shows or hides it.",
- "version": "0.1.6",
- "source": "./mods/context-bar",
- "category": "See what's happening",
- "tags": [
- "band",
- "command"
- ]
- },
- {
- "name": "browser-lanes",
- "description": "Shows if this session has a Playwright browser and who holds it. /browser clean closes leftover browsers. A subagent that wants the browser waits until the one using it is done.",
- "version": "0.1.4",
- "source": "./mods/browser-lanes",
- "category": "See what's happening",
- "tags": [
- "band",
- "toast",
- "guard",
- "command"
- ]
- },
- {
- "name": "md-preview",
- "description": "Shows the Markdown files Claude edits, rendered like GitHub, in a pane next to the chat. Before and after side by side. /md opens it.",
- "version": "0.1.11",
- "source": "./mods/md-preview",
- "category": "See what's happening",
- "tags": [
- "pane",
- "toast",
- "command"
- ],
- "needs": [
- "Chrome"
- ]
- },
- {
- "name": "glance",
- "description": "One line above the prompt with what needs you: next meeting, PRs, Linear issues and Slack DMs. /glance lists them all.",
- "version": "0.1.3",
- "source": "./mods/glance",
- "category": "My setup (fork and adapt)",
- "tags": [
- "band",
- "command"
- ],
- "needs": [
- "gh",
- "Google Calendar connector",
- "Linear connector",
- "Slack connector"
- ]
- },
- {
- "name": "heatmap",
- "description": "A GitHub-style grid of your Claude Code time in a /heatmap pane, with streaks, peaks and top projects.",
- "version": "0.1.3",
- "source": "./mods/heatmap",
- "category": "See what's happening",
- "tags": [
- "pane",
- "toast",
- "command"
- ]
- },
- {
- "name": "merge-gate",
- "description": "Holds `gh pr merge` until CI passes and one Codex review (OpenAI's luna model) has run. A PR line above the prompt, and /gate shows the PR's status.",
- "version": "0.1.6",
- "source": "./mods/merge-gate",
- "category": "My setup (fork and adapt)",
- "tags": [
- "band",
- "guard",
- "command"
- ],
- "needs": [
- "gh",
- "codex"
- ]
- },
- {
- "name": "mission-control",
- "description": "/mission opens a live map of the main agent, its subagents and every tool call, plus a code map of the files they touch.",
- "version": "0.1.10",
- "source": "./mods/mission-control",
- "category": "See what's happening",
- "tags": [
- "band",
- "pane",
- "command"
- ]
- },
- {
- "name": "next-steps",
- "description": "After each turn, 2 or 3 likely next prompts above the prompt. Press 1, 2 or 3 in an empty prompt to draft one, 0 to dismiss.",
- "version": "0.3.1",
- "source": "./mods/next-steps",
- "category": "See what's happening",
- "tags": [
- "band"
- ]
- },
- {
- "name": "now-playing",
- "description": "What Spotify is playing, one line above the prompt: track, progress and the lyric being sung, with ⏮ ⏸ ⏭ buttons. /music controls it too. macOS.",
- "version": "0.1.2",
- "source": "./mods/now-playing",
- "category": "For fun",
- "tags": [
- "band",
- "command"
- ],
- "needs": [
- "macOS",
- "Spotify"
- ]
- },
- {
- "name": "prayer-times",
- "description": "The current prayer and how long is left, the next prayer, and zawal, above the prompt. Computed on your computer from your location; nothing is sent anywhere.",
- "version": "0.1.6",
- "source": "./mods/prayer-times",
- "category": "See what's happening",
- "tags": [
- "band",
- "toast",
- "command"
- ]
- },
- {
- "name": "reels",
- "description": "YouTube Shorts in a terminal pane: plays while Claude works, pauses when Claude is done.",
- "version": "0.1.3",
- "source": "./mods/reels",
- "category": "For fun",
- "tags": [
- "pane",
- "command"
- ],
- "needs": [
- "Playwright"
- ]
- },
- {
- "name": "replay-theater",
- "description": "Step through the last turn's file edits, one diff at a time.",
- "version": "0.1.3",
- "source": "./mods/replay-theater",
- "category": "See what's happening",
- "tags": [
- "pane",
- "toast",
- "command"
- ]
- },
- {
- "name": "review-watch",
- "description": "A live line above the prompt for each running code review: Codex or a review subagent, its model, what it reviews, time, and Codex's latest output. A toast with the findings when it ends.",
- "version": "0.1.3",
- "source": "./mods/review-watch",
- "category": "See what's happening",
- "tags": [
- "band",
- "toast"
- ]
- },
- {
- "name": "rulebook-guard",
- "description": "Writing and git rules: replaces em dashes in prose, and asks before git commit --amend, an unformatted push, or personal info in notes and commits.",
- "version": "0.1.4",
- "source": "./mods/rulebook-guard",
- "category": "My setup (fork and adapt)",
- "tags": [
- "guard",
- "toast"
- ]
- },
- {
- "name": "session-saver",
- "description": "Names untitled sessions through unpause. /park saves where you left off, and a resumed session shows it.",
- "version": "0.1.4",
- "source": "./mods/session-saver",
- "category": "My setup (fork and adapt)",
- "tags": [
- "band",
- "toast",
- "command"
- ],
- "needs": [
- "unpause"
- ]
- },
- {
- "name": "snake",
- "description": "Snake in a pane while Claude works, paused when it's done. Opt-in, so nothing opens until /snake.",
- "version": "0.2.3",
- "source": "./mods/snake",
- "category": "For fun",
- "tags": [
- "pane",
- "command"
- ]
- },
- {
- "name": "token-weather",
- "description": "A live forecast of the context window, with a prompt-cache countdown, drawn above the prompt.",
- "version": "0.2.4",
- "source": "./mods/token-weather",
- "category": "See what's happening",
- "tags": [
- "band"
- ]
- },
- {
- "name": "cache-clock",
- "description": "A prompt-cache line under your status line, from Claude Code's own cache figures: time left while warm, hit rate and misses, and how many tokens the next message re-caches once cold. /cache-clock setup adds it.",
- "version": "0.1.1",
- "source": "./mods/cache-clock",
- "category": "See what's happening",
- "tags": [
- "statusline",
- "command"
- ],
- "needs": [
- "node"
- ]
- },
- {
- "name": "usage-meter",
- "description": "Your plan's 5-hour and 7-day usage as small bars above the prompt, with the reset countdown and the session's cost.",
- "version": "0.1.2",
- "source": "./mods/usage-meter",
- "category": "See what's happening",
- "tags": [
- "band",
- "toast"
- ]
- },
- {
- "name": "where-am-i",
- "description": "A live recap above the prompt: goal, doing now, waiting on you, next. /where for a longer one.",
- "version": "0.1.10",
- "source": "./mods/where-am-i",
- "category": "See what's happening",
- "tags": [
- "band",
- "command"
- ]
- },
- {
- "name": "switchboard",
- "description": "Picks the model for each subagent that names none, with OpenAI's Decisions API or Jev, from its short label only. One line per spawn above the prompt; /route shows each pick and what each subagent cost.",
- "version": "0.3.4",
- "source": "./mods/switchboard",
- "category": "Spend less",
- "tags": [
- "band",
- "pane",
- "guard",
- "command"
- ]
- },
- {
- "name": "openai-balance",
- "description": "Your OpenAI API credit above the prompt: an estimated balance with a gauge, today's spend, where the money mostly went, and the last call. /openai-balance shows the breakdown.",
- "version": "0.1.3",
- "source": "./mods/openai-balance",
- "category": "See what's happening",
- "tags": [
- "band",
- "command"
- ],
- "needs": [
- "OpenAI Admin key"
- ]
- },
- {
- "name": "openrouter-balance",
- "description": "Your OpenRouter credit above the prompt: the balance with a gauge, today's spend and where the money mostly went. /openrouter-balance shows the breakdown.",
- "version": "0.1.3",
- "source": "./mods/openrouter-balance",
- "category": "See what's happening",
- "tags": [
- "band",
- "command"
- ],
- "needs": [
- "OpenRouter key"
- ]
- },
- {
- "name": "gotham-night",
- "description": "A Gotham theme for the Claude Code Desktop app: searchlights sweep while Claude works, and when it needs you the signal lights with a burst of bats. Desktop app only.",
- "version": "0.2.3",
- "source": "./mods/gotham-night",
- "category": "For fun",
- "tags": [
- "theme"
- ],
- "needs": [
- "Claude Code Desktop app"
- ]
- },
- {
- "name": "matrix-mode",
- "description": "A Matrix theme for the Claude Code Desktop app: green code rains while Claude works, and when it needs you the rain slows and parts for a waiting cursor. Desktop app only.",
- "version": "0.1.0",
- "source": "./mods/matrix-mode",
- "category": "For fun",
- "tags": [
- "theme"
- ],
- "needs": [
- "Claude Code Desktop app"
- ]
- },
- {
- "name": "stark-lab",
- "description": "A JARVIS theme for the Claude Code Desktop app: a holographic workshop with a spinning arc reactor while Claude works, and when it needs you the reactor locks and flares gold. Desktop app only.",
- "version": "0.1.0",
- "source": "./mods/stark-lab",
- "category": "For fun",
- "tags": [
- "theme"
- ],
- "needs": [
- "Claude Code Desktop app"
- ]
- },
- {
- "name": "interstellar",
- "description": "An Interstellar theme for the Claude Code Desktop app: a black hole turns while Claude works, and when it needs you a ship holds station and hails you with its beacon. Desktop app only.",
- "version": "0.1.0",
- "source": "./mods/interstellar",
- "category": "For fun",
- "tags": [
- "theme"
- ],
- "needs": [
- "Claude Code Desktop app"
- ]
- },
- {
- "name": "akatsuki-night",
- "description": "An Akatsuki theme for the Claude Code Desktop app: red clouds drift past a blood moon whose eye slowly turns, crows resting on a shrine gate. Desktop app only.",
- "version": "0.1.0",
- "source": "./mods/akatsuki-night",
- "category": "For fun",
- "tags": [
- "theme"
- ],
- "needs": [
- "Claude Code Desktop app"
- ]
- }
- ]
- }
README.md · README · 107 lines
- <p align="center"><img src="images/claude-wave.gif" alt="" width="40"></p>
- <h1 align="center">Claude Code mods and themes</h1>
- <p align="center"><b>Make Claude Code show what it's doing, and look the way you want.</b><br>Plugins for Claude Code, built on function hooks: live lines above the prompt, guards, panes, games and Desktop themes. Install only the ones you want.</p>
- <p align="center">
- <a href="https://www.npmjs.com/package/claude-code-mods"><img src="https://img.shields.io/npm/v/claude-code-mods.svg" alt="npm"></a>
- <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-blue.svg" alt="MIT"></a>
- <a href="https://github.com/hamzafer/claude-code-mods/actions/workflows/ci.yml"><img src="https://github.com/hamzafer/claude-code-mods/actions/workflows/ci.yml/badge.svg?branch=main" alt="CI"></a>
- </p>
- <a id="mission-control"></a>
- 
- <p align="center"><sub><b>mission-control</b>: every subagent, tool call and file they touch, live. Shown at 4x. <a href="docs/mods.md#%EF%B8%8F-mission-control">Details</a></sub></p>
- <a id="-install"></a>
- ## Install
- ```sh
- npx claude-code-mods@latest
- ```
- Tick the mods you want, press Enter, restart Claude Code. Needs Claude Code 2.1.287+. [Flags and other ways to install](docs/install.md).
- <table>
- <tr>
- <td align="center" width="33%"><a href="docs/mods.md#-context-bar"><img src="images/context-bar.png" alt="context-bar: Claude Code context window usage as a stacked bar, a color per category" width="260"></a><br><b>context-bar</b><br>what fills your context</td>
- <td align="center" width="33%"><a href="docs/mods.md#-review-watch"><img src="images/review-watch.png" alt="review-watch: live lines for running Codex and subagent code reviews in Claude Code" width="260"></a><br><b>review-watch</b><br>running code reviews, live</td>
- <td align="center" width="33%"><a href="docs/mods.md#-md-preview"><img src="images/md-preview.png" alt="md-preview: Markdown that Claude Code edits, rendered like GitHub next to the diff" width="260"></a><br><b>md-preview</b><br>Markdown rendered like GitHub</td>
- </tr>
- <tr>
- <td align="center" width="33%"><a href="docs/mods.md#-blast-radius"><img src="images/gallery/blast-radius.png" alt="blast-radius: a Claude Code hook holds rm -rf and lists the files it would delete" width="260"></a><br><b>blast-radius</b><br>see what <code>rm -rf</code> would delete</td>
- <td align="center" width="33%"><a href="docs/mods.md#-switchboard"><img src="images/switchboard.png" alt="switchboard: subagents routed from opus to sonnet and haiku, with confidence and cost" width="260"></a><br><b>switchboard</b><br>cheaper models for subagents</td>
- <td align="center" width="33%"><a href="docs/mods.md#-now-playing"><img src="images/now-playing.png" alt="now-playing: Spotify track, progress bar and synced lyrics inside Claude Code" width="260"></a><br><b>now-playing</b><br>Spotify and its lyrics, live</td>
- </tr>
- </table>
- <a id="-the-mods"></a>
- ## The mods
- Full descriptions, commands and setup notes are in [docs/mods.md](docs/mods.md). More screenshots are in [docs/demo.md](docs/demo.md).
- ### See what's happening
- - 🛰️ [**mission-control**](docs/mods.md#%EF%B8%8F-mission-control): agents, tool calls and the code they touch
- - 📊 [**context-bar**](docs/mods.md#-context-bar): what fills your context window
- - 🌦️ [**token-weather**](docs/mods.md#%EF%B8%8F-token-weather): context fill and a prompt-cache countdown
- - ⏱️ [**cache-clock**](docs/mods.md#%EF%B8%8F-cache-clock): cache time left, hit rate and misses
- - 📍 [**where-am-i**](docs/mods.md#-where-am-i): goal, doing now, waiting on you
- - ➡️ [**next-steps**](docs/mods.md#%EF%B8%8F-next-steps): likely next prompts, one key to draft
- - 💰 [**usage-meter**](docs/mods.md#-usage-meter): plan usage, resets and session cost
- - 🔥 [**heatmap**](docs/mods.md#-heatmap): a GitHub-style grid of your Claude time
- - 💳 [**openai-balance**](docs/mods.md#-openai-balance): your OpenAI API credit (needs an Admin key)
- - 🪙 [**openrouter-balance**](docs/mods.md#-openrouter-balance): your OpenRouter credit and spend
- - 📡 [**agent-radar**](docs/mods.md#-agent-radar): one live line per subagent or shell
- - 🔍 [**review-watch**](docs/mods.md#-review-watch): running code reviews, live
- - 🌐 [**browser-lanes**](docs/mods.md#-browser-lanes): whether this session has the browser
- - 🕌 [**prayer-times**](docs/mods.md#-prayer-times): the current prayer and the next
- - 🎬 [**replay-theater**](docs/mods.md#-replay-theater): the last turn's edits, one diff at a time
- - 📝 [**md-preview**](docs/mods.md#-md-preview): Markdown edits rendered like GitHub (needs Chrome)
- ### Guard your repo
- - 💥 [**blast-radius**](docs/mods.md#-blast-radius): see what `rm -r` would delete before it runs
- - 🔑 [**secret-guard**](docs/mods.md#-secret-guard): keeps API keys out of Claude's context and your commits
- ### Spend less
- - 🔀 [**switchboard**](docs/mods.md#-switchboard): cheaper models for subagents, with their costs
- ### My setup (fork and adapt)
- - 👀 [**glance**](docs/mods.md#-glance): meetings, PRs, issues and DMs (needs `gh` and connectors)
- - 🚦 [**merge-gate**](docs/mods.md#-merge-gate): holds merges until CI and Codex pass (needs `gh`, Codex)
- - 📏 [**rulebook-guard**](docs/mods.md#-rulebook-guard): enforces my writing and git rules
- - 💾 [**session-saver**](docs/mods.md#-session-saver): where you left off (needs [unpause](https://github.com/hamzafer/unpause))
- ### For fun (opt-in)
- - 📱 [**reels**](docs/mods.md#-reels-and-snake): Shorts while Claude works
- - 🐍 [**snake**](docs/mods.md#-reels-and-snake): Snake while Claude works
- - 🎵 [**now-playing**](docs/mods.md#-now-playing): Spotify and its lyrics (needs macOS)
- ### Themes (Desktop app)
- Most themes have two scenes, one while Claude works and one when it needs you; [**akatsuki-night**](docs/mods.md#-akatsuki-night) has one.
- <p align="center"><a href="docs/mods.md#-gotham-night"><img src="images/gotham-night.gif" width="560" alt="gotham-night: Why do we fall, Bruce? Searchlights sweep a rainy city, then the signal lights and bats scatter"></a><br><a href="docs/mods.md#-gotham-night"><b>gotham-night</b></a><br>searchlights, then the bat signal</p><!-- [**gotham-night**] -->
- <table>
- <tr>
- <td align="center" width="50%"><a href="docs/mods.md#-matrix-mode"><img src="images/matrix-mode.png" alt="matrix-mode: green code rain slowed to a crawl, parting in the upper right for a prompt that reads your move with a block cursor" width="400"></a><br><a href="docs/mods.md#-matrix-mode"><b>matrix-mode</b></a><br>code rain, waiting cursor</td><!-- [**matrix-mode**] -->
- <td align="center" width="50%"><a href="docs/mods.md#-stark-lab"><img src="images/stark-lab.png" alt="stark-lab: a dark holographic workshop, the arc reactor at the right locked and glowing gold inside targeting brackets, ping rings spreading from it" width="400"></a><br><a href="docs/mods.md#-stark-lab"><b>stark-lab</b></a><br>arc reactor, gold flare</td><!-- [**stark-lab**] -->
- </tr>
- <tr>
- <td align="center" width="50%"><a href="docs/mods.md#-interstellar"><img src="images/interstellar.png" alt="interstellar: deep space, a black hole with a glowing disc at the upper right, a small ring ship below it sending signal rings, an ice planet in the lower left" width="400"></a><br><a href="docs/mods.md#-interstellar"><b>interstellar</b></a><br>black hole, ship hailing</td><!-- [**interstellar**] -->
- <td align="center" width="50%"><a href="docs/mods.md#-akatsuki-night"><img src="images/akatsuki-night.png" alt="akatsuki-night: a blood-red moon with three comma marks in its eye over a shrine gate, red clouds with pale outlines and crows resting on the gate" width="400"></a><br><a href="docs/mods.md#-akatsuki-night"><b>akatsuki-night</b></a><br>blood moon, red clouds</td>
- </tr>
- </table>
- <a id="-community-mods"></a>
- ## Community mods
- Built by other people and maintained in their own repos, so read the code before you install. They show up last in the checklist. [See them all](docs/community.md), or open a PR to add yours.
- **Community pick: [image-view](https://github.com/jarrodwatts/claude-image-view)** by [@jarrodwatts](https://github.com/jarrodwatts) shows the images you paste as thumbnails above the prompt.
- <p align="center"><img src="images/community/image-view.png" width="600" alt="image-view: a thumbnail of the pasted image, labeled #1, above the prompt that holds [Image #1]"></p>
- ## More
- - [Add your own mod](CONTRIBUTING.md)
- - My earlier project: [cursor-commands](https://github.com/hamzafer/cursor-commands), 670+ stars for Cursor slash commands
mods/agent-radar/hooks/watch.ts · Bundled script · 111 lines · 1 finding marked
- // Pure helpers for background Bash commands: labels, output paths and output tails.
- // Nothing here touches `$`, so the tests call it directly.
- // Where a command starts: after `;`, `&&`, `|`, `(`, then `timeout 900`, `nohup`, `FOO=1` and the like.
- const START = String.raw`(?:^|[;&|(])\s*(?:\w+=\S*\s+)*(?:(?:timeout|nohup|nice|env|time|command)(?:\s+[-\w.=:]+)*\s+)?(?:\S*\/)?`
- const AGENT = new RegExp(`${START}(?:(codex)\\s+exec|(opencode)\\s+run|(cursor-agent|agy|crush|copilot|qwen|cline|omp|hermes))(?=\\s|$)`)
- const MODEL = /(?:^|\s)(?:--model|-m)(?:\s+|=)["']?(\w[\w.:/-]*)/
- const CODEX_MODEL = /\s-c\s+["']?model\s*=\s*\\?["']?([\w.:/-]+)/
- const MAX_COMMAND = 4096 // the agent CLI and its --model come early; a huge command must not stall the regexes
- // The agent CLI a shell command runs and its `--model`, or undefined for any other command.
- export function agentOf(full: string): { agent: string; model?: string } | undefined {
- const command = full.slice(0, MAX_COMMAND)
- const m = AGENT.exec(command)
- if (!m) return undefined
- const agent = m[1] ?? m[2] ?? m[3]
- if (!agent) return undefined
- const part = command.slice(m.index).split(/\s*(?:&&|\|\||;|\|(?!&))\s*/)[0]!
- // A quoted prompt may mention --model: look past quoted strings, except as a flag's own value.
- const bare = part.replace(/(?<!(?:--model|-m)[\s=])(["'])(?:(?!\1).)*\1/g, ' _ ')
- const model = MODEL.exec(bare)?.[1] ?? CODEX_MODEL.exec(part)?.[1]
- return { agent, model }
- }
- // What the band calls a background shell: the agent and model it runs, else the Bash
- // description, else the program it runs. `detail` is the other one, for the pane: never the whole command line.
- export function shellLabel(command: string, description?: string): { label: string; detail: string } {
- const flat = clean(command.slice(0, MAX_COMMAND)).replace(/\s+/g, ' ').trim()
- const text = clean(description ?? '').trim().slice(0, 200) || program(flat)
- const a = agentOf(command)
- return a ? { label: a.model ? `${a.agent} ${a.model}` : a.agent, detail: text } : { label: text, detail: program(flat) }
- }
- // The tools whose second word is a subcommand worth naming: `git push`, `npm test`.
- const SUBCOMMANDS = new Set(['git', 'gh', 'npm', 'pnpm', 'yarn', 'bun', 'docker', 'cargo', 'go', 'kubectl', 'make'])
- // A command's program, never its arguments (a token often sits there): `curl -H "…" url` is `curl`,
- // `cd /x && npm test` is `npm test`. A start that is no plain name (`FOO=1`, a quote, a subshell) says so.
- export function program(command: string): string {
- const words = command.replace(/^\s*cd\s+\S+\s*(?:&&|;)\s*/, '').trim().split(/\s+/)
- const name = words[0]!.slice(words[0]!.lastIndexOf('/') + 1)
- if (!/^[\w.+-]{1,30}$/.test(name)) return 'a shell command'
- return SUBCOMMANDS.has(name) && /^[a-z][a-z-]{0,19}$/.test(words[1] ?? '') ? `${name} ${words[1]}` : name
- }
- // Where Claude Code keeps a background shell's output: `.../tasks/<id>.output` in 2.1.x
- // ("Output is being written to: ..."), "written to: ....output" in older text, or the result's own field.
- // Only an absolute path with no control characters or `..` is taken: lsof and tail run on it.
- export function outputPathOf(text: string | undefined, result?: unknown): string | undefined {
- const ok = (p: unknown): p is string => typeof p === 'string' && /^\/[^\x00-\x20\x7f-\x9f]+\.output$/.test(p) && !p.split('/').includes('..')
- const r = result && typeof result === 'object' ? (result as { backgroundOutputPath?: unknown }) : undefined
- if (ok(r?.backgroundOutputPath)) return r.backgroundOutputPath
- const t = (text ?? '').slice(0, 4096)
- const found = [/(?:written to|output (?:file )?(?:is|at)):?\s+(\/\S+\.output)/i.exec(t)?.[1], /(\/[^\s"'`]*\/tasks\/[\w-]+\.output)/.exec(t)?.[1]]
- return found.find(ok)
- }
- export function baseName(path: string) {
- return path.slice(path.lastIndexOf('/') + 1)
- }
- // Text from a command is shown on the terminal: drop every escape sequence (CSI, OSC such as the
- // clipboard write, DCS and the like, 7- and 8-bit) and every other control character, keeping tab and line breaks.
- const ESCAPES = /\x1b(?:\[[0-?]*[ -/]*[@-~]|[\]PX^_][\s\S]*?(?:\x07|\x1b\\|$)|[@-Z\\-_])|\x9b[0-?]*[ -/]*[@-~]|[\x90\x98\x9d\x9e\x9f][\s\S]*?(?:\x07|\x9c|$)|[\x00-\x08\x0b\x0c\x0e-\x1f\x7f-\x9f--]/g
- Note: Usual in code (characters a sanitizer strips): Contains 4 bidirectional-override character(s), which make text display in a different order from how it's read
- Line 65 on GitHub
- export function clean(text: string) {
- return text.replace(ESCAPES, '')
- }
- // The last n non-empty lines of an output tail (carriage-return progress included), each cut short.
- export function tailLines(text: string, n = 8): string[] {
- return clean(text)
- .split(/[\r\n]+/)
- .map(l => l.trimEnd())
- .filter(l => l.trim() !== '')
- .slice(-n)
- .map(l => l.slice(0, 200))
- }
- // The tail of each file named, each after a \001 line with its path: one process for all of them.
- export const TAILS_SH = `# radar:tails
- for f in "$@"; do printf '\\001%s\\n' "$f"; tail -c 16384 -- "$f" 2>/dev/null | LC_ALL=C tr -d '\\001'; done
- exit 0
- `
- // Every file some process we can see holds open, as `lsof -Fn` lines (`n<path>`), from Linux's /proc:
- // for a Linux machine without lsof. Exits 2 elsewhere (macOS, or Git Bash, whose /proc shows only its
- // own processes), so the caller knows it cannot say.
- export const OPEN_SH = `# radar:open
- [ "$(uname -s)" = Linux ] && [ -d /proc/self/fd ] || exit 2
- ls -l /proc/[0-9]*/fd/ 2>/dev/null | sed -n 's/.* -> /n/p'
- exit 0
- `
- // Splits "\001path\n<body>" blocks.
- export function blocks(stdout: string): { path: string; body: string }[] {
- return stdout
- .split('\x01')
- .filter(Boolean)
- .map(b => {
- const nl = b.indexOf('\n')
- return nl < 0 ? { path: b.trim(), body: '' } : { path: b.slice(0, nl).trim(), body: b.slice(nl + 1) }
- })
- }
- // File names `lsof -Fn` reports open, as base names (the task id is unique; /tmp and /private/tmp agree).
- export function parseOpen(stdout: string): Set<string> {
- const open = new Set<string>()
- for (const line of stdout.split('\n')) if (line.startsWith('n')) open.add(baseName(line.slice(1).trim()))
- return open
- }
Ratings and comments
Sign in to rate this skill.
Sign inFree to use. If it’s helped, pass it on.