MCPcopy Create free account
hub / github.com/CodeGraphContext/CodeGraphContext / watch

Function watch

src/codegraphcontext/cli/main.py:1771–1813  ·  view source on GitHub ↗

Watch a directory for file changes and automatically update the code graph. This command runs in the foreground and monitors the specified directory for any file changes. When changes are detected, the code graph is automatically updated. The watcher will: - Perfor

(
    path: str = typer.Argument(".", help="Path to the directory to watch. Defaults to current directory."),
    context: Optional[str] = typer.Option(None, "--context", "-c", help="Specific context to use"),
    poll: bool = typer.Option(
        False,
        "--poll",
        help="Use watchdog's polling observer for Docker bind mounts and network filesystems.",
    ),
    sync_on_start: bool = typer.Option(
        False,
        "--sync-on-start",
        help=(
            "Synchronize already-indexed files before watching. "
            "Defaults off; use 'cgc index --force' for a full re-index."
        ),
    ),
)

Source from the content-addressed store, hash-verified

1769
1770@app.command()
1771def watch(
1772 path: str = typer.Argument(".", help="Path to the directory to watch. Defaults to current directory."),
1773 context: Optional[str] = typer.Option(None, "--context", "-c", help="Specific context to use"),
1774 poll: bool = typer.Option(
1775 False,
1776 "--poll",
1777 help="Use watchdog's polling observer for Docker bind mounts and network filesystems.",
1778 ),
1779 sync_on_start: bool = typer.Option(
1780 False,
1781 "--sync-on-start",
1782 help=(
1783 "Synchronize already-indexed files before watching. "
1784 "Defaults off; use 'cgc index --force' for a full re-index."
1785 ),
1786 ),
1787):
1788 """
1789 Watch a directory for file changes and automatically update the code graph.
1790
1791 This command runs in the foreground and monitors the specified directory
1792 for any file changes. When changes are detected, the code graph is
1793 automatically updated.
1794
1795 The watcher will:
1796 - Perform an initial scan if the directory is not yet indexed
1797 - Attach immediately for already-indexed directories unless --sync-on-start is passed
1798 - Monitor for file creation, modification, deletion, and moves
1799 - Automatically re-index affected files and update relationships
1800
1801 Press Ctrl+C to stop watching.
1802
1803 Examples:
1804 cgc watch . # Watch current directory
1805 cgc watch /path/to/project # Watch specific directory
1806 cgc watch --poll . # Use polling for Docker/NFS/SMB mounts
1807 cgc watch --sync-on-start . # Reconcile current files before watching
1808 cgc w . # Using shortcut alias
1809
1810 Set CGC_WATCH_POLLING=1 to use polling without passing --poll.
1811 """
1812 _load_credentials()
1813 watch_helper(path, context, use_polling=poll or None, sync_on_start=sync_on_start)
1814
1815@app.command()
1816def unwatch(

Callers 1

watch_abbrevFunction · 0.85

Calls 2

_load_credentialsFunction · 0.85
watch_helperFunction · 0.85

Tested by

no test coverage detected