# Plans, Goals & Checkpoints

> Source: https://parallelworks.com/docs/ai/code/plan-and-goals

# Plans, Goals & Checkpoints

Beyond one prompt and one answer, `pw code` can plan before it changes anything, keep working until a condition you set is met, repeat a prompt on a schedule, and roll code and conversation back to an earlier prompt.

## Plan Mode

In plan mode the agent researches and writes a plan instead of changing your code. It can read and search files and run shell commands that do not modify anything, and the only file it may write is its plan. See [Plan Mode](/docs/ai/code/permissions#plan-mode) for exactly what is allowed.

Enter plan mode in any of these ways:

- Press <kbd>Shift</kbd>+<kbd>Tab</kbd> until the permission line shows `⏸ plan mode`.
- Start with `pw code --permission-mode plan`.
- Run `/plan`, or `/plan <description>` to switch and start planning that task in one step.

| Command | Effect |
| --- | --- |
| `/plan` | Switch to plan mode, and show the session's plan if it has one. |
| `/plan <description>` | Switch to plan mode and send the description as the next prompt. |
| `/plan open` | Open the plan file in your editor. |

Plans are saved as markdown files under `~/.local/state/pw/plans/`, named after your request. The plan stays with the session, so `/plan` shows it again after you resume. `/plan` works from the main session, not from a subagent's window.

### Approving a Plan

When the plan is ready, the agent asks you to approve it. The prompt shows the plan and three choices:

1. **Yes, clear context and auto-accept edits**: Clear the conversation and start building the plan in `accept-edits` mode, with the plan as the starting point.
2. **Yes, auto-accept edits**: Keep the conversation and switch to `accept-edits` mode.
3. **Tell the agent what to change**: Type feedback and press <kbd>Enter</kbd> to send it back; the agent revises the plan and asks again.

| Key | Action |
| --- | --- |
| <kbd>↑</kbd>/<kbd>↓</kbd> or <kbd>k</kbd>/<kbd>j</kbd> | Move between choices. |
| <kbd>1</kbd>-<kbd>3</kbd> | Jump to a choice. |
| <kbd>Enter</kbd> | Confirm the highlighted choice. |
| <kbd>Shift</kbd>+<kbd>Tab</kbd> | With feedback typed, approve the plan and pass the feedback along as a note. |
| <kbd>Ctrl</kbd>+<kbd>G</kbd> | Edit the plan in your editor (`$VISUAL`, then `$EDITOR`); your edits become the plan. Not available in an [attached](/docs/ai/code/remote-control#attaching-to-another-machine) session. |
| <kbd>PgUp</kbd>/<kbd>PgDn</kbd>, <kbd>Home</kbd>/<kbd>End</kbd> | Scroll the plan. |
| <kbd>Esc</kbd> | Decline; the agent stays in plan mode. |

In a [non-interactive run](/docs/ai/code/non-interactive), approval is always declined and the run prints where the plan was saved.

## Goals

`/goal <condition>` keeps the agent working until a condition is met. The agent starts right away, and after every turn a separate check reads the conversation and decides whether the condition holds. If it does not, the agent takes another turn, guided by what the check found missing.

```text
/goal all tests in ./parser pass and go vet is clean, or stop after 20 turns
```

The check cannot run commands or read files: it judges only what the agent showed in the conversation, so state the condition in terms the agent can prove, such as a command's exit status. Bound the loop in the condition itself, with a turn or time limit; the check honors it even when the work is unfinished. Conditions are limited to 4,000 characters.

| Command | Effect |
| --- | --- |
| `/goal <condition>` | Set the goal and start working toward it. Replaces any current goal. |
| `/goal` | Show the current goal, or the one most recently achieved. |
| `/goal pause` | Stop the loop but keep the condition. `hold` also works. |
| `/goal resume` | Pick a paused goal back up. `continue` also works. |
| `/goal clear` | Stop working toward the goal. `stop`, `off`, `reset`, `none`, and `cancel` also work. |

`/goal` takes effect immediately, even while a turn is running. Interrupting a turn with <kbd>Esc</kbd> or <kbd>Ctrl</kbd>+<kbd>C</kbd> pauses the goal; run `/goal resume` or send a prompt to continue. While a goal is set, `◎ /goal active (elapsed)` or `◎ /goal paused` shows above the composer, and when the check passes the transcript reports the time, turns, and tokens it took.

The goal is saved with the session and survives a resume. Each check is an extra model request. To run a goal from a script, see [Running a Goal](/docs/ai/code/non-interactive#running-a-goal).

## Loops

`/loop` repeats a prompt in the session:

```text
/loop 10m check the deploy and report any failed pods
/loop run the flaky test again and dig into any failure
/loop
```

- **With an interval** (`30s`, `5m`, `2h`, `1d`, or a trailing `every 2 hours`), the agent creates a recurring scheduled task for the prompt. Intervals are converted to a cron schedule, so seconds round up to one minute.
- **Without an interval**, the loop paces itself: after each pass, the agent picks a delay from 1 to 60 minutes before the next one, and stops when the work is done.
- **Without a prompt**, a maintenance prompt runs: continue unfinished work from the conversation, then tend to the current branch's pull request (review comments, failed CI runs, merge conflicts), and otherwise do a focused cleanup pass. To replace it, write your own prompt in `.claude/loop.md` in the workspace, or in `~/.claude/loop.md` for every workspace.

Ask the agent to list or cancel scheduled tasks at any time. A session holds up to 50 scheduled tasks, and recurring tasks expire after 7 days. Tasks fire while the session is hosted by the [background daemon](/docs/ai/code/remote-control#the-background-daemon), so they keep running after you quit `pw code`. Set the `CLAUDE_CODE_DISABLE_CRON` environment variable to `1` to turn off `/loop` and scheduled tasks entirely.

## Rewinding to a Checkpoint

`pw code` takes a checkpoint each time you send a prompt in the main session, keeping the 100 most recent. To go back to one, run `/rewind`, or press <kbd>Esc</kbd> twice at an empty prompt. Pick a prompt from the list, newest first, then choose what to restore:

| Choice | Effect |
| --- | --- |
| **Restore code and conversation** | Undo file changes made since that prompt, and remove that prompt and everything after it from the conversation. |
| **Restore conversation** | Remove that prompt and everything after it, leaving files as they are. |
| **Restore code** | Undo file changes made since that prompt, keeping the conversation. |

The code choices appear only when files changed after that prompt. When the conversation is restored, the prompt is put back in the composer so you can edit and resend it.

:::note What code restore covers
Code restore undoes changes the agent made with its file-editing tools. Changes made by shell commands, by you, or by other programs are not tracked.
:::

`/rewind` is available only from the main session, and waits for a running turn to finish.

## Related Documentation

- [pw code Overview](/docs/ai/code): Feature overview and quick start
- [Permissions](/docs/ai/code/permissions): Permission modes, including plan mode
- [Slash Commands](/docs/ai/code/slash-commands): All built-in commands
- [Non-Interactive Mode](/docs/ai/code/non-interactive): Goals and plans in scripts
- [Interface & Shortcuts](/docs/ai/code/interface): Keyboard shortcuts
- [Remote Control & Agents](/docs/ai/code/remote-control): The background daemon that runs scheduled tasks
