Use Claude Code with your ChatGPT, Kimi, Cursor or Grok subscription via a local Anthropic-compatible proxy
Rust
log: capture full assistant output and add verbose mode
Raine Virta74400676a3a5
diff --git a/README.md b/README.mdindex 7e234e3..c03efd7 100644--- a/README.md+++ b/README.md@@ -286,11 +286,12 @@ The proxy speaks enough of the Anthropic API for Claude Code:Settings are environment variables on the proxy process, not a config file.-| Variable | Default | Purpose |-| ----------------- | ---------------- | ------------------------------- |-| `PORT` | `18765` | Proxy listen port |-| `XDG_STATE_HOME` | `~/.local/state` | Base dir for `proxy.log` |-| `CCP_LOG_STDERR` | unset | Also mirror log lines to stderr |+| Variable | Default | Purpose |+| ------------------ | ---------------- | --------------------------------------------------- |+| `PORT` | `18765` | Proxy listen port |+| `XDG_STATE_HOME` | `~/.local/state` | Base dir for `proxy.log` |+| `CCP_LOG_STDERR` | unset | Also mirror log lines to stderr |+| `CCP_LOG_VERBOSE` | unset | Log full request/response bodies + every SSE event |### Filesdiff --git a/src/log.ts b/src/log.tsindex c6ef0fa..2510bfd 100644--- a/src/log.ts+++ b/src/log.ts@@ -63,11 +63,13 @@ async function maybeRotate(): Promise<void> {return rotating}+const VERBOSE = !!process.env.CCP_LOG_VERBOSE+function redact(value: unknown, depth = 0): unknown {if (depth > 6) return "[depth-limit]"if (value == null) return valueif (typeof value === "string") {- if (value.length > 4000) return value.slice(0, 4000) + `…[${value.length - 4000} more]`+ if (!VERBOSE && value.length > 4000) return value.slice(0, 4000) + `…[${value.length - 4000} more]`return value}if (typeof value !== "object") return valuediff --git a/src/server.ts b/src/server.tsindex b766132..433e45c 100644--- a/src/server.ts+++ b/src/server.ts@@ -8,6 +8,7 @@ import { CodexError, postCodex } from "./codex/client.ts"import { countTokens } from "./count-tokens.ts"const log = createLogger("server")+const VERBOSE = !!process.env.CCP_LOG_VERBOSEexport interface ServeOptions {port: number@@ -83,6 +84,7 @@ async function handleMessages(req: Request, reqId: string): Promise<Response> {sessionId,hasJsonSchemaFormat: body.output_config?.format?.type === "json_schema",})+ if (VERBOSE) log.debug("anthropic request body", { reqId, body })try {assertAllowedModel(body.model)@@ -105,6 +107,7 @@ async function handleMessages(req: Request, reqId: string): Promise<Response> {hasInstructions: !!translated.instructions,promptCacheKey: translated.prompt_cache_key,})+ if (VERBOSE) log.debug("translated request body", { reqId, body: translated })let upstreamtry {diff --git a/src/translate/reducer.ts b/src/translate/reducer.tsindex 78a32c8..67ee75e 100644--- a/src/translate/reducer.ts+++ b/src/translate/reducer.ts@@ -1,4 +1,8 @@import { parseSseStream } from "./sse.ts"+import { createLogger } from "../log.ts"++const log = createLogger("translate.reducer")+const VERBOSE = !!process.env.CCP_LOG_VERBOSEexport class UpstreamStreamError extends Error {constructor(@@ -32,6 +36,7 @@ export type ReducerEvent =interface TextState {kind: "text"index: number+ textAccum: string}interface ToolState {kind: "tool"@@ -72,6 +77,8 @@ export async function* reduceUpstream(}const t: string = p.type || evt.event || ""+ if (VERBOSE) log.debug("upstream event", { type: t, output_index: p.output_index, item_id: p.item_id })+if (t === "codex.rate_limits") {if (p.rate_limits?.limit_reached) {throw new UpstreamStreamError(@@ -94,7 +101,7 @@ export async function* reduceUpstream(if (item.type === "reasoning") continueif (item.type === "message") {const idx = anthropicIndex++- blocksByOutputIndex.set(outputIndex, { kind: "text", index: idx })+ blocksByOutputIndex.set(outputIndex, { kind: "text", index: idx, textAccum: "" })if (item.id) itemIdToOutputIndex.set(item.id, outputIndex)yield { kind: "text-start", index: idx }continue@@ -128,6 +135,7 @@ export async function* reduceUpstream(if (!state || state.kind !== "text") continueconst delta: string = p.delta ?? ""if (!delta) continue+ state.textAccum += deltayield { kind: "text-delta", index: state.index, text: delta }continue}@@ -170,11 +178,22 @@ export async function* reduceUpstream(? item.arguments: state.argsAccum) || ""if (finalArgs.length) {+ state.argsAccum = finalArgsyield { kind: "tool-delta", index: state.index, partialJson: finalArgs }}}- if (state.kind === "text") yield { kind: "text-stop", index: state.index }- else yield { kind: "tool-stop", index: state.index }+ if (state.kind === "text") {+ log.debug("text block complete", { index: state.index, text: state.textAccum })+ yield { kind: "text-stop", index: state.index }+ } else {+ log.debug("tool block complete", {+ index: state.index,+ callId: state.callId,+ name: state.name,+ args: state.argsAccum,+ })+ yield { kind: "tool-stop", index: state.index }+ }blocksByOutputIndex.delete(p.output_index)continue}