ping-claude
# ping-claude
One read-only Claude advisor that any coding agent can ping for a second opinion.
Inspired by https://x.com/jon_barron/status/2126793821606629749
The workflow: many worker agents (Gemini, Codex, or anything else) write the code. One
Claude session sits beside them. It cannot write code, and you never read its output.
When you want a second opinion in a worker thread, you tell the worker to ping Claude.
The worker is free to overrule Claude, and it must rewrite Claude's take in its own
words before it shows you anything.
`ping-claude` is the piece that connects the two sides: a single-file MCP server with
no dependencies. A ping is one tool call, so the worker asks, waits, and gets the
answer inside the same turn. Nothing is passed through shared files.
```mermaid
flowchart LR
You -->|talk| A[Worker thread A]
You -->|talk| B[Worker thread B]
A -->|ask_claude| P1[ping-claude]
B -->|ask_claude| P2[ping-claude]
P1 --> L{{file lock:<br/>one ping at a time}}
P2 --> L
L -->|claude -p --resume| S[(One Claude session<br/>per repository and model)]
S -.->|read-only| R[Your code]
```
## What you get
| Rule | How it is enforced |
|---|---|
| Claude cannot write code | Hard. The advisor starts with `--tools "Read,Grep,Glob"`, so no edit or shell tool exists in its session. `ping-claude` refuses to start if you configure a tool that can write or execute. The session also runs with `--restricted`: your Claude Code settings, hooks, plugins and skills are not loaded, and the file tools cannot read outside the worker's checkout. |
| One advisor for all workers | Hard. Every ping to a model resumes that model's one Claude Code session, and a file lock makes concurrent pings take turns. Worktrees of one repository share an advisor; different repositories get different advisors, and so do different directories outside git. |
| You never read Claude's output | By design. The advisor has no interface. Its answers go to the worker and to a local log file. |
| Claude sees the uncommitted work | Hard. `ping-claude` runs `git status` and `git diff HEAD` in the worker's checkout and attaches the result to every ping, so it does not depend on the worker. |
| The worker may overrule Claude and must rewrite its take; when it overrules, it must name the risk Claude raised and say why it does not hold | Soft. This is an instruction in the server's MCP instructions, in the tool description and after every answer. The worker model follows it; nothing forces it. |
## Requirements
- Python 3.9 or newer. Only the standard library is used.
- The [Claude Code](https://code.claude.com/docs) CLI, installed and signed in on the same
machine (`claude` on your `PATH`). It must know the `--restricted` flag; 2.1.332 is the
version tested. Each ping uses your Claude usage.
- macOS or Linux. Windows is untested; it has no `flock`, so only pings from the same
agent session are serialized there.
## Install
Pick one.
```bash
# Run straight from GitHub with uv, nothing to install:
uvx --from git+https://github.com/zihaofeng2001/ping-claude ping-claude --version
# Or install the command:
uv tool install git+https://github.com/zihaofeng2001/ping-claude
pipx install git+https://github.com/zihaofeng2001/ping-claude
# Or copy the single file to any server:
curl -fsSL https://raw.githubusercontent.com/zihaofeng2001/ping-claude/main/ping_claude.py \
-o ~/.local/bin/ping-claude && chmod +x ~/.local/bin/ping-claude
```
## Connect your worker agent
`ping-claude` speaks MCP over stdio, so every MCP client can start it. The commands
below assume `ping-claude` is on your `PATH`.
**Antigravity CLI (`agy`)**
```bash
agy mcp add --env PING_CLAUDE_WAIT=300 ping-claude -- ping-claude
```
Antigravity asks before each MCP tool call. To approve the two tools once, add this to
`~/.gemini/antigravity-cli/settings.json`. Headless runs (`agy -p`) need it, because
nobody can answer the prompt there.
```json
{ "permissions": { "allow": ["mcp(ping-claude/ask_claude)", "mcp(ping-claude/claude_reply)"] } }
```
**Claude Code** (for example Sonnet workers that ping a Fable advisor)
```bash
claude mcp add ping-claude -- ping-claude
```
**Gemini CLI**
```bash
gemini mcp add ping-claude ping-claude
```
**Codex**
```bash
codex mcp add ping-claude -- ping-claude
```
**No MCP at all**: let the agent run a shell command instead.
```bash
ping-claude ask "Is fetch_with_retry safe to call from async handlers?" \
--context "I think it is fine as is, because three attempts is plenty."
```
### What has been tested
| Client | Result |
|---|---|
| Antigravity CLI with Gemini 4 Neon | Full workflow with a real Claude Fable advisor. Also waited 130 s on one tool call without a timeout. |
| Claude Code 2.1.332 | Tool call works. |
| Gemini CLI, Codex | Not tested yet. The commands above follow each CLI's `mcp add` help. |
## Use it
In any worker thread, say what you want checked:
> Ping Claude for a second opinion on the retry change, then tell me your conclusion.
The worker calls `ask_claude` with the question, its own position, and pointers to the
files. Claude reads the code itself and answers the worker. The worker then reports to
you in its own words: what it asked, where it agrees or disagrees, and what it decided.
The worker gets these rules when it connects (the MCP `instructions`), in the tool
description, and again after every answer, so no rules file is needed. If your worker
still needs a firmer hint, add this to its rules file (`AGENTS.md`, `GEMINI.md`, or
similar):
```markdown
When I ask you to ping Claude, call the ask_claude tool. Send the question, your own
position, the files Claude should read, and your workdir. Claude's answer is advice: you
may overrule it. Never paste it to me. Tell me in your own words what you asked, where
you agree or disagree and why, and what you decided. If you overrule Claude, name each
risk it raised and say why it does not hold.
```
Claude only has the tools `Read`, `Grep` and `Glob`, so it cannot run `git diff`.
`ping-claude` does that for it: every ping carries `git status --short` and
`git diff HEAD` of the worker's checkout, up to 60,000 characters. The worker only has
to pass the right `workdir`, which the tool marks as required. Test output and anything
else that is not in the files still has to go in `context`.
### Tools
| Tool | Purpose |
|---|---|
| `ask_claude(question, context?, paths?, workdir, model?, effort?, wait_seconds?)` | Ask. Blocks until Claude answers or the wait runs out; then it returns a ticket. |
| `claude_reply(ticket?, wait_seconds?)` | Keep waiting for an answer. Without a ticket it returns this thread's latest question. |
A slow answer is never lost. If the wait runs out, or the client gives up on the call,
Claude keeps working and `claude_reply` collects the result. If the agent session closes
during a question, the server stays until Claude has finished. If the server is
terminated (`SIGTERM`), it stops Claude too, so no stray Claude process keeps writing to
the session.
## Choose the model and effort
The advisor is Claude Fable 5.2 (`claude-fable-5-2`) at `xhigh` effort unless you say
otherwise.
- **For every ping**: set `PING_CLAUDE_MODEL` and `PING_CLAUDE_EFFORT` where you register
the server, for example
`agy mcp add --env PING_CLAUDE_MODEL=opus --env PING_CLAUDE_EFFORT=high ping-claude -- ping-claude`.
- **For one ping**: name them in your request, such as "Ping Claude with opus at high
effort about the retry change". The worker passes `model` and `effort` to `ask_claude`.
From a shell: `ping-claude ask "..." --model opus --effort high`.
A model is any alias or full model name that your Claude Code account can use: `fable`,
`opus`, `sonnet`, `haiku`, or a full name. That includes a Mythos model if your account
has access to one; give its full model name. If the account cannot use the model, the
worker gets Claude Code's error message instead of an answer.
Effort is one of `low`, `medium`, `high`, `xhigh` and `max`.
Each model is its own advisor with its own memory. A ping to `opus` does not see what
you asked the default model, so a second model gives you an independent opinion.
An alias and the full name it stands for are the same advisor: `fable` and
`claude-fable-5-2` share one session. `ping-claude` learns what an alias stands for from
its first answer. If the full name already had a session by then, that first alias ping
ran in a session of its own and the advisor does not remember it. Every answer states
which model and effort produced it.
## Configuration
All settings are environment variables of the `ping-claude` process.
| Variable | Default | Meaning |
|---|---|---|
| `PING_CLAUDE_MODEL` | `claude-fable-5-2` | Default advisor model: an alias or a full model name. |
| `PING_CLAUDE_EFFORT` | `xhigh` | Default reasoning effort: `low`, `medium`, `high`, `xhigh` or `max`. |
| `PING_CLAUDE_TOOLS` | `Read,Grep,Glob` | Advisor tools. Only `Read`, `Grep`, `Glob`, `WebSearch` and `WebFetch` are accepted. The two web tools cannot change files, but a prompt injection in your code could use them to send code out in a URL. |
| `PING_CLAUDE_WAIT` | `50` | Seconds a tool call blocks before it returns a ticket. Raise it if your client allows long tool calls. |
| `PING_CLAUDE_TIMEOUT` | `1800` | Seconds before one Claude call is abandoned. `0` means no limit. |
| `PING_CLAUDE_SCOPE` | per repository, or per directory outside git | Name of the advisor to use. Set one value everywhere to share a single advisor across repositories. |
| `PING_CLAUDE_THREAD` | random | Label for this worker thread in Claude's view. |
| `PING_CLAUDE_HOME` | `~/.local/state/ping-claude` | Where sessions and logs are kept. |
| `PING_CLAUDE_BIN` | `claude` | Path of the Claude Code CLI. |
## State and logs
```bash
ping-claude status # defaults and advisor sessions for the repository you are in
ping-claude reset # forget those sessions; the next ping starts a new one
ping-claude reset --model opus # forget only one model's session
```
One session collects every ping, so it grows. Claude Code compacts it when it gets too
long; reset it when the advisor's memory is no longer useful.
Each repository has a directory under `PING_CLAUDE_HOME` with its session ids, one per
model, and `log.jsonl`, which records every question and answer. That log is the only
place where Claude's raw output is kept. The directory is readable by your user only.
## How it works
Each agent session starts its own `ping-claude` process. A ping does this:
1. Find the advisor for the worker's repository (`git rev-parse --git-common-dir`, so
all worktrees map to the same one). Outside git, the directory itself is the key.
2. Take that advisor's file lock. Other pings wait here.
3. Run `claude -p --resume <session>` from a neutral directory, with the chosen model
and effort, read-only tools, no MCP servers, no user settings or skills
(`--restricted --disable-slash-commands`), and `--add-dir <the worker's checkout>`.
4. Return the answer to the worker, followed by the overrule-and-rewrite rule.
If the stored session no longer exists, the next ping starts a new one.
## Development
```bash
python3 -m unittest discover -s tests -v
```
The tests run the real server process against a fake Claude CLI, so they need no
network and no account.
## License
MIT
TDQS
Scored across 2 tools
The two tools form a clear initiate/collect pair: ask_claude sends a question and claude_reply fetches an answer. The only blur is that claude_reply without a ticket falls back to the most recent question, which slightly overlaps with ask_claude's immediate-return path, but the descriptions make the intended sequence clear.
Both names use snake_case, but the word order breaks the pattern: ask_claude is verb_object while claude_reply is object_verb. The convention is still readable, but an agent cannot infer a single naming scheme from the two names.
Two tools is minimal but well matched to the narrow purpose of pinging an advisor and collecting an asynchronous answer. No tool is redundant, though the surface is slightly thinner than the typical 3-15 range.
The core lifecycle is covered: ask a question, then collect the answer via ticket. Minor gaps remain, such as listing pending tickets, checking status without a ticket, or cancelling a request, but none block the main workflow.