Skip to content

Explore ! shell interpolation to pre-gather context and reduce token usage in commands #149

Description

@LeanAndMean

Summary

mach10 commands currently instruct Claude to run gh/git context-gathering commands as explicit in-session steps. Each such gather costs a full tool-call round trip (tool-call block + tool-result framing + inter-step reasoning). Claude Code supports !-backtick shell interpolation in command Markdown, which runs commands at invocation time and injects their output directly into the prompt -- collapsing that scaffolding into plain text. This issue is to explore adopting that pattern where it pays off, with a failure-recovery structure so a broken user setup (e.g., gh not installed/authenticated) remains diagnosable.

Current Behavior

Commands gather context through Claude-driven steps. For example, the opening of issue-plan, issue-implement, issue-assessment, issue-plan-review, pr-create, and doc-review runs the gh ... view + gh ... view --comments two-call pattern as instructions Claude executes one at a time, each incurring round-trip token overhead.

Proposed Behavior

  • Investigate converting unconditional, independent, fast, read-only context gathers to ! interpolation in the relevant command files, so the output is injected at invocation rather than fetched via tool calls.
  • Adopt a self-describing failure-recovery convention for each interpolated block so that when a command fails on a user's machine, Claude can still recover:
    • Restate the exact command as literal adjacent prose (it is not executed, so it survives even when the executed twin errors).
    • Capture stderr (2>&1) and append a detectable sentinel (e.g., || echo "__FAILED__") so failures are deterministically identifiable.
    • Provide a recovery instruction block (or a gather "manifest") that tells Claude how to interpret a failed/empty block and what the fallback is per gather.
  • For commands with optional flags (e.g., pr-review-fix's --review-comment/--assessment-comment IDs), evaluate a guarded-block variant that injects the targeted fetch only when the flag is present and otherwise emits a sentinel handing the heuristic-selection path back to Claude -- avoiding a large unconditional comment dump.
  • Document the decision (adopt / partially adopt / reject) and, if adopted, the conventions in CLAUDE.md under the command-writing guidance.

Acceptance Criteria

  • A written assessment exists identifying which command gathers are good ! candidates (unconditional/independent/fast/read-only) versus which must stay Claude-driven (conditional, data-dependent on prior output, or requiring selection reasoning).
  • The assessment covers the interaction with existing mach10 conventions, specifically: the task-tracking 1-to-1 step-visibility philosophy (pre-running collapses visible checkpoints into invisible preamble) and allowed-tools least-privilege gating (each interpolated command must be permitted or its block is silently skipped).
  • A reusable failure-recovery convention (label + 2>&1 + sentinel + recovery instructions/manifest) is specified.
  • At least one pilot conversion is prototyped (recommended: issue-assessment, as its opening gather is unconditional with no branching) so the token/diff tradeoff can be evaluated against the current flow before any broad rollout.
  • The $ARGUMENTS escaping hazard (text substitution into the shell before execution) is documented as a caveat, with guidance to prefer positional $1 extraction and defensive parsing where free-text context could reach a ! block.
  • A go/no-go recommendation for broader rollout (the six --comments two-call commands) is recorded.

Technical Notes

  • Relevant convention anchors in CLAUDE.md: the --comments two-call sync (six command files), the Task Tracking section (Step 0 bootstrap, 1-to-1 step mapping), and the command-writing allowed-tools least-privilege guidance.
  • ! interpolation can reference $ARGUMENTS/$1 (substituted before bash runs), so user-provided IDs are available to interpolation -- this is distinct from data that depends on a prior command's runtime output, which cannot be pre-run.
  • Guarded-block sketch for optional flags: extract the ID with grep -oP, then [ -n "$id" ] && gh api .../comments/$id 2>&1 || echo "__NO_FLAG__ ...".
  • Pre-run blocks run synchronously before the prompt reaches Claude; slow or hanging commands stall invocation with no spinner, so keep gathers fast and never place mutating/destructive commands in them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions