Skip to content

docs: cover gh api mutation pitfalls in the gh skill #14701

Open

Description

@MatiasOlivera

Summary

Agents frequently mishandle gh api field flags when constructing mutations. Values starting with @ are treated as file references under -F/--field, typed literals are converted, and {owner}/{repo}/{branch} is expanded, while -f/--raw-field sends raw strings. This causes accidental file reads, wrong types, and failed bodies. The official skill's gh api section does not document the distinction or the --input escape hatch.

Acceptance Criteria

  • skills/gh/SKILL.md documents the difference between -f/--raw-field and -F/--field, including typed conversion and @file/@- expansion.
  • Clarifies placeholders {owner}, {repo}, {branch} behavior per flag.
  • Documents --input as the way to avoid `@) ambiguity.
  • Adds guidance to re-read the mutated object to verify changes.

Scope

Documentation only in skills/gh/SKILL.md. No CLI code changes.

Out of scope

  • General gh usage.
  • Changing gh api behavior itself.

Requesting maintainers add help wanted if this is accepted, so the accompanying PR can follow contribution rules.

Activity

  1. cli-triage commented on Oct 15, 2026

    @cli-triage

    Thanks for the detailed writeup! This reads as a clear, scoped documentation improvement for skills/gh/SKILL.md (clarifying -f/--raw-field vs -F/--field semantics, placeholder expansion, and --input), and there's already a linked PR (#14700) implementing it, so I'm suggesting enhancement.

    For reference, the current gh api section in skills/gh/SKILL.md (at 819f972) doesn't yet cover the -f vs -F distinction, so the acceptance criteria look accurate and actionable.

    Duplicate check: not a duplicate. #14199 is related (a CLI behavior change proposing a runtime warning when -f values start with @) but this issue is scoped purely to documentation, so they're complementary rather than duplicates.

    No additional information needed from the reporter at this time — a maintainer can review and consider adding help wanted per the issue's request if the docs-only PR is accepted.

    Generated by Issue Triage (skills-driven) for #14701 · copilot · auto · 25.1 AIC · ⌖ 2.2 AIC · ⊞ 9.7K · ◷

  2. added
    enhancement
    on Oct 15, 2026
  3. github-actions commented on Oct 15, 2026

    @github-actions
    Contributor

    Thank you for your issue! We have categorized it as an enhancement (feature or improvement) request, and it has been added to our backlog. In doing so, we are not committing to implementing this feature at this time, but, we will consider it for future releases based on community feedback and our own product roadmap.

    Unless you see the help wanted Contributions welcome label, we are not currently looking for external contributions for this feature.

    If you come across this issue and would like to see it implemented, please add a thumbs up! This will help us prioritize the feature. Please only comment if you have additional information or viewpoints to contribute.

  4. removed
    needs-triage
    on Oct 15, 2026
  5. MatiasOlivera commented on Oct 22, 2026

    @MatiasOlivera
    Author

    Agents have hit this in several sessions, so here is the field evidence plus one gap the current acceptance criteria do not name.

    What happened. Two review-thread replies were posted with:

    gh api -X POST "repos/<owner>/<repo>/pulls/<n>/comments/<comment-id>/replies" -f body=@/tmp/<file>.md
    

    -f/--raw-field sends a static string, so both comments landed with the literal text @/tmp/<file>.md as the body, and both had to be deleted and reposted. Agents reach for -f body=@file because it reads like "body from file", so the skill is where that misreading has to be closed.

    One addition to the acceptance criteria would close the loop. Name the typed-command path: gh issue comment and gh pr comment take --body-file, so posting a body from a file needs no gh api and no @ parsing at all. The current text mentions --body-file only next to the --attach rules, so an agent looking for how to post a file body does not find it.

  6. MatiasOlivera commented on Oct 25, 2026

    @MatiasOlivera
    Author

    Following up on the earlier field evidence with the rest of the cookbook. Beyond the -f/-F and @-file expansion cases this issue tracks, later sessions hit a few more gh api contract traps in the same mutation workflows. They are listed below together with the earlier ones, plus the filter used to separate genuine contract traps from one-off agent mistakes, in case they help when scoping the skills/gh/SKILL.md section (complementary to what #14700 already covers).


    Cookbook: gh api Mutation & Parameter Traps

    1. Passing File Bodies (-f vs -F vs --input)

    • The Pitfall: Passing -f [email protected] does not read the file; -f/--raw-field passes the literal text @file.md into the payload. On pull request or issue timelines, this silently posts the path string instead of the content.
    • Safe Alternatives:
      • Prefer typed commands when posting files: gh issue comment <n> --body-file <file> or gh pr comment <n> --body-file <file>.
      • In gh api, use -F body=@<file> to expand the file, or --input <file.json> for structured JSON payloads.

    2. Ambiguity with Leading @ (Mentions)

    • The Pitfall: If a body string begins with an @mention (e.g. @username), passing -F body=@username causes gh to look for a local file named username and fail.
    • Safe Alternative: Use -f body="@username" for string literals, or pass the payload via --input.

    3. Type Conversion Cuts Both Ways (-f vs -F)

    • The Pitfall: -F (typed field) magic-converts values, in both directions:
      • Certain GitHub REST parameters (such as in_reply_to on review comment creation) strictly require JSON integers. Passing -f in_reply_to=123 sends a JSON string ("123"), causing the API to reject the request with HTTP 422 Unprocessable Entity.
      • Conversely, inline text posted with -F loses its string type: a review-thread reply sent as -F body=123 arrives as the JSON number 123 instead of the text "123".
    • Safe Alternative: Match the flag to the value's required type: -F key=123 for numeric parameters, -f body="..." for inline literal text (including reply bodies), -F body=@<file> for file bodies, and --input <file.json> for structured payloads.

    4. Endpoint Routing Asymmetries

    • The Pitfall: Intuitively trying to fetch a single review comment via repos/{owner}/{repo}/pulls/{n}/comments/{comment_id} returns HTTP 404 Not Found.
    • Safe Alternative: Single review comments are addressed at repos/{owner}/{repo}/pulls/comments/{comment_id} (no PR number in the path). Replying to a comment is addressed at POST repos/{owner}/{repo}/pulls/{n}/comments/{comment_id}/replies.

    5. Post-Mutation Verification

    • Because mutations lack a dry-run flag and land immediately on public timelines, automated tooling should always perform a read-back check immediately after every mutation, split by operation:
      • After POST/PATCH/PUT: query the created or modified resource, assert it exists, the HTTP status indicates success, and the resulting body does not contain literal @<path> text.
      • After DELETE: assert absence instead — a follow-up query returns HTTP 404, or the deleted item no longer appears when listing the collection. (An existence check here would fail for every successful deletion.)

    How These Traps Were Verified (Contract Quirks vs. Agent Errors)

    A major risk when documenting CLI edge cases is feature creep—skills can quickly become an unmaintainable dumping ground for arbitrary user or agent mistakes.

    To prevent this, every item in the cookbook above was required to pass an objective 3-Check Verification Gate:

    1. API / CLI Contract Quirk vs. User Error:
      • If an issue is resolved by reading gh <cmd> --help (e.g., guessing --jobs instead of --json jobs, or sleeping instead of using --watch) or fixing basic shell syntax (unquoted pipes), it is an agent error and is strictly excluded.
      • Only discrepancies between intuitive expectations and the actual CLI/API contract (like -f not expanding @file, or pulls/comments/{id} vs pulls/{n}/comments/{id}) are eligible.
    2. Empirical Specification & Live Verification:
      • Each endpoint path and parameter type was verified against GitHub's official OpenAPI description (github/rest-api-description) or confirmed via a live gh api -i probe (e.g. confirming that pulls/{n}/comments/{id} returns 404 while pulls/comments/{id} returns 200).
    3. High Blast Radius:
      • Priority is given only to traps that cause silent payload corruption on public timelines (e.g., posting @/tmp/body.md) or immediate 422/404 failures.

    Documenting these five points takes roughly 30 lines, and in our sessions that has been enough to keep agents and script authors clear of every mutation trap we have actually hit, without turning the section into a catch-all.

    If any of this wording is useful, please lift it into the section or #14700 as-is.

  7. changed the title [-]docs: clarify gh api -f vs -F and @-file expansion in the gh skill[/-] [+]docs: cover gh api mutation pitfalls in the gh skill[/+] on Oct 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions