Repository navigation
perf(cli): write compact JSON when output is not a terminal - #1413
Merged
Merged
Conversation
`--json` / `--format json` always indented its streamed result. Agents and scripts read REA through pipes and redirects, where indentation carries no information: on real application results it added 16-45% model tokens (o200k proxy) and 25-73% bytes. The skill's CLI fallback uses `--json`. Indent only when stdout is a TTY, as `gh --json` does; piped or redirected JSON is compact. The JSON value, `jsonl`, `--filter-output`, `--full-output` and the token-window paths are unchanged. `jq .` restores indentation for files. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits. |
darsrc
pushed a commit
to darsrc/rea
that referenced
this pull request
Oct 10, 2026
…1413) `--json` / `--format json` always indented its streamed result. Agents and scripts read REA through pipes and redirects, where indentation carries no information: on real application results it added 16-45% model tokens (o200k proxy) and 25-73% bytes. The skill's CLI fallback uses `--json`. Indent only when stdout is a TTY, as `gh --json` does; piped or redirected JSON is compact. The JSON value, `jsonl`, `--filter-output`, `--full-output` and the token-window paths are unchanged. `jq .` restores indentation for files.
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
--json/--format jsonalways writes its streamed result with two-space indentation (jsonParts(value, format === "json")). The main readers of that output are agents and scripts, which consume it through pipes and redirects. The skill's CLI fallback and the docs both use--json. For them, indentation carries no information but costs bytes and model tokens.Measured on real results (
--format jsonloutput re-encoded both ways; token counts with theo200k_basetokenizer as a proxy, not a model-host measurement):decode-interface-builderXLD.appinspect-native-dispatch-metadataStash.apptrace-dylib-resolutionStash.appinspect-asset-catalogStash.appinspect-artifactStash.appChange
writeJsonOutputindentsjsononly when the destination is a TTY. Piped or redirectedjsonis the same value written compactly, likegh --json:Unchanged: the JSON value and exit status,
jsonl,--filter-output,--full-output, and the--token-count/--token-limit/--token-offsetpaths (Incur still formats those). Small errors formatted by Incur itself also keep their existing layout.docs/cli.mddocuments the behavior andjq .for indented files.Compatibility: any consumer that parses the JSON is unaffected. A script that matched indented text (for example
grep '"code": "') sees a different layout when piped. The one repository test that did this now parses the JSON. I usedperf:rather than!; please re-tag if you treat output whitespace as a breaking contract.Tests
tests/boundary/cli/jsonOutput.test.ts: new case, indented for a terminal destination and compact otherwise. The encoding cases and the beyond-string-limit streaming cases mark their destination as a terminal, so they still cover the indented encoder.tests/acceptance/tools/historicalCaptureResources.test.tsparses the CLI JSON instead of matching'"code": "resource_constraint"'.scripts/verify/javascript/output.mjsredirects to a file, so it now expects compact output. Ran locally for both formats:json_output_verified: true, 536,961,629 bytes past the 536,870,888-character string limit, peak RSS about 168 MB.vitest run: 6213 passed. The remaining failures fail identically on unmodifiedmainon this Mac: ibtool NIB fixtures,hdiutilrefusal, and three Node-discovery path tests.npm run check:fast,npm run format:check,npm run docs:checkscript -q /dev/null rea … --json(TTY) is indented; the same command piped is compact.No Hopper/Ghidra verification needed. Refs #723, #1065.
🤖 Generated with Claude Code