Reference for using Codefresh via the CodeFresh CLI (run from its Docker image). Use when a Codefresh CI check is failing in a recursionpharma PR, or when working with Codefresh builds.
24 stars
0 votes
0 copies
4 views
Added September 3, 2026
ai-agentspythonbashdockergitapi
Works with
claude code
cli
api
Security analysis
B75/100
criticalAccesses sensitive system or user directories
criticalSends environment variables or credentials to an external URL
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Use Codefresh?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/ooloth-use-codefresh)
---
name: use-codefresh
description: Reference for using Codefresh via the CodeFresh CLI (run from its Docker image). Use when a Codefresh CI check is failing in a recursionpharma PR, or when working with Codefresh builds.
allowed-tools: [Bash, Read]
---
Consider using a subagent when you just need an answer and don't need to see the intermediate
CodeFresh responses.
## Extract Build ID from PR Status Checks
From `gh pr view <number> -R <owner>/<repo> --json statusCheckRollup`:
- Failing checks have `"state": "FAILURE"` (StatusContext) or `"conclusion": "FAILURE"` (CheckRun)
- Build URL is in `targetUrl` (StatusContext) or `detailsUrl` (CheckRun)
- Extract the 24-char hex ID from `https://g.codefresh.io/build/{build-id}`
## Commands
```bash
# A pipeline's recent builds, newest first. The name includes the project prefix
# (example-project/example-pipeline); --branch and --status also filter.
# The table's times are local but 12-hour with no AM/PM, so read `created` from -o json
codefresh get builds --pipeline-name <project>/<pipeline> --limit 5
# Build metadata, including "status", "started" and "finished". This is the way to watch a build
# that is still running: poll it until the status is no longer running or pending
codefresh get builds <build-id> -o json
# Full logs of a FINISHED build (can exceed 30k lines — use grep to find errors quickly)
codefresh logs <build-id> | grep -E -B 10 -A 20 -i "error|fail|found.*error"
```
A plain `codefresh logs` on a build that is still running or waiting for approval can print nothing
and never return, and the wrapper stops it after 90 seconds with exit code 142 and a line on stderr
saying so. Check the status with `codefresh get builds <build-id> -o json` first, and read logs once
it has finished. A finished build's `logs` occasionally hangs the same way, and running it again
prints the log. `codefresh logs -f` follows a running build, but the wrapper allows it an hour,
which is longer than a Bash call can wait, so poll the status instead.
A build at `pending-approval` prints no log until it ends. Read its effects instead: image tags in
Artifact Registry and the CD commit in the repo the pipeline commits image tags to, which the
project's docs name.
```bash
# Each image digest with its tags and when it was last pushed
gcloud artifacts docker images list <registry>/<project>/<repository>/<image> --include-tags \
--format='value(version,tags,updateTime)'
# Commits on the CD repo's default branch since the build started (UTC)
gh api "repos/<owner>/<cd-repo>/commits?sha=<default branch>&since=<build start>" \
-q '.[] | .sha[0:8] + " " + .commit.committer.date + " " + (.commit.message | split("\n")[0])'
```
## Log Structure
Codefresh logs are long (often 1000–3000+ lines) and front-loaded with noisy setup
output: apt package installs, Python compilation `configure` checks, mise tool
downloads. **The actual failure is almost always near the end.** Skip directly to
the tail and work backwards:
```bash
# Start at the end — most failures appear in the last ~100 lines
codefresh logs <build-id> 2>&1 | tail -100
# Then narrow with grep if needed
codefresh logs <build-id> | grep -E -B 5 -A 15 "FAILED|ERROR|AssertionError|raise " | tail -150
```
### Failure type heuristics
| What you see near the end | Likely cause |
|---|---|
| `FAILED tests/...` / `AssertionError` | Test failure (prek/pytest) |
| `ruff-check...Failed` / `ty check...Failed` | Lint or type error |
| `error: ...` in a Python traceback | Runtime error in a build step |
| Process exited with code 1, no clear message | Check a few hundred lines before the end |
## Starting a run
Starting a build is a side effect, so get the user's approval first and say so in the command's
description, or the auto-mode classifier blocks it. `--detach` prints the build id and returns:
```bash
codefresh run <pipeline-name-or-id> --trigger <trigger-name> -b <branch> -s <full-sha> --detach
```
A new run loads the pipeline's spec as it is now, when the spec comes from git (`specTemplate` with
`revision: trunk` in `codefresh get pipelines <name> -o json`). A restart replays the spec the
original build ran, so to pick up a spec change, start a new run instead of restarting.
To try a spec change before it merges, pass the local file with `--yaml`, run from the repo that
holds it. The wrapper mounts the current directory when any argument names a file or folder that
exists, except when it is your home folder or a folder above it. Only paths inside the current
directory resolve in the container, so a relative path works from inside the repo:
```bash
codefresh run <pipeline-name> --trigger <trigger-name> -b <branch> -s <full-sha> \
--yaml build/pipelines/<spec>.yaml --detach
```
## Troubleshooting
**Command not found:** `codefresh` is a wrapper in the dotfiles (`tools/codefresh/bin/codefresh`,
linked into `~/.local/bin` by its `link.bash`) that runs the official `codefresh/cli` Docker image.
Do not install it with Homebrew or npm. The Homebrew tap's packaged binary crashes on startup with
`Cannot find module '/snapshot/cli/...'`, and the npm package needs a git dependency that npm 12
refuses to fetch by default.
**Docker isn't running:** the wrapper says so and exits 1. Ask the user to start Docker. If they
can't, the REST API answers the same questions, but an agent in auto mode is usually blocked from
reading the token out of `~/.cfconfig`, so ask the user's approval before trying:
```bash
TOK=$(grep -E "^\s+token:" ~/.cfconfig | head -1 | sed -E "s/.*token: *'?([^']*)'?/\1/")
cf_auth_header() { printf 'Authorization: %s\n' "$TOK"; } # printf is a builtin, so the token stays out of ps
cf_auth_header | curl -s -H @- "https://g.codefresh.io/api/workflow?limit=100&page=1" # recent builds
cf_auth_header | curl -s -H @- "https://g.codefresh.io/api/builds/<build-id>" # one build
cf_auth_header | curl -s -H @- "https://g.codefresh.io/api/progress/<progress-id>" # log location
```
The build document's `progress` field is the progress id. The progress document's `location.url` is
a signed URL that returns the whole log as JSON, with one entry per step in `steps[].logs`.
**Not authorized:** Run `codefresh auth current-context` to check the active context. If missing or
wrong, the user needs to re-authenticate. The wrapper mounts `~/.cfconfig` read-only, so the user
stores the API key once with `secret add codefresh`, then runs the image directly (no `:ro`), or
edits `~/.cfconfig` directly. The user runs this, not you: Claude Code's settings deny any Bash
command containing `secret get`.
```sh
( t="$(secret get codefresh)" && CF_ARG_API_KEY="$t" docker run --rm -it -e CF_ARG_API_KEY \
-v ~/.cfconfig:/root/.cfconfig codefresh/cli auth create-context )
```