What the agent does
The message means the go command is running in module mode in a directory that has no go.mod. For a project written before modules, the cure is to make it one, and the first decision is the module path. h2non/baloo, an HTTP testing library, shows why that takes reading. It has no go.mod. Its .travis.yml tests on Go 1.7 through 1.10, fetches dependencies with a list of go get lines, and then symlinks the checkout into $GOPATH/src/gopkg.in/h2non/baloo.v3. Its own _examples import the library as gopkg.in/h2non/baloo.v3. So the path the code expects is the gopkg.in one, and a module named after the GitHub URL would break every example and every user.
The agent confirms the failure first. On a current Go, go build and go test stop with go: cannot find main module, and the Makefile's update target, go get -u ./..., prints the title's message followed by 'go get' is no longer supported outside a module. It runs go mod init gopkg.in/h2non/baloo.v3 and then go mod tidy, which reads the imports and writes three direct requirements: github.com/nbio/st, github.com/xeipuuv/gojsonschema and gopkg.in/h2non/gentleman.v2. Two details need a decision. go mod init stamps the go directive with the version of the toolchain that ran it, which silently makes that the minimum for every user, so the agent sets it deliberately. And tidy selects the newest golang.org/x/net as an indirect dependency, which can demand a newer Go than the one installed. The agent pins a release the chosen Go can build.
With a module in place, go test ./... runs for the first time in years, and it does not come back clean. In baloo the assert package fails to build its tests because go test now runs vet checks, and assert/json_schema.go passes a non-constant string as the format of fmt.Errorf. In the root package, TestRequestBaseURL fails at request_test.go:314, expecting http://foo.com and getting http://foo.com/bar/baz, a disagreement between the test and the dependency versions tidy selected. Several _examples tests call httpbin.org and assert on its response headers.
None of that is caused by adding go.mod, and the agent keeps it apart. It fixes what is mechanical and safe, such as the format string. For the failing assertion it finds which dependency version the test last agreed with and reports the choice between pinning that version and updating the test. It marks the network-dependent examples as such. Then it replaces the dead setup: the go get lines and the symlink leave the CI file, and the Makefile's update target gets a command that works inside a module.
Start it with one API call
POST https://api.phoenix.so/o/{org}/sessions with this body:
{
"agent": "claude",
"input": "This Go project has no go.mod and fails with \"go: go.mod file not found in current directory or any parent directory\" or \"cannot find main module\". Convert it to a Go module. Before running go mod init, work out the correct module path: read how the package is imported in its own examples, tests and README, any vanity or gopkg.in path, and CI steps that place the checkout under GOPATH. If the project is at major version 2 or higher, account for the /vN or .vN suffix. Check for Gopkg.lock, glide.lock, vendor.json or a vendor directory and carry their pinned versions over if present; if there are none, say that versions were resolved fresh. Run go mod init and go mod tidy. Set the go directive on purpose: choose the lowest Go version the code and its dependencies support, not whatever the local toolchain wrote, and pin any indirect dependency that would force a newer Go. Then run go build, go vet and go test for every package, including example directories. Report each failure in one of three groups: caused by the conversion, already present and now visible, or dependent on network access. Fix the first group, fix the second only where the fix is mechanical, and list the rest with evidence. Replace GOPATH-era setup in CI files, Makefiles and the README (go get lists, symlinks, dep or glide commands) with module commands. Commit go.mod and go.sum. Open a pull request.",
"resources": [
{
"url": "https://github.com/your-org/your-app"
}
]
}- 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.
- 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.
- 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
A pull request that adds go.mod and go.sum and edits the files that described the old workflow. For baloo those are .travis.yml and the Makefile, plus the one-line fix in assert/json_schema.go. The description opens with the module path and the evidence for it, then the go directive and why that version, then the dependency versions tidy selected, with a note that no lock file existed to compare against.
The test report is the part to read slowly. It lists every package with its result and puts each failure in its group. A reviewer learns that the build now works, that one assertion disagrees with a current dependency, and that some examples need the network, with the exact file and line for each. Nothing is hidden by skipping tests or deleting them.
The reviewer confirms the module path, because it is the one thing that cannot be changed later without breaking importers, and decides the open question about the failing assertion. A follow-up message to the same session can carry that decision, and the agent continues in the same sandbox with the module cache already warm.
Run it on every repository without a go.mod
Old Go repositories pile up in an organisation: internal tools, forks, libraries nobody has built in years. Each one fails the same way on a new laptop. List them with a code search for Go repositories lacking a go.mod at the root, and send POST /o/{org}/sessions with the body above once for each, with the repository in resources. Give each start a request_id that is a UUID v5 of the repository's full name, so a rerun of the script starts nothing twice.
The runs are independent, and those past your key's concurrency limit are created queued and start as slots free. Set a webhook_url on the key and each run the key starts reports run.completed or run.failed there. Sort the finished pull requests by their failure groups: the ones with an empty second group can merge on a quick read.
The use case this job follows, with its automation and trigger: Hand off a long task.
Why run it on Rush?
Creating go.mod takes one command. Learning what state the code is in takes a clean machine, a current toolchain and the patience to run every package and read every failure, and that is the part this job is really about. The agent has that machine: its own sandbox with nothing in the module cache and no old GOPATH tree to mask a missing requirement. The commands and their output are kept in the session, so the failure groups in the description can be checked line by line.
It is also work that suits being handed off. Resolving modules and running a neglected test suite is mostly waiting, and the judgement comes at the end, when the results need sorting. Start the run, do something else, and come back to a pull request and a list of decisions. If one of them needs your input, the sandbox is parked with its disk intact and a follow-up picks up where it stopped.
Frequently asked questions
What does this error actually mean?
Since Go 1.16 the go command works in module mode by default and looks for a go.mod file in the current directory or above it. Without one it does not know what project it is in or which dependency versions to use. Inside a repository the fix is go mod init with the right module path, followed by go mod tidy.
Can I set GO111MODULE=off instead?
It restores GOPATH mode on toolchains that still support it, and it leaves you with unpinned dependencies fetched at their latest commit. That is how old tests end up disagreeing with new libraries without anyone noticing. Converting to a module records the versions, which is what makes the build repeatable.
How do I choose the module path?
Use the path other code already imports. If the project's examples and README import gopkg.in/h2non/baloo.v3, that is the module path, whatever the repository URL says. A module at major version 2 or higher must carry the version in its path, as /v2 on most hosts or .v2 on gopkg.in.
Why do tests fail right after adding go.mod?
Usually because they are running for the first time in a long while. A current toolchain runs vet checks during go test, dependencies have moved, and services that tests call have changed. The agent separates those failures from anything the conversion caused, so you can merge the module and schedule the rest.
Should go.sum be committed?
Yes, together with go.mod. It holds the checksums of every module version the build uses, and the go command verifies downloads against it. The agent commits both and removes CI steps that fetched dependencies by hand.
More jobs like this: Hand off a long task
- Fix golangci-lint Findings in a Go CLI and Make Lint Block Merges (Go CLI)
- Fix N+1 Queries in a Gin API (Gin)
- Fix N+1 KV Reads in a Hono API (Hono)
- Fix N+1 Queries in a Flask + SQLAlchemy App (SQLAlchemy)
- Fix 'orm_mode' Has Been Renamed to 'from_attributes' in a FastAPI App (Pydantic)
- Fix "AttributeError: module 'scipy.misc' has no attribute 'imread'" (SciPy)