Skip to main content

CopyTree

Bundle a worktree, or a scratch or non-git folder, into a structured context snapshot (from the toolbar, a sidebar row, a file row, or an agent) with per-project history, re-runnable recents, and budgets you can test.

Updated
Reviewed

What CopyTree Does

CopyTree walks a worktree, applies your filters and budgets, and produces one structured bundle of the file tree plus file contents. Paste it into an agent, hand an agent the file it was written to, or inject it straight into a terminal. It saves you copying files one at a time or describing your project structure in prose, and it gives the agent something it can read in a single pass.

A copy normally resolves to a worktree: the active one, the one whose card you used, or the one a file row belongs to. A scratch workspace or a project folder that is not a git repository has no worktree, so there CopyTree bundles the folder itself; see workspaces without a worktree.

Note
CopyTree is also a standalone command-line tool, and Daintree embeds it as a library rather than shelling out to it. Nothing on this page needs it installed. If you want the same bundles in a bare terminal, a CI job, or an editor that is not Daintree, CopyTree CLI covers installing and using it.

Three Ways to Copy

The toolbar button

The Copy context button in the toolbar opens a menu rather than copying immediately:

  • Copy full context, with its keyboard shortcut, copies the whole worktree under your project settings.
  • Under Recent, up to five recent copies for this project, each with its name, size and age (the accessible name adds the file count and any non-default format). Selecting one re-runs it. A plain full-context copy is not repeated here, since the entry above already is that copy. Until something else has been copied the list reads "Copy a folder to reuse it here".
  • Context settings opens Settings > Project > Context, where the excludes and budgets that shape every copy live.

Shift-Command-C Control-Shift-C Control-Shift-C skips the menu and copies the full context for the active worktree directly. While a copy is running, the button shows a spinner and refuses a second run.

Copy the full context, or re-run a recent copy

The worktree card

  1. Click the ⋯ button on a worktree card, or right-click the card.
  2. Hover Copy.
  3. Choose Full context or Modified files only.

Full context copies everything that survives your filters, the right choice when you start a session, ask an architectural question, or onboard an agent to a project. Modified files only restricts the bundle to git-tracked files with staged or unstaged changes, on top of whatever else your project settings apply. Use it for iterative work, when the agent already holds the broader picture. The same submenu also copies the worktree's Path and Branch name.

Note
Untracked files (ones you have never run git add on) are not in a Modified files only bundle. Stage them first if you want them included.

From an agent

The in-app Daintree Assistant reaches CopyTree through three tools, all in the Full tool set; none is in Core. External API-key MCP clients expose only copyTree.generateAndCopyFile; they do not expose the temporary-file-only or terminal-injection tools:

ToolTool setWhat it does
copyTree.generateFullWrites the bundle to a temporary file and returns its path.
copyTree.injectToTerminalFullStreams the bundle straight into a terminal. Target an idle one: this types a potentially enormous payload into a live pane.
copyTree.generateAndCopyFileFullBundles to a file and puts it on the system clipboard, replacing what you had copied. macOS and Linux copy the file; Windows copies its path.

A bundle is never returned inline. copyTree.generate hands back a file handle because these bundles routinely run to tens of megabytes; the caller can opt into a bounded head of the content alongside the path, with a flag saying whether that head was truncated. Temporary bundles are pruned by age, so an agent should read the file promptly.

Named copies

Assistant and MCP callers can pass a name with the run. That name becomes the label on the history row, so an agent's "auth module context" sits in the same recents list as your own copies, labeled the way it described itself rather than as another anonymous entry. Names are capped at 120 characters; a run with no name gets one derived from its options.

Without a worktree

In a scratch workspace, or a project whose folder is not a git repository, there is no worktree to copy, so CopyTree bundles the workspace folder itself under the same ignore rules and budgets. These routes copy it:

  • the toolbar's Copy context menu and Shift-Command-C Control-Shift-C Control-Shift-C ;
  • Copy > Full context on the folder's row in the sidebar, from its ⋯ button or a right-click;
  • a recent copy re-run from the toolbar menu, which replays against the folder when there is no active worktree.

For a project, Daintree first confirms the folder really is not a git repository. While a git project's worktrees are still loading, the button stays unavailable with the tooltip "Open a worktree first" rather than copying the whole folder by mistake; with no project or scratch open at all it reads "Open a project or scratch first". Modified files only needs git, so the folder's row doesn't offer it, and the file-row scoped copies still need a worktree. A scratch has no project settings, so its menu has no Context settings entry.

How a Finished Copy Is Confirmed

A copy from the toolbar menu, the shortcut, the action palette, a recent re-run or an agent confirms with a short-lived notice pinned to the toolbar's Copy context button for about five seconds. It carries the title "Context copied", followed by the run's name when an agent named it, and a one-line summary: file count, size, and format. That includes copies you never clicked for, like an agent bundling context in the background.

The notice falls back to a toast when the button can't carry it: the button is unmounted or has overflowed out of the toolbar, the window is in the background, or the recents menu is open on the same anchor and the two surfaces would stack. In a background window the fallback lands in the notification inbox instead of a toast. The notice is mirrored into a live region, so assistive technology gets it either way.

A copy started from a row menu (a worktree card, or a file row's Copy context) shows a progress toast instead, updated in place with the same result, and an injection into a terminal reports "Context injected". The summary's wording follows the destination, because the verb has to be true: clipboard copies read "Copied … to clipboard", terminal injections "Injected … into terminal", and temporary-file bundles "Bundled … into a temporary file". A failure reads Copy context failed: … with the reason.

Tip
Read the file count and size as a token-budget check before you send the bundle anywhere. If it looks too big, the fix is usually a scoped copy rather than a tighter global filter.

Scoped Copies

Right-click a file or folder row in the file browser, the diff sidebar, the Review Hub, or the worktree card's changed-file list, and choose Copy > Copy context. It bundles just that path.

A scoped copy passes the row's literal path rather than a pattern, and scoping restricts traversal rather than adding a filter: your project's ignore rules and excludes still apply inside the scope, so the result is exactly the subset a whole-worktree copy would have produced for that path. Nothing outside the scope can be pulled in.

That default is deliberate, but it has a cost: name a folder your .gitignore prunes and you get an empty bundle. Rather than leave you to guess, an empty scoped copy reports No files copied and explains itself: "Every file in this folder is excluded by an ignore rule" when that accounts for all of it, and a neutral wording when the causes are mixed.

Agent and MCP callers have a narrow escape hatch for exactly that case. scopeIgnoresIgnoreFiles lifts only the rules blocking entry into each scoped path, and only from .gitignore and .copytreeignore. Unrelated rules in those same files, negations, ignore files at or below the selection, project excludes, .git, the git filters and every budget all still apply. It requires scopePaths and is rejected without it.

Filtering and Pattern Semantics

The selection surface an agent sees is wider than the project settings screen, and the shapes are not interchangeable:

OptionBehavior
filter / includePathsTwo spellings of one selection set, unioned when both are given. Worktree-relative exact file paths or globs. An explicit selection includes matching dotfiles; an unfiltered whole-project copy keeps the library’s hidden-file default. Empty arrays and blank selection entries are rejected.
excludePatterns to drop. Installed as an ignore layer, so it prunes before the include patterns are consulted.
alwaysForce-include. The blunt instrument: it beats ignore files, project and config excludes, your own exclude, the git filters, and the per-file size gate.
scopePathsLiteral file or directory paths to walk. Restricts traversal; the include patterns can only narrow within it.
modified / changedOnly files with uncommitted changes, or only files changed since a named base branch.
Warning
Patterns match file paths, so a folder needs a glob: pass src/panels/**, not src/panels. scopePaths is the exact opposite: literal paths, so pass src/panels there. When a selection matches nothing, the result names which selector came up empty rather than just reporting an empty bundle.

What always does not override is worth knowing before you reach for it: your explicit include selection and scope, .git, CopyTree's internal 10 MB per-file memory ceiling, and the file-count, total-size and character budgets, which still drop force-included files. A broad always pattern can pull in node_modules, and a ../ pattern reaches outside the worktree entirely. When you only need past an ignore rule, prefer a scoped copy.

CopyTree reads and honors your project's .gitignore and .copytreeignore alongside the excludes configured in project settings.

Limits and Budgets

These are enforced, not advisory: a file that survives every filter is still dropped when a budget bites, force-included or not. The first four are settings in Settings > Project > Context, where sizes are entered in megabytes and an empty field means the default.

SettingDefaultEffect
Max context size100 MBTotal size of all included files.
Max file size10 MBFiles larger than this are skipped. Left empty, there is no separate per-file gate, and CopyTree's own 10 MB ceiling is the limit.
Character budgetNo limitTotal characters of file content across the bundle.
File priority strategyDefault (all files)Which files to keep when a budget drops some: Include all files or Recently modified first.
File count10,000CopyTree's own cap on selected files. Not a project setting; agents can pass a lower one.

A result reports which budget bit first and how many files it dropped, so a truncated bundle is legible rather than silently short. The total-size budget fits greedily: a file that doesn't fit is skipped and smaller files after it are still considered. A single file larger than the whole budget is dropped like any other, so a tight budget over a few large files can produce an empty bundle.

Output Formats

Six formats are available, chosen per run by the caller: xml (the default), json, markdown, tree, ndjson, and sarif. XML suits AI consumption, Markdown reads well to a human, and tree gives the structure alone with no file contents, a cheap way to orient an agent before it reads into specific files.

Format is not a project setting. Manual copies use the default; agents and MCP clients name a format on the call.

Testing Your Configuration

Test config, under Test configuration in Settings > Project > Context, runs a dry pass against the project's main worktree with your current (including unsaved) settings, and reports:

  • How many files would be included, at what total size, with a rough token estimate.
  • How many were excluded, and the reasons that account for most of them.
  • The file list itself, with per-file sizes, so you can see what actually made the cut.
  • A truncation warning naming the budget that bit, if one did.

Sizes are an estimate: the dry run plans the character budget from file sizes without reading content, and says so when a character budget is set. The button is unavailable while a limit field holds an invalid value ("Fix the limit values above to test"), and in a project with no worktrees.

The Test config result in Settings > Project > Context
Tip
Run this before your first full copy on a large project. It is a quick check that your filters catch the right files at a sane size, and it is much faster than discovering the problem in an agent's context window.

Per-Project Configuration

CopyTree settings are per-project, so each repository gets its own excludes and budgets. Configure them in Settings > Project > Context (see Project Settings), or from Context settings at the bottom of the toolbar's Copy context menu. The tab holds Excluded paths (also left out of file monitoring), then Context generation with the four limits above and the Always include and Always exclude glob lists, and the Test config panel.

Options supplied on a call take precedence over the project's settings, field by field: an agent that names its own exclude replaces yours for that call rather than adding to it. When a call names no excludes, the project's excluded paths and its always-exclude patterns are combined and used together.

Copy History

Every completed run is recorded in a per-project history: 20 records kept, up to five surfaced in the menu. The file lives beside that project's own settings, and its updates reach only views bound to that project.

Each record stores the caller's options before project settings were folded in. That is what makes a re-run useful rather than a fossil: replaying a record dispatches its original options through the normal path, so current project settings and excludes apply. A record that froze the merged result would replay a configuration you had since changed.

Runs are also tagged with the surface that asked for them (toolbar, shortcut, worktree card, file browser, MCP, terminal, or workflow), because the same options mean different things coming from a folder menu and from an agent.

Recents replay against the active worktree, not the worktree stored on the record, or against the workspace folder when there is no worktree. The record's worktree is whichever one ran it last, and it may since have been removed.

Multi-Window Behavior

CopyTree resolves the worktree and the project settings from the view that made the request, not from whichever project the app most recently focused. A call from a backgrounded window therefore reaches its own project rather than failing or picking up a sibling project's exclusions. The same resolution is captured before any asynchronous work starts, so a view that gets evicted mid-request can't silently drop its project's settings from the bundle.

Embedded Library and Configuration

This documentation was checked against Daintree’s pinned CopyTree 1.0.0-rc.3. The app supplies its packaged defaults and project/call options directly; it does not load the CLI’s user-level configuration. Installing a different CLI version does not upgrade the app’s engine.

The adapter maps the app’s max-file setting to CopyTree’s overridable size gate, preserves the library’s separate memory ceiling, sorts before applying budgets, and disables the library’s secret redaction to preserve source text. Review the bundle and project exclusions before sharing it. The CopyTree service is the source reference for option mapping, streamed temporary files, cancellation and budget reporting.