All jobs

Add a Progress Bar to a Go Command-Line Tool

Yes. An agent adds an opt-in progress line to your Go CLI on stderr, counting completed work without touching stdout, tests it with a fake server and opens a PR.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads how the tool reports today. In a load generator laid out like rakyll/hey, hey.go parses flags with the standard flag package (-n 200 requests, -c 50 workers, -q rate, -z duration, -o csv, -t timeout, -h2, -cpus and the header, body and auth flags), builds a requester.Work and calls w.Init() and w.Run(), stopping it on SIGINT or when -z elapses. go.mod is go 1.24.0 with one direct dependency, golang.org/x/net v0.48.0. In requester/requester.go, Run starts runReporter on a goroutine, then runWorkers, then Finish, which closes the results channel, waits on report.done and calls finalize; runReporter in requester/report.go drains the results channel and counts each in numRes, and print.go renders either the summary or the CSV template to Work.Writer, which defaults to os.Stdout. Until the last result arrives, the tool prints nothing: a two-minute -z 2m run is silent until its end. The tests are hey_test.go for flag parsing and requester/requester_test.go (TestN, TestQps, TestRequest, TestBody) against httptest servers.

The design puts progress where it cannot corrupt output. Stdout carries the summary or the CSV, which scripts parse, so the progress line goes to stderr, where the usage text already goes, and only behind a new -progress flag so existing invocations produce byte-identical output. Work gains a Progress io.Writer field, nil by default; when set, Run starts a goroutine with a 100-millisecond time.Ticker that reads an atomic counter the reporter increments per result and writes one carriage-return line: completed over N with a percentage when -n governs the run, elapsed over the duration when -z does, and the current requests per second in both cases. Finish stops the ticker, writes a final line with a newline, and only then calls finalize, so the summary never lands on top of a half-drawn line. Errors count as completed, since the reporter counts them, and the line says how many.

Two details come from reading the code rather than the description. -z sets N to math.MaxInt32, so the counter mode must switch on dur > 0, which hey.go already knows and passes through a new Work.Duration field rather than inferring from the absurd N. And the reporter owns the only place a result is seen once, so the counter is incremented there, in runReporter, not in makeRequest, where a retry or a stopped worker would miscount. The agent writes nothing to stderr when it is not a terminal unless the flag is explicit, checking os.Stderr.Stat() for ModeCharDevice, so hey -progress ... 2> log gets plain newline-separated lines rather than carriage returns.

A test in requester/requester_test.go sets Progress to a bytes.Buffer, runs 20 requests against an httptest server with a small sleep so at least one tick fires, and asserts the buffer's final line reads 20/20 and that Writer, a second buffer, holds only the summary. A second test runs with Progress nil and asserts stderr-bound output is empty. The usage text in hey.go gains a -progress line in the same style as -disable-redirects, the README's options block is updated from it, and the agent runs go vet ./..., go test ./... and gofmt -l before opening the pull request.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Add an opt-in progress line to this Go CLI. Read go.mod, hey.go, requester/requester.go, requester/report.go, requester/print.go, hey_test.go, requester/requester_test.go, the Makefile and the README first. Add a -progress flag, off by default, that writes a carriage-return progress line to stderr every 100 milliseconds: completed over total with a percentage when -n governs the run, elapsed over duration when -z does, plus current requests per second and the error count. Keep stdout byte-identical when the flag is off. Add a Progress io.Writer field and a Duration field on Work, count completed results in the reporter where each result is seen once, stop the ticker and print a final line with a newline before the summary is printed, and fall back to newline-separated lines when stderr is not a terminal. Document the flag in the usage text and the README. Add tests that drive the progress writer with a bytes.Buffer against an httptest server and assert the final line and that the summary writer holds only the summary. Run go vet, go test ./... and gofmt -l, and open a pull request that quotes the output and shows one sample progress line.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

The pull request changes hey.go (the flag, the usage line, the Duration and Progress wiring), requester/requester.go (the ticker goroutine in Run and its stop in Finish), requester/report.go (the counter), requester/requester_test.go and the README, and adds requester/progress.go for the line formatting. Its description quotes go test ./... with the two new tests, go vet and gofmt -l with no output, and one sample line from a run in the sandbox against a local server.

A reviewer checks that a run without -progress writes nothing new anywhere, that the final line is flushed before the summary so hey -progress ... | tee reads cleanly, and that the tick interval and the non-terminal fallback are what they want for CI logs, which would otherwise fill with carriage returns.

The CSV output, the summary template, the worker loop and the rate limiter are unchanged; the counter is one atomic add per result in a goroutine that already handled each.

Run it on every Linear issue labelled ux

In the console, add an automation on the Project with a linear trigger on linear.issue.labeled and the label ux, with the prompt above. When someone labels an issue asking for feedback during long runs, the run starts with the issue as its context, makes the change in the Project's repository and opens a pull request on its own branch linked to the issue. A label added by an app integration never fires the trigger.

To start it from a support tool instead, send this body to POST /o/{org}/sessions with the issue text appended to the prompt and a request_id that is a UUID v5 of the issue id, so a retried delivery returns the run already started.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

The risk in a progress line is not the arithmetic but the plumbing: a write to stdout that breaks the CSV, a counter in the wrong goroutine, a final line that lands under the summary. The agent reads where results flow, puts the counter at the one point each is seen, and proves the separation with a test that captures both writers; the run's record keeps that test's output next to a real run against a local server.

The same question comes up for any CLI that is silent until it finishes, and the answer has the same shape each time: a writer field, a ticker, a terminal check. One run per tool reads that tool's output path and fits the line to it.

Frequently asked questions

Will it change the output scripts parse?

No. The flag is off by default, the line goes to stderr, and Finish prints the final progress line and a newline before the summary or CSV goes to stdout. A test captures both writers and asserts stdout holds only the summary.

What does it show with -z?

Elapsed time over the duration and the current requests per second, because -z sets the request count to math.MaxInt32 and a count against that would be meaningless. The mode is chosen from the duration hey.go already knows, passed to Work as a field.

Why no third-party progress bar package?

The tool has one direct dependency and a Makefile that cross-compiles three binaries, and a bar library would add more code than the feature. A ticker, an atomic counter and fmt.Fprintf with a carriage return cover it, and the format lives in one small file.

What happens when stderr is a file?

The agent checks os.Stderr.Stat() for ModeCharDevice; when stderr is not a terminal it writes newline-separated lines instead of carriage returns, so a CI log or 2> progress.log reads as a list rather than one long overwritten line.

Does it count failed requests?

Yes. The reporter counts every result, errors included, so the completed figure matches what the summary will report, and the line shows the error count separately so a run that is failing fast is visible before the end.

More Go CLI jobs

More jobs like this: Hand off a long task

Keep reading