Product case study · November 12, 2026

Keep working while Claude Code runs your tests

Use Claude Code background commands and /tasks to keep working during a test run, then retrieve its exit status and failure output.

Reading time
6 min
Checked
Nov 12, 2026
A cut-paper hourglass feeds a charcoal conveyor carrying an ochre card toward a muted blue evidence tray
A free prompt is useful. A finished test result is what lets you move on.
Bottom line

Background a slow test when you have independent work to do. Keep its command, task ID and final result together before calling the change ready.

A slow test suite should not hold your conversation hostage. Let it run while you ask Claude to explain a confusing function or draft the release note. The useful trick is keeping the test result attached to the work: getting your prompt back does not tell you whether anything passed.

Claude Code supports background Bash commands, with task IDs and saved output. Ask it to background a command, or press Ctrl+B during a regular Bash tool invocation. In tmux, Anthropic documents pressing Ctrl+B twice. Keep the session open for this exercise. These behaviors come from the interactive-mode reference.

The Python fixture below was tested locally in both modes. The Claude Code interaction is a documentation-backed walkthrough, not a reported end-to-end Claude session. Official sources checked November 12, 2026. You need Python 3, an installed and authenticated Claude Code CLI, and Bash on macOS, Linux or WSL.

Give yourself a test worth waiting for

Start in a fresh practice directory. This fixture waits 15 seconds so you have time to inspect the background task. Its two tests check a tiny expense calculation; --fail deliberately changes one expected value. It installs nothing and makes no network requests.

Paste this into your ordinary terminal:

lab_dir=$(mktemp -d /tmp/claude-background-lab.XXXXXX)
cd "$lab_dir"
cat > slow_tests.py <<'PY'
import sys
import time
import unittest

force_failure = "--fail" in sys.argv
if force_failure:
    sys.argv.remove("--fail")

class ExpenseTests(unittest.TestCase):
    def test_total(self):
        expected = 36 if force_failure else 35
        self.assertEqual(sum([12, 23]), expected)

    def test_empty(self):
        self.assertEqual(sum([]), 0)

if __name__ == "__main__":
    print("Practice run: waiting 15 seconds before testing", flush=True)
    time.sleep(15)
    unittest.main(verbosity=2)
PY
claude

Review any workspace trust prompt for this new directory. Inside Claude Code, send:

Run python3 slow_tests.py as a background Bash command in this directory.
Do not edit the file or launch a second run.
Report the exact command and background task ID.
Leave the result pending until that task finishes.

Review any command approval Claude requests. If it starts the command in the foreground, use Ctrl+B while it runs. If the run has already finished, read that result; there is no need to repeat it just to see a background indicator.

Use the waiting time without moving the target

Open the background-work view:

/tasks

Anthropic’s command reference identifies /tasks as the current session’s background-work list. Use the task ID and command to locate your run. A planning checklist is a different view; it does not establish that a shell command completed.

For a small independent request, ask:

Read slow_tests.py and explain what the empty-list test checks.
Do not edit files, run commands or start another test.

I would use this waiting time for explanation or review. Editing the same files the tests are reading makes the result harder to interpret: which version did the runner actually exercise? For this first experiment, keep the input still and watch one run finish.

Retrieve the result, including the unpleasant one

Once the task completes, send:

Retrieve the output and exit status for the background task you started.
Report its task ID, exact command, number of tests and final test summary.
If the result is unavailable or still pending, say so. Do not rerun it.

The supplied normal run should exit with status 0 and a summary showing two tests and OK. That is the fixture’s expected outcome, not a promise about your application’s tests.

Now practise the failure path:

Run python3 slow_tests.py --fail as a new background Bash command.
Do not modify the fixture to repair the deliberate failure.
When it finishes, retrieve this run's exit status and output.
Explain which assertion failed and why.

The expected result is exit status 1, two tests run, and one failure: the calculated total is 35 while the deliberately wrong expectation is 36. A summary that says “tests completed” misses the most useful fact.

Write down your observed results using this small record:

RunTask IDExit statusSummary
python3 slow_tests.pyYour first IDObserved valueObserved test summary
python3 slow_tests.py --failYour second IDObserved valueObserved failing assertion

This follows Anthropic’s advice to give Claude a check to run. In your own project, choose a check that can expose the bug you care about. A passing command is only as useful as what it checks.

Recover without creating a pile of duplicate runs

If the task is still running, inspect it before launching another. If the output is missing, ask for the saved output associated with that task ID. Record an unknown result as unknown; rerunning is a new observation, not recovery of the old one.

If backgrounding is unavailable, check whether CLAUDE_CODE_DISABLE_BACKGROUND_TASKS=1 is set or the session uses bare mode. Both disable background commands according to the interactive-mode documentation. You can finish the exercise in the foreground without changing those settings.

For a stuck run, use /tasks to identify and stop that specific task. Avoid broad process-kill commands. Anthropic documents cleanup of background tasks when Claude Code exits, so this walkthrough should not be treated as an overnight scheduler.

For a real repository, replace the Python command with its documented test command. Keep the command and final output beside the change you reviewed. My rule is simple: if I cannot tell which run produced the result, I am not ready to use it as the reason to ship.

Sources and verification

The hero is an AI-generated editorial illustration, not a screenshot of Claude Code.

Put this to work

Track a background test from launch through completion in Claude Code.

Try

Run the supplied Python fixture in the background, then repeat with --fail.

Prove it worked

Match each task ID to its command, exit status and test summary; explain the intentional failure.

Keep in view

  • Move a slow Bash command into the background while keeping the session open.
  • Practise with a disposable test that can pass or deliberately fail.
  • Retrieve the exact run's exit status and output before accepting its result.
Learn the workflow: Build your first small project with Claude Code