# Claude Code Multiple agents, background work, and workflows

> Claude Code: Agent View, background sessions, batch, fork, goals, loops, dynamic workflows, teams, and cache/cost boundaries.

URL: https://docs.passion8.cc/en/docs/claude-code/parallel-agents
Language: en
Publisher: Passion8

Parallel execution includes several different mechanisms:

| Mechanism | Unit | Use |
| --- | --- | --- |
| Subagent | Focused delegation in a session | Research, review, context isolation |
| Background session | Complete session in the background | Long work with a free terminal |
| Agent View | Multiple background sessions | Monitor task progress |
| Batch | Bundled migration skill | Repeated changes across worktrees |
| Dynamic workflow | Script-orchestrated subagents | Audits, migrations, research, repair loops |
| Agent teams | Named collaborating teammates | Sustained coordinated work |

See [Teams and channels](https://docs.passion8.cc/en/docs/claude-code/agent-teams-channels) for configuration and [Advanced workflows](https://docs.passion8.cc/en/docs/claude-code/advanced-workflows-cloud) for comparisons.

## Background sessions

```text
/background
/bg Continue running tests and repair failures
```

Manage from the shell:

```bash
claude agents
claude agents --json
claude attach <id>
claude logs <id>
claude stop <id>
claude respawn <id>
claude rm <id>
```

| Action | Cache effect |
| --- | --- |
| Background | Same session continues within TTL |
| Attach | Resume its existing history |
| Respawn | Retains conversation; changed version/environment can alter prefix |
| Stop | No further TTL refresh |

## Agent View

| Capability | Purpose |
| --- | --- |
| Monitor | State and input needs |
| Peek/reply | Send input without fully attaching |
| Attach | Enter a background session |
| Dispatch | Start a new task |
| Filter | Directory, status, PR |
| JSON | Scriptable agents output |

Use worktrees to isolate writes and clean completed workspaces when the directory grows.

## Fork versus branch

| Command | Behavior | Use |
| --- | --- | --- |
| /branch [name] | Copy conversation and switch to it | Personally explore another route |
| /fork | Send current context to a background subtask | Independent side work |

Both inherit a prefix that may remain reusable within TTL.

## Batch

Batch typically:

1. Studies the repository.
2. Splits work into roughly 5–30 independent units.
3. Presents a plan for approval.
4. Creates isolated worktrees and background agents.
5. Implements/tests each unit and returns PRs or results.

| Suitable task | Example |
| --- | --- |
| Migration | /batch migrate src from Redux to Zustand |
| Repeated replacement | /batch replace deprecated API usage across packages |
| Test coverage | /batch add missing tests for service modules |
| Broad review | /batch audit every package for unsafe env access |

| Poor fit | Reason |
| --- | --- |
| Vague requirements | Incorrect task decomposition |
| Strongly coupled edits | Merge conflicts |
| No validation criteria | Hard to converge |
| Every step needs manual review | Background concurrency obscures sequencing |

## Dynamic workflows

Claude writes an orchestration script that calls subagents for repeatable, separable work and aggregates results.

```text
Use a workflow to audit all content/docs pages for untranslated UI text and broken links.
Return one consolidated report.
```

```text
Migrate each package's ESLint configuration with one subagent per package,
then run the combined validation.
```

| Aspect | Batch | Dynamic workflow |
| --- | --- | --- |
| Purpose | Large code-change skill | General orchestration |
| Units | Worktrees/subagents | Script-defined |
| Reuse | Task-oriented | Script can be retained |
| Observation | Background sessions/progress | /workflows |

## Goals

A goal defines completion criteria and lets Claude continue until achieved or genuinely blocked.

```text
/goal Complete the documentation migration: new pages build, no raw directives,
new routes return 200, and mobile pages have no horizontal overflow.
```

| Good goal | Weak goal |
| --- | --- |
| Verifiable conditions | Make it good |
| Test/check commands | Improve it as much as possible |
| Autonomous progress | Wait for approval on every routine step |
| Defined blockers | Stop at every small error |

Goal state itself does not rebuild the system prompt. Continued turns append normally and refresh TTL; compaction/model changes retain their usual effects.

## Loops and schedules

| Mechanism | Use | Cache consideration |
| --- | --- | --- |
| Loop | Periodic checks in current session | Intervals within TTL help |
| Schedule | One-off or recurring work | Longer intervals may benefit from supported longer TTL |
| Routines | Hosted automation | Independent cloud cache |

Do not expect a five-minute cache to remain warm through long gaps. Short prompts, stable rules, and explicit output limits matter. See [Scheduling](https://docs.passion8.cc/en/docs/claude-code/routines-scheduling).

## Cache and cost boundaries

| Unit | Relationship |
| --- | --- |
| Main session | Own prompt/project/history |
| Subagent | Separate conversation, typically its own default TTL |
| Background session | Complete history and TTL |
| Worktree | Different paths can change prompt prefixes |
| Cloud session | Separate environment, not local Passion8 cache |
| Advisor | Toggle preserves main cache; advisor requests have separate behavior |

## Practical recommendations

1. Use the main session for small work.
2. Isolate broad research in subagents.
3. Plan decomposition before batch/workflow migrations.
4. Combine parallel writers with worktrees and shared acceptance criteria.
5. Give every task an explicit validation command.
6. Avoid overlapping file regions; conflict resolution can erase concurrency gains.

## Official references

- [Parallel agents](https://code.claude.com/en/docs/en/agents.md)
- [Agent View](https://code.claude.com/en/docs/en/agent-view.md)
- [Workflows](https://code.claude.com/en/docs/en/workflows.md)
- [Subagents](https://code.claude.com/en/docs/en/sub-agents.md)
- [Worktrees](https://code.claude.com/en/docs/en/worktrees.md)
- [Teams](https://code.claude.com/en/docs/en/agent-teams.md)
- [Channels](https://code.claude.com/en/docs/en/channels.md)
- [Goals](https://code.claude.com/en/docs/en/goal.md)
- [Scheduled tasks](https://code.claude.com/en/docs/en/scheduled-tasks.md)
