[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-75966":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":9,"language":10,"languages":9,"totalLinesOfCode":9,"stars":11,"forks":12,"watchers":13,"openIssues":14,"contributorsCount":15,"subscribersCount":15,"size":15,"stars1d":14,"stars7d":16,"stars30d":17,"stars90d":15,"forks30d":15,"starsTrendScore":18,"compositeScore":19,"rankGlobal":9,"rankLanguage":9,"license":9,"archived":20,"fork":20,"defaultBranch":21,"hasWiki":22,"hasPages":20,"topics":23,"createdAt":9,"pushedAt":9,"updatedAt":24,"readmeContent":25,"aiSummary":26,"trendingCount":15,"starSnapshotCount":15,"syncStatus":14,"lastSyncTime":27,"discoverSource":28},75966,"claude-p","smithersai\u002Fclaude-p","smithersai","Drop-in replacement for `claude -p` that drives the interactive Claude Code TUI inside an in-process zmux PTY session.",null,"Zig",375,30,1,2,0,15,87,8,4.47,false,"main",true,[],"2026-06-12 02:03:38","# claude-p\n\n> **Use at your own risk.** This package and repository exist for\n> **educational purposes** and demonstrates why client-side restrictions\n> on how a product is used are fundamentally unenforceable.\n\nA drop-in replacement for `claude -p` that drives the interactive\n`claude` UI inside an in-process [zmux][zmux] PTY session.\n\n[zmux]: https:\u002F\u002Fgithub.com\u002Fsmithersai\u002Fzmux\n\nBuilt using [smithers](https:\u002F\u002Fgithub.com\u002Fsmithersai\u002Fsmithers) self-improving harness\n\n## Use\n\n```bash\nnpx claude-p \"your prompt here\"\n```\n\nOutput on stdout matches `claude -p` byte-for-byte.\n\n```bash\nnpx claude-p --output-format json \"summarize this commit\" \u003C commit.diff\nnpx claude-p --output-format stream-json \"audit src\u002F\" --verbose | jq .\nnpx claude-p --model opus \"explain quicksort to a 10-year-old\"\n```\n\n## How it works\n\n1. Spawns `claude` interactively inside a [zmux][zmux] `NativeSession`\n   (a real PTY with a reader thread and bounded scrollback).\n2. A small ANSI scanner answers the DA1 \u002F DA2 \u002F DSR \u002F XTVERSION \u002F\n   window-size queries Ink (the React-for-terminals runtime Claude\n   Code uses) issues at startup. Without these, the TUI hangs.\n3. Registers two hooks via `--settings '\u003Cinline-json>'` — never\n   touches your `~\u002F.claude\u002F` config:\n   - **`SessionStart`** — the wrapper types the prompt + Enter.\n   - **`Stop`** — fires when the model finishes; payload carries\n     `transcript_path`.\n4. Reads the transcript JSONL, extracts the final assistant message\n   plus usage, and prints in the requested format.\n\n## Flags\n\n```\n--output-format \u003Ctext|json|stream-json>   default: text\n--model \u003Cname>\n--fallback-model \u003Cname>\n--max-turns \u003CN>\n--allowedTools \u003Clist>\n--disallowedTools \u003Clist>\n--permission-mode \u003CacceptEdits|auto|bypassPermissions|default|dontAsk|plan>\n--dangerously-skip-permissions\n--system-prompt \u003Ctext>\n--append-system-prompt \u003Ctext>\n--add-dir \u003Cdir>...                        repeatable, variadic\n--mcp-config \u003Ccfg>...                     repeatable, variadic\n--setting-sources \u003Cuser,project,local>\n--resume \u003Cid> | --continue | --session-id \u003Cuuid>\n--cwd \u003Cpath>\n--input-file \u003Cpath>\n--verbose\n--timeout \u003Cseconds>                       default: 300\n--debug\n--                                        end-of-options, remaining tokens go to PROMPT\n```\n\nUnrecognized flags are forwarded verbatim to `claude`. `-p`\u002F`--print` and\nuser-supplied `--settings` are rejected — claude-p emulates print mode and\ninjects its own settings to register the Stop hook.\n\n## Exit codes\n\n| Code  | Meaning                                                               |\n| ----- | --------------------------------------------------------------------- |\n| `0`   | Success.                                                              |\n| `1`   | Assistant returned an error (`is_error: true`) or transcript missing. |\n| `2`   | Wrapper internal error (PTY failure, spawn failed, etc.).             |\n| `124` | Timed out or `--max-turns` exceeded.                                  |\n| `130` | Interrupted (SIGINT).                                                 |\n\n## Caveats\n\n- **macOS \u002F Linux only.** No Windows (no `forkpty`).\n- **Requires `claude` on `$PATH`.** The wrapper invokes the real CLI.\n- **Per-message streaming, not per-token.** With\n  `--output-format stream-json`, transcript lines (user messages, tool\n  uses, assistant turns, the trailing `result` envelope) are emitted\n  to stdout the moment `claude` flushes them. Individual tokens within\n  a single assistant message are not streamed — those require\n  `claude -p --include-partial-messages` which is only available in\n  claude's native `--print` mode.\n- **Adds ~50–200 ms** over `claude -p` due to PTY + Ink startup\n  overhead.\n- **Multiline prompts** must come via `--input-file` or stdin to keep\n  shell escaping sane.\n- **API instability.** `claude` is not designed to be driven this way.\n  A future Claude Code release that changes the hook payload schema or\n  adds a new terminal probe at startup can break us; the wrapper will\n  surface the failure rather than hide it.\n\n## From source\n\n```bash\ngit clone https:\u002F\u002Fgithub.com\u002Fsmithersai\u002Fclaude-p\ncd claude-p\nzig build -Doptimize=ReleaseSafe\n```\n\nRequires Zig **0.15.2**. Dependencies are fetched by `zig build`.\n\n## As a Zig library\n\n```sh\nzig fetch --save=claude_p git+https:\u002F\u002Fgithub.com\u002Fsmithersai\u002Fclaude-p\n```\n\n```zig\nconst std = @import(\"std\");\nconst claude_p = @import(\"claude_p\");\n\npub fn main() !void {\n    var gpa: std.heap.GeneralPurposeAllocator(.{}) = .{};\n    defer _ = gpa.deinit();\n    const alloc = gpa.allocator();\n\n    var result = try claude_p.run(alloc, .{\n        .prompt = \"what is the capital of France?\",\n        .output_format = .text,\n        .skip_permissions = true,\n    });\n    defer result.deinit(alloc);\n\n    std.debug.print(\"{s}\\n\", .{result.summary.final_text});\n}\n```\n\nThe `Options` struct mirrors the CLI flags 1:1. See `src\u002Froot.zig` and\n[`SPEC.md`](.\u002FSPEC.md) for the full API.\n\n## License\n\nMIT.\n","claude-p 是一个用于替代 `claude -p` 的工具，能够在进程内 zmux PTY 会话中驱动交互式的 Claude Code TUI。该项目使用 Zig 语言编写，并通过 zmux 实现了一个真实的 PTY 会话，支持 ANSI 扫描器处理 Ink 运行时在启动时发出的查询。它通过注册两个钩子（SessionStart 和 Stop）来实现对 Claude Code 的控制，而无需修改用户的配置文件。此外，claude-p 支持多种输出格式（如文本、JSON、流式 JSON）和丰富的命令行选项，适用于需要自动化或批量处理 Claude Code 任务的场景，例如代码审计、生成摘要等。请注意，该项目仅供教育用途，使用需自行承担风险。","2026-06-11 03:54:03","CREATED_QUERY"]