Skip to content

Need built-in envelope unwrap for claude --print --output-format json responses #90

@ameet

Description

@ameet

Description

When flows call `claude --print --output-format json` via bash steps, the response is wrapped in an envelope:

{"type": "result", "result": "```json\n{\"actual\": \"data\"}\n```"}

Every flow that consumes this output must implement identical unwrap logic:

  1. Detect the `{"type": "result", "result": "..."}` envelope
  2. Strip markdown fences (```json ... ```)
  3. Strip any preamble text before the JSON
  4. Parse the inner JSON
  5. Handle parse failures gracefully

This pattern is duplicated 20+ times across flows. Each copy is ~8 lines of JavaScript.

Current Workaround

Each code step defines an inline `unwrap()` function:

var unwrap = function(r) {
  if (r && r.type === 'result' && r.result) {
    var s = String(r.result)
      .replace(/^\`\`\`[a-z]*\\s*\\n?/gm, '')
      .replace(/\\n?\`\`\`\\s*$/gm, '')
      .trim();
    try { return JSON.parse(s); } catch(e) { return r; }
  }
  return r;
};
raw = unwrap(raw);

Suggested Fix

One or more of:

  1. `parseEnvelope: true` option on bash steps — automatically unwrap the Claude envelope before passing to downstream steps
  2. Built-in helper exposed to code steps — e.g., `$.unwrapEnvelope(raw)` available in the sandbox
  3. `--raw-json` flag for `claude --print` — return just the JSON without the envelope (this may be an Anthropic CLI issue, not One CLI)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions