Repository navigation
Description
What happened?
When an agent harness (Claude Code, Codex, etc.) invokes contextbridge via a hook or skill, the CLI floods the agent's view with raw JSON pino lines on stderr. Two interacting behaviors cause this:
- Claude Code's
Bashtool merges stdout and stderr into a single result block. The CLI correctly routes logs toio.stderr(packages/cli/src/context.ts:46-49), but that channel discipline doesn't help when the harness reads both streams together. - Non-TTY stderr falls back to raw JSON (
packages/context/src/logger.ts:15-17). Thepino-prettysync stream is only attached whendestination.isTTY, so under a harness the agent sees structured JSON lines instead of human-readable output.
The result is that routine info-level logs (e.g. 'open received', 'open session interrupted') burn agent context for no value, and any future MCP / hook integration that captures combined output sees the same noise.
contextbridge version
0.8.0
Operating system
macOS
Steps to reproduce
- From a Claude Code session, run a skill that shells out to the CLI (e.g.
/planbridge:planbridge-last, which invokescontextbridge open). - Observe the contents of the
Bashtool result block returned to the agent.
What did you expect to happen?
The agent should see only the CLI's stdout payload, plus warnings/errors when something is actually wrong. Routine info-level breadcrumbs should not appear in the harness's combined-output view — and if they do appear, they should be readable, not raw JSON.
What actually happened?
The result block is dominated by JSON pino lines like:
{
"level": 30,
"time": 1779311607160,
"msg": "open received"
}…instead of the intended clean stdout payload.
Relevant logs or stack trace
Bash(contextbridge open <<'PLANBRIDGE_LAST_MESSAGE'
Recommended approach locked in. Now moving to the design ...)
⎿ {
"level": 30,
"time": 1779311607160,
"msg": "open received"
… +34 lines (ctrl+o to expand)Anything else
The "logs go to stderr to keep stdout clean for piped consumers" invariant is documented in AGENTS.md. The fix should preserve that invariant — interactive humans running contextbridge in a terminal must still get pretty info logs (stderr is a TTY → unchanged).
Suggested fix: default LOG_LEVEL to warn when stderr is not a TTY, while keeping the existing LOG_LEVEL env var as an override. In packages/cli/src/environment.ts, compute the default from process.stderr.isTTY (info when TTY, warn otherwise). Anyone debugging a skill can re-run with LOG_LEVEL=info to get the full trace. The logger wiring in packages/cli/src/context.ts stays unchanged.
Alternatives considered:
- Redirect stderr in each skill template (
2>/dev/nullor2>"$LOG"). Fragile — every skill template duplicates the same redirect, and it swallows real errors when something does go wrong. - Delete the routine
logger.info('open received', …)/'open session interrupted'calls inpackages/cli/src/commands/open.ts. Addresses the current noise but doesn't prevent the next info log from re-introducing it. Best as a small cleanup, not as the fix. - Detect a harness-driven invocation explicitly (e.g.
CONTEXTBRIDGE_INVOKED_BY_HARNESS=1env var the skills set). More precise than the TTY heuristic but requires every skill template to opt in and adds a new contract surface. Stderr-not-a-TTY is a simpler, broader proxy.
Activity
[-]feat: default LOG_LEVEL to warn when stderr is not a TTY[/-][+]bug: agent harnesses see raw JSON pino logs in command output[/+]