# Code Harvest

Extracts and exports structured Unity code segments for documentation, reuse, or organized archiving.

{% embed url="<https://assetstore.unity.com/packages/tools/utilities/code-harvest-ai-friendly-tools-323003>" %}

{% tabs %}
{% tab title="Overview" %}
**Code Harvest** is a Unity Editor tool designed to export project scripts in structured and automation-ready formats. It allows developers to generate consolidated exports of source files for documentation, backup, review, AI processing, or CI/CD integration.

The tool provides three usage modes: a quick one-click export, a configurable custom export interface, and a scene context exporter capable of serializing GameObject hierarchies and optionally embedding C# source code.

Exports can be generated through the Unity Editor interface or programmatically through an embedded local HTTP API running on `http://localhost:8080` .

Code Harvest does not modify project files. It reads scripts and writes export artifacts to `Assets/ScriptExports/` by default.

<figure><img src="/files/Ek0JljgjMYVUzsS6cIh2" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Installation" %}
After importing the package via the Unity Asset Store or Package Manager, the tool becomes available under:

**Tools > CodeHarvest > Open Exporter UI**

The HTTP server starts automatically when the Unity Editor loads, using an internal `HttpListener` bound to `localhost:8080`

The package requires the official Unity Newtonsoft.Json package for JSON export and API operations, as documented in the README
{% endtab %}

{% tab title="Quick Start" %}
Open the Exporter UI and navigate to the *Quick Export* tab. This mode is intended for fast full-project script exports with sensible defaults.

When triggered, Quick Export scans `Assets/Scripts` while excluding common external or plugin folders, then generates a consolidated export file in text format.

The resulting file contains:

* A structured file tree summary
* The full contents of each exported script
* A timestamped filename

The export location is `Assets/ScriptExports/`, and the file can be opened, copied to clipboard, or cleared directly from the interface.

<figure><img src="/files/E3PNY4wQejShsTWN5jb8" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Workflow" %}
Code Harvest operates through three primary workflows.

In **Quick Export** mode, it performs a predefined scan and writes a consolidated export with minimal configuration.

In **Custom Export** mode, users define inclusion and exclusion folders, file extensions, and export format. The tool scans eligible scripts, allows per-file selection, and generates exports in `.txt`, `.md`, `.json`, or `.zip` format \_2026-02-21\_18-26-09.

In **Scene Context** mode, the tool serializes a GameObject hierarchy, including selected components and optionally the underlying C# source files. Reflection is used to extract serialized fields, component data, and object references. The result can be wrapped as an AI-ready structured prompt, including ROLE, CONTEXT, and TASK sections.

For automation scenarios, the embedded HTTP server exposes endpoints for scanning and exporting scripts without manual interaction.

<figure><img src="/files/Pg0JIsd3e1XoXpZwMtq9" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Technical Notes" %}
Code Harvest is an Editor-only tool and has no runtime footprint README.

The local HTTP server initializes automatically using `HttpListener` and runs in a background thread. It shuts down safely during assembly reload or editor quit events.

Available API endpoints include:

* `GET /status` — returns server state and version
* `GET /scripts` — returns filtered script metadata
* `GET /export` — triggers export using query parameters
* `POST /export` — triggers export from a custom JSON payload

Export formats supported internally are:

* Plain text
* Markdown
* JSON
* ZIP archiv

The Scene Context exporter uses reflection to retrieve serialized fields and safely handles Unity object references. Source code inclusion is restricted to assets under the `Assets/` directory and excludes packages, plugins, and the Code Harvest tool itself.

All file output operations are written to disk and followed by `AssetDatabase.Refresh()` to ensure Unity detects the new files.
{% endtab %}

{% tab title="Limitations" %}
Code Harvest is not a static analysis tool and does not interpret code semantics. It performs structural export only.

The embedded HTTP API is limited to localhost and does not implement authentication. It is intended for local development and CI use, not public deployment.

Large projects with thousands of scripts may generate substantial export sizes, especially when including full source code inside scene context exports.

Scene Context serialization reflects serialized fields only and does not execute runtime logic.

JSON export and API features require the Unity Newtonsoft.Json package to be installed.
{% endtab %}

{% tab title="FAQ" %}

<details>

<summary>Does Code Harvest modify my scripts?</summary>

No. The tool only reads script files and writes export artifacts. It never edits or deletes source files.

</details>

<details>

<summary>Where are exports saved?</summary>

By default, exports are written to `Assets/ScriptExports/`. A custom output path can be specified via the HTTP API&#x20;

</details>

<details>

<summary>Can I use this in CI/CD pipelines?</summary>

Yes. The HTTP API can be triggered using `curl`, PowerShell, or any HTTP client. The `/export` endpoint supports both GET and POST operations&#x20;

</details>

<details>

<summary>Does the HTTP server expose my project externally?</summary>

No. The server binds only to `localhost` and `127.0.0.1`&#x20;

</details>

<details>

<summary>Can I export only specific files?</summary>

Yes. In Custom Export mode you can scan and manually select files. Through the API, a POST request can include a custom list of script entries

</details>

<details>

<summary>Why am I getting JSON-related compile errors?</summary>

You must install the official Unity Newtonsoft.Json package as described in the installation instructions

</details>
{% endtab %}
{% endtabs %}

***

{% content-ref url="/spaces/u6FKPRtV6vGPNteP2vic/pages/EgxBm4l0E89vUp4vN3qL" %}
[Code Harvest Changelog](/julestools-docs/changelog/readme-2.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://julestools.gitbook.io/julestools-docs/documentation/tools/code-harvest.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
